Skip to content

Feature/audacity3 podcast chapters json export - #9935

Merged
kryksyh merged 5 commits into
audacity:audacity3from
nosenfield:feature/audacity3-podcast-chapters-json-export
Dec 30, 2025
Merged

kryksyh merged 5 commits into
audacity:audacity3from
nosenfield:feature/audacity3-podcast-chapters-json-export

Conversation

@nosenfield

@nosenfield nosenfield commented Nov 25, 2025 •

Copy link
Copy Markdown

Title

feat: Add Podcast 2.0 Chapters JSON export for label tracks

Description

Resolves: #7078

Add support for exporting label tracks in Podcast 2.0 Chapters JSON format, enabling podcasters to create chapter markers compatible with modern podcast apps.

Changes

  • Add PODCAST_CHAPTERS_JSON to LabelFormat enum in LabelTrack.h
  • Add PodcastChaptersFiles file type constant in LabelTrack.cpp
  • Update FormatForFileName() to detect .json extension
  • Implement JSON export in LabelStruct::Export() with proper string escaping
  • Implement JSON export in LabelTrack::Export() with JSON header/footer
  • Add "Podcast Chapters" option to Export Labels dialog in FileMenus.cpp
  • I signed CLA
  • The title of the pull request describes an issue it addresses
  • If changes are extensive, then there is a sequence of easily reviewable commits
  • Each commit's message describes its purpose and effects
  • There are no behavior changes unnecessary for the stated purpose of the PR

Recommended:

  • Each commit compiles and runs on my machine without known undesirable changes of behavior

QA:

  • Autobot test cases have been run

@kryksyh kryksyh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nosenfield thanks for this submission!

escapedTitle.Replace(wxT("\f"), wxT("\\f"));

wxString entry = wxString::Format(
wxT(" {\"startTime\": %s, \"title\": \"%s\"}"), // 3 spaces per Audacity coding standards

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exported json file should not follow Audacity coding standards.

{
// Individual chapter object (called from LabelTrack::Export)
// Format: {"startTime": X.XXX, "title": "..."}
// Podcast 2.0 Chapters spec: https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#chapters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escapedTitle.Replace(wxT("\r"), wxT("\\r"));
escapedTitle.Replace(wxT("\t"), wxT("\\t"));
escapedTitle.Replace(wxT("\b"), wxT("\\b"));
escapedTitle.Replace(wxT("\f"), wxT("\\f"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this to a helper function, something like this

namespace {
wxString EscapeJSON(const wxString& in)
{
    wxString out;
    out.reserve(in.length());

    for (wxChar c : in)
    {
        switch (c)
        {
            case '\"': out += "\\\""; break;
            case '\\': out += "\\\\"; break;
            case '\n': out += "\\n";  break;
            case '\r': out += "\\r";  break;
            case '\t': out += "\\t";  break;
            case '\b': out += "\\b";  break;
            case '\f': out += "\\f";  break;
            default:
                out += c;
                break;
        }
    }

    return out;
}
}

int numLabels = mLabels.size();
for (auto &labelStruct: mLabels) {
bool isLast = (index == numLabels - 1);
labelStruct.Export(f, format, index);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add isLast as an argument to LabelStruct::Export, and move the comma logic there.

Comment thread src/menus/FileMenus.cpp Outdated

// Ensure filename has correct extension for selected format
if (format == LabelFormat::PODCAST_CHAPTERS_JSON && fName.Right(5).CmpNoCase(wxT(".json")) != 0) {
// Add .json extension if not present

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here does not match what the code does, it overrides the extension if it does not match ".json", do we really want to restrict the user from exporting the file with an alternative extension?

@nosenfield
nosenfield requested a review from kryksyh November 26, 2025 03:08
void LabelStruct::Export(wxTextFile &file, LabelFormat format, int index) const
// Helper function to escape JSON special characters
// Podcast 2.0 Chapters spec requires proper JSON escaping
// Order matters: backslash must be escaped first to avoid double-escaping

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments here do not make sense, the order in switch statements does not matter. Please proofread the generated code before submitting it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies. that comment was left over from the previous implementation which used .Replace and was order-dependent. migrating to the suggested switch format nullified the order requirement.

@kryksyh kryksyh Dec 4, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, thanks!

@nosenfield
nosenfield requested a review from kryksyh December 4, 2025 18:25
@kryksyh kryksyh moved this to Ready for QA in [AU3] Main board Dec 4, 2025
@github-project-automation github-project-automation Bot moved this from Ready for QA to In Progress in [AU3] Main board Dec 4, 2025
@kryksyh
kryksyh force-pushed the feature/audacity3-podcast-chapters-json-export branch from 96a790b to a576a3c Compare December 29, 2025 09:38
@kryksyh kryksyh linked an issue Dec 29, 2025 that may be closed by this pull request
Add support for exporting label tracks in Podcast 2.0 Chapters JSON format.

- Add PODCAST_CHAPTERS_JSON to LabelFormat enum
- Add PodcastChaptersFiles file type constant
- Update FormatForFileName to detect .json extension
- Implement JSON export in LabelStruct::Export with proper string escaping
- Implement JSON export in LabelTrack::Export with header/footer
- Add JSON option to export dialog in FileMenus.cpp

The implementation follows Podcast 2.0 spec with version 1.2.0 and
properly escapes special characters in chapter titles including \b and \f.
Uses 3-space indentation per Audacity coding standards.

Task: Feature 1 - Podcast 2.0 JSON Export (Issue audacity#7078)
- Change file type name from 'Podcast Chapters JSON' to 'JSON file' to match existing naming conventions (e.g., 'WebVTT file', 'SubRip text file')
- Ensure filename has .json extension when JSON format is selected in export dialog
- Fixes issue where file extension doesn't update when JSON format is selected

Task: Feature 1 - Podcast 2.0 JSON Export (Issue audacity#7078)
Change file type display name from 'JSON file' to 'Podcast Chapters' to
better communicate the purpose of the export format to users.

Rationale:
- Users want to export podcast chapters, not 'a JSON file'
- The .json extension already indicates the file format
- More user-friendly and purpose-focused
- Matches user mental model and intent

Task: Feature 1 - Podcast 2.0 JSON Export (Issue audacity#7078)
- Fix JSON indentation to 2-space-per-level (matching spec)
- Extract escaping logic into EscapeJSON() helper function
- Move comma handling into LabelStruct::Export() with isLast parameter
- Extract header/footer logic into ExportHeader()/ExportFooter() functions
- Remove forced .json extension (let file dialog handle it)

Addresses PR review feedback from kryksyh
@kryksyh
kryksyh force-pushed the feature/audacity3-podcast-chapters-json-export branch from a576a3c to f613567 Compare December 30, 2025 13:16
@kryksyh
kryksyh merged commit 5aae37c into audacity:audacity3 Dec 30, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in [AU3] Main board Dec 30, 2025
@kryksyh kryksyh modified the milestone: Audacity 3.7.8 Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Export label track as a Podcast2.0 chapters json file

2 participants