Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metaflac bug - error writing multi-line tag from stdin #232

Open
audiomuze opened this issue Jan 2, 2021 · 2 comments
Open

metaflac bug - error writing multi-line tag from stdin #232

audiomuze opened this issue Jan 2, 2021 · 2 comments

Comments

@audiomuze
Copy link

audiomuze commented Jan 2, 2021

Seeing as there's no option within metaflac to --remove-all-tags-except, in an effort to achieve consistency in tagging I devised a workaround that writes tags to be preserved to stdout and pipes same to another call to metaflac which deletes all tags and then writes back input from stdin.

The general form would be:
metaflac --show-tag tagname1 --show-tag tagname2 --show-tag tagnamex "filename.flac" | metaflac --preserve-modtime --remove-all-tags --import-tags-from=- "filename.flac"

However, I've come up against an issue, as the following call demonstrates:
metaflac --show-tag lyrics x.flac | metaflac --import-tags-from=- x.flac

Running the above should result in the corresponding vorbiscomment simply being rewritten, and it works as intended until it encounters a tag with a CR or LF within the tag, meaning it will not work for the likes of a Lyrics tag, rendering the workaround fruitless.

To illustrate:
metaflac --list x.flac

METADATA block #0
  type: 0 (STREAMINFO)
  is last: false
  length: 34
  minimum blocksize: 4608 samples
  maximum blocksize: 4608 samples
  minimum framesize: 1009 bytes
  maximum framesize: 14722 bytes
  sample_rate: 44100 Hz
  channels: 2
  bits-per-sample: 16
  total samples: 8627724
  MD5 signature: 74bdec14815e8c901cf1f9a87171e2c5
METADATA block #1
  type: 4 (VORBIS_COMMENT)
  is last: false
  length: 73
  vendor string: reference libFLAC 1.3.1 20141125
  comments: 1
    comment[0]: lyrics=FIRST LINE
SECOND LINE
METADATA block #2
  type: 1 (PADDING)
  is last: true
  length: 22445

As soon as there's a CR or LF in a comment, such as in the example above, metaflac fails with the following:

-: ERROR: malformed vorbis comment field "SECOND LINE",
       field contains no '=' character

Is there something more I can do my side to work around this or does this now mean there's no solution until this bug is addressed or something like --remove-all-tags-except is implemented?

@audiomuze audiomuze changed the title metaflac - error writing multi-line tag from stdin metaflac bug - error writing multi-line tag from stdin Jan 3, 2021
@audiomuze
Copy link
Author

audiomuze commented Jan 8, 2021

There's currently no workaround using metaflac, even writing multi-line tags to a temp file > /tmp/savedtag and then attempting to --import-tags-from=/tmp/savedtag doesn't work because whilst --show-tag will happily read and show a multi-line tag and I'm able to redirect to a file, --import-tags-from=FILE doesn't support multi-line comments.

Please could you either implement --remove-all-tags-except or improve metaflac by enabling multi-line tags to be written from file and/or stdin.

@dlehammer
Copy link

Hi FLAC-gurus,

Thought I'd add my findings to support future users puzzled by this issue, as I too encountered this issue during metaflac export/import for multi-line tags (v1.3.3).

(I've attempted to batch-upgrade FLAC-files in-place, but that fails sometimes (ex. caused by ID3-tag), so I fall-back on re-encode & re-tagging instead ~ hence encountering the multi-line issue during import of exported tags)

Workaround

The flac --tag-from-file=<tag-name>=<tag-file> ... argument supports multi-line tags.

(In my case I now combine re-encode and re-tagging into a single command by splitting the exported tags into separate files and arguments ~ short-circuiting my previous re-tagging approach based on metaflac import)

A plea for flac/metaflac multi-line tag feature parity

The vorbiscomment --escapes argument explicitly enables support for multi-line tags and empowers the user.

Quote/unquote newlines and backslashes in the comments. This ensures every comment is exactly one line in the output (or input), allowing to filter and round-trip them. Without it, you can only write multi-line comments by using -t and you can't reliably distinguish them from multiple one-line comments.

The reasoning behind the above approach is discussed further here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants