fmang / opustags

Ogg Opus tags editor
BSD 3-Clause "New" or "Revised" License
82 stars 11 forks source link

Feature request: equivalent of metaflac's remove-all-tags-except #68

Closed anonymous5555522222 closed 6 months ago

anonymous5555522222 commented 6 months ago

--remove-all-tags-except=NAME1[=NAME2[=...]] Remove all tags, except the vendor string and the tag names specified. Tag names must be separated by an = character.

Example: --remove-all-tags-except=TITLE=ARTIST=METADATA_BLOCK_PICTURE This would delete every tag except the title and artist tags, and the cover art, from an Opus file.

Thank you for this tool, it works perfectly.

fmang commented 6 months ago

This is quite a specific feature request. opustags provides --edit to leverage the power of your text editor, or --set-all to allow scripting. For example, to get the behavior you need, you can do:

opustags file.opus | grep -E '^(TITLE|ARTIST|METADATA_BLOCK_PICTURE)=' | opustags -S -i file.opus

The caveat is that it truncates multi-line tags, but the three tags you listed are all supposed to fit on one line.

As a more generic approach, I would consider something like --keep=TAG that, when combined with --delete-all or --set-all, prevents the selected tags from being deleted. Or, to reuse the existing options, allow specifying --add=TAG without a value, so that --delete-all --add TITLE would mean “delete all the tags then add TITLE with the value it had before”.

anonymous5555522222 commented 6 months ago

As a more generic approach, I would consider something like --keep=TAG that, when combined with --delete-all or --set-all, prevents the selected tags from being deleted.

This one sounds good to me as long as various tags can be requested (--keep TITLE --keep ARTIST or --keep TITLE=ARTIST), the other one makes me think that it would result in adding TITLE= to a file.

fmang commented 6 months ago

I have ended up adding a -z flag. See https://github.com/fmang/opustags/issues/67#issuecomment-2084627133.

The following command should solve your use case and also support multi-line tags, assuming you use GNU grep:

opustags -z file.opus | grep -z -E '^(TITLE|ARTIST|METADATA_BLOCK_PICTURE)=' | opustags -z -S -i file.opus
anonymous5555522222 commented 6 months ago

I have ended up adding a -z flag. See #67 (comment).

The following command should solve your use case and also support multi-line tags, assuming you use GNU grep:

opustags -z file.opus | grep -z -E '^(TITLE|ARTIST|METADATA_BLOCK_PICTURE)=' | opustags -z -S -i file.opus

I have tested this one-liner command with commit 0067162, and it works great. Thanks!

fmang commented 6 months ago

Great! Thank you for your feedback. I’m closing the issue.