nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
532 stars 58 forks source link

can't insert newlines into comments #602

Open ClaireCJS opened 1 year ago

ClaireCJS commented 1 year ago

PROBLEM: I've searched with google, through the docs, even with chatgpt, and for the life of me can't see how to embed comments with newlines into an mp3 file in such a way that winamp properly displays them like it does all the other ones that already exist.

BACKGROUND: I'm using ytl-dp to download a youtube video as a set of mp3s, which puts the description in a json file. I have a program that ingests this same description and uses eyed3 to insert the description into the mp3s comment field.

BACKSTORY: I see a literal "\n" in my json file. But when i copy that string into the winamp comments, i don't see the newlines in wnamp. (Winamp displays newlines just fine if i enter them myself in winamp)

ATTEMPTED SOLUTIONS: I've tried replacing the literal \n ("\n") with the real newline ("\n") as well as \r\n as well as \\n to try to unescape it. None display right in winamp.

description_new = description.replace('\\n',  '\n'))   #didn't work
description_new = description.replace('\\n','\r\n'))   #still doesn't work
description_new = description.replace('\\n','\\\n'))   #still doesn't work in winamp but displays right in vlcplayer
if description_new: audiofile.tag.comments.set(description_new)

ANALYSIS: I feel this is a winamp-specific issue and not an eyed3 specific issue, as things displayed fine in VLCplayer.

But winamp isn't really supported anymore (they expect us to run a brand new version that lacks proper plugin compatibility, and some of us are too deep in the weeds to lose our plugins until proper replacements exist).

So I'm hoping to find a solution here nonetheless because I imagine this to be an extremely common use case.

FURTHER TESTING #1: So, I manually edited a comment to have newlines then wrote another script to simply read the comment with eyed3 and print it to the screen. THE NEWLINES ARE THERE!

FURTHER TESTING #1: I also did the same with the ones I'm inserting with eyed3, and when re-read with this new script, THE NEWLINES ARE THERE.

FURTHER ANALYSIS: If you manually put an enter into a comment in winamp in such a way it is visible, and read the value back out, it's actually "\r\n\r" for each newline! I disagree with their implementation, but nothing can be done about that.

Yet: description_new = description.replace('\\n','\n\r\n'))

Still doesn't seem to work right! I'm surprised at this point. Feels like every tag editing software in the world does this right, but I can't do it right.

WhitePeter commented 2 months ago

I think I may have found an estimate of a solution:

eyeD3 --comment="$(printf 'foo\nbar')" file.mp3

That way I was able to get an actual newline displayed in eyeD3's output, whereas --comment="foo\nbar" only got me a literal 'foo\nbar'.