Repository navigation
Conversation
kryksyh
left a comment
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
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 |
| escapedTitle.Replace(wxT("\r"), wxT("\\r")); | ||
| escapedTitle.Replace(wxT("\t"), wxT("\\t")); | ||
| escapedTitle.Replace(wxT("\b"), wxT("\\b")); | ||
| escapedTitle.Replace(wxT("\f"), wxT("\\f")); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Please add isLast as an argument to LabelStruct::Export, and move the comma logic there.
|
|
||
| // 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 |
There was a problem hiding this comment.
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?
| 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 |
There was a problem hiding this comment.
The comments here do not make sense, the order in switch statements does not matter. Please proofread the generated code before submitting it.
There was a problem hiding this comment.
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.
96a790b to
a576a3c
Compare
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
a576a3c to
f613567
Compare
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
PODCAST_CHAPTERS_JSONtoLabelFormatenum inLabelTrack.hPodcastChaptersFilesfile type constant inLabelTrack.cppFormatForFileName()to detect.jsonextensionLabelStruct::Export()with proper string escapingLabelTrack::Export()with JSON header/footerFileMenus.cppRecommended:
QA: