Bug 499812 - Feature request: Edit chapters via the CLI
Summary: Feature request: Edit chapters via the CLI
Status: RESOLVED FIXED
Alias: None
Product: kid3
Classification: Applications
Component: general (other bugs)
Version First Reported In: unspecified
Platform: unspecified All
: NOR wishlist
Target Milestone: ---
Assignee: Urs Fleisch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-02-11 12:46 UTC by Molly Messner
Modified: 2025-07-24 16:30 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Molly Messner 2025-02-11 12:46:36 UTC
Currently, itʼs not possible to edit chapters using the CLI. In fact, the `Chapters` pseudo-tag does not even appear using the `get` command (though it can be selected/deselected/copied/pasted/deleted). I would love to be able to edit chapter markers in the CLI! (Currently, the only tool that can edit chapters using the command line across several formats is FFmpeg, and that has the unfortunate side effect of mangling all other metadata in various ways.

I suggest a new command or set of commands for this – building this more complex functionality into the existing `set` and `get` commands strikes me as shoving a square peg into a round hole.

(I presume the plan is to eventually implement the `Chapters` pseudo-tag for all the relevant formats – manipulating that may be a good way to solve this.)

One consideration that may need to be made is Kid3ʼs eventual Matroska support: Matroska chapters appear to potentially be far more complex than in other formats, so whatever solution is chosen would need to be extensible to Matroska (without unintentionally mangling metadata) as well.
Comment 1 Urs Fleisch 2025-02-12 05:28:14 UTC
For the MP4 Chapters (and later for the "pseudo" Chapters representation for MP3), I "misused" the editor for synchronized lyrics (SYLT) and event timing codes (ETCO) frames. This has the advantage, that they can be played in a "Karaoke" style, and that import and export to LRC files is possible. Therefore you can export synchronized lyrics to an LRC file in kid3-cli using `get SYLT:'/path/to/lyrics.lrc'` and set them from an LRC file using `set SYLT:'/path/to/lyrics.lrc' 'Lyrics Description'`. I would suggest to implement the same for chapters. Would that be an acceptable solution?
Comment 2 Molly Messner 2025-02-12 10:39:55 UTC
Eventually, it would be nice to have a separate set of commands – having to create an intermediate file is slightly fraught (of course, on Linux, you can generally create an in-memory pseudo-file, but that isnʼt available on all operating systems), and itʼs easier to manually work with a direct command-line flow (as an example, Iʼve never ever written an `FFMETADATA` file manually, since itʼs just too darn much faff – though that *is* a particularly faffy syntax).  Additionally, itʼs hard to imagine a text file syntax that supports all the different properties for chapters in various metadata formats without being annoying… unless one makes it a JSON file or somesuch, but then the user certainly wouldnʼt want to type it out manually. Iʼm imagining something akin to:

* `chapters list`: Would list the existing chapters in a way thstʼs both readable to humans and easily machine-parsable.
* `chapters insert 0:58:39.606 1:21:01.567 "Title Here"`: Would insert the specified chapter after the time-wise preceding chapter. Would also take a switch. `--index`, in case the user wants to insert it at a particular position. More switches could be added for more obscure properties only found in certain metadata formats – say, for chapter images, or all of Matroskaʼs heaps of features. The end time would be ignored for VorbisComment.
* `chapters delete 3`: Would delete the chapter with index #3. Matroska may require extra syntax due to its potential for *nested chapters*(! What!) – say, `chapters delete 3.2`
* `chapters edit 3 * * "New Title"`: Would allow editing an existing chapter.
* `chapters sort`: Would sort the chapters by start time if theyʼre out of order.
* `chapters clear`: Would remove all chapter-related tags from the file.

Implementing those without any special options would be enough for 95% of cases – and then itʼd be extensible, should those extra features be desired.

For formats with multiple different chapter formats, one could add a switch: `chapters insert 0 43.3 "Title Here" --format nero`, for example, for MP4. (I donʼt believe Kid3 supports Nero chapters – the `chpl` atom – at present, but hey, if it should ever.) Matroska might require the additional switch `--edition 1` (though itʼd default to the default edition) and a command for adding/deleting/editing editions, but… that feels like a decidedly “cross that bridge when one comes to it” sort of problem. Same goes for Matroska chapter menu features, which it doesnʼt feel like Kid3 has to be able to edit… at least certainly not as part of CLI chapter editing support as a feature in itself.

All that said, implementing a new set of commands is a good bit more work, so if itʼs relatively trivial to add the file import solution, it *would* be nice!
Comment 3 Urs Fleisch 2025-02-16 10:31:42 UTC
That was actually an easy one, only two lines had to be fixed.
Now you can get existing chapters from an ID3v2 tag as an LRC file with

    kid3-cli -c "get Chapters:/path/to/file.lrc" /path/to/file.mp3

The LRC file can be edited and the chapters can be set using

    kid3-cli -c "set Chapters:/path/to/file.lrc ''" /path/to/file.mp3

The same works also with MP4 tags when the Mp4v2Metadata plugin is used.

I hope that this solution is enough. I would then probably invest my time
rather in implementing MP4 chapter support for TagLib than in enhancing
the CLI with fancy chapter commands.

You can find a fixed version kid3-git20250216 in https://sourceforge.net/projects/kid3/files/kid3/development/.
Comment 4 Molly Messner 2025-02-19 15:21:41 UTC
Thank you ever so kindly! That’s just good enough for my purposes – now I can take FFmpeg out of my toolchain for some purposes. Would be nice to have those chapter commands, but… I suppose they’d necessarily come after abstraction of chapters had been implemented for all formats. I can think about that some time in the future.
Comment 5 Urs Fleisch 2025-07-24 16:30:50 UTC
Fixed in version 3.9.7.