News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Extract "Lyrics" (USLT) content from ID3 tag and export to a text file

Started by RandP, April 28, 2022, 10:29:10 PM

Previous topic - Next topic

RandP

So I've read the link at https://exiftool.org/TagNames/ID3.html, it says "ID3v2 tags which support multiple languages (eg. Comment and Lyrics) are extracted by specifying the tag name, followed by a dash ('-'), then a 3-character ISO 639-2 language code (eg. "Comment-spa")"

Currently I have something like:
"%_path%" -Lyrics-eng > "%_folderpath%\%_filename%.lrc"
or to be more specific:
C:\abc.mp3 -Lyrics-eng > C:\abc.lrc
which isn't working

How do I extract the Lyrics content (encoded in Unicode) including all the original EOL chars (CRLF), and export that as .lrc files with same filename and directory?

Most of my mp3 files are ID3v2.4 (UTF-8), I'm using Mp3Tag to run multiple command lines, which looks something like the attached image (I need to figure out what to put in the "Parameter" field for the ExifTool).

RandP

Note that the .lrc files are just plain text files (similar to .txt) with a different extension.

StarGeek

Do you have a sample file?  Do the lyrics not appear if you use the command in FAQ #3?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Now that I'm rested and awake, not sleepy and heading for bed, I can comment better.

In a lot of the alternative language tags, the alternative languages are optional and a lot of people don't take the time to actually set the language.  You should only need to specify the language if the file has another language entry for the tag and that is the one you want to extract.  Exiftool should return the default value for the tag if you don't specify a language.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

RandP

Quote from: StarGeek on April 29, 2022, 09:38:46 AM
Now that I'm rested and awake, not sleepy and heading for bed, I can comment better.

In a lot of the alternative language tags, the alternative languages are optional and a lot of people don't take the time to actually set the language.  You should only need to specify the language if the file has another language entry for the tag and that is the one you want to extract.  Exiftool should return the default value for the tag if you don't specify a language.

The tested Mp3 file's Lyrics (USLT) frame actually does have a language code (eng) as I checked in Mp3tag, the Mp3 file I tested is attached. (Attached Mp3 file uses ID3v2.4 tag, UTF-8 encoding)

I'm using the "Stand-Alone Executable" of ExifTool, so far I can do something like:
-k "%_path%"
where "%_path%" is the path to Mp3 file, this displays all the metadata (not just lyrics) on the Window, but how do I get only the "Lyrics" content and how do I export that content into a text file (with certain filename given)? Could you show me how you did it with the given Mp3 file?

I'm also not sure about how to enter any command after opening the "exiftool.exe" window (I can only hit "Enter" and scroll the tutorial text on the screen).

StarGeek

You would just use -Lyrics with that file.  Don't assume that whatever other programs use for a tag is what exiftool will return.  That's why I pointed you to FAQ #3.  The command there would have shown you that the tag was simply Lyrics.

Normally, on the command line, you would just redirect the output of exiftool into a file.  For example
exiftool -Lyrics "Like a Cat.mp3" >Lyrics.txt

This may not work though because you're calling it from another program.  In that case you can do something like
exiftool -Lyrics -w %f.txt "Like a Cat.mp3"
which will create a text file with the exiftool output and the same base name as the mp3, i.e. -w %f.txt "Like a Cat.mp3" will create "Like a Cat.txt"

Based upon the contents of your example file, you may run into Windows character code problems where some of the multi-byte characters get Mojibaked.  Hopefully that won't happen when writing the output to a text file, but other see FAQ #18.
This output will still have Lyrics                          : before the contents of the tag, but you can remove that with the -s3 (-short3) option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

RandP

So I tried the
exiftool -Lyrics "Like a Cat.mp3" >Lyrics.txt
by converting it to
-Lyrics "%_path%" > "%_folderpath%%_filename%.txt"
as parameters,

but I faced warning "FileName encoding not specified. Use "-charset FileName=CHARSET""

So I checked my system and found the charset/codepage (I'm using a Simplified Chinese version of Windows 7), the result is attached as image.

Then based on the result, I tried all of the following:
-charset filename=936 -Lyrics "%_path%" > "%_folderpath%%_filename%.txt"
-charset filename=cp936 -Lyrics "%_path%" > "%_folderpath%%_filename%.txt"
-charset filename=gb2312 -Lyrics "%_path%" > "%_folderpath%%_filename%.txt"

But was told "Invalid Charset 936", then I tried
-charset filename=latin -Lyrics "%_path%" > "%_folderpath%%_filename%.txt"
this time I wasn't told "Invalid Charset", but was told "1 directories scanned" "0 image files read" (I'm guessing it's because my system doesn't use "latin"?)

What value should I give to "-charset filename=" if I'm using Simplified Chinese version of Windows 7 SP1?

RandP

So after reading https://exiftool.org/forum/index.php?topic=10882.0, I tried the following:
-k -charset filename=utf-8 -@ -lyrics "%_path%" > "%_folderpath%%_filename%.txt"

Now I get the error saying "Error opening arg file -lyrics"


StarGeek

Quote from: RandP on April 30, 2022, 02:01:51 AM
So after reading https://exiftool.org/forum/index.php?topic=10882.0, I tried the following:
-k -charset filename=utf-8 -@ -lyrics "%_path%" > "%_folderpath%%_filename%.txt"

Now I get the error saying "Error opening arg file -lyrics"

The -@ (Argfile) option requires a second argument which is the filename that exiftool is supposed to read commands from.  Since you have -lyrics immediately following -@, exiftool is trying to read a file with that name, which doesn't exists and results in that error.

The command in the post you link is reading data from STDIN, which is represented by the hyphen as the ArgFile -@ -  That command is using the very complex -stay_open option to continually send commands to exiftool.  IMO, this isn't the command you want to run.

QuoteWhat value should I give to "-charset filename=" if I'm using Simplified Chinese version of Windows 7 SP1?

Unfortunately, I can't really help with this.  Windows command line truly sucks when it comes to the more complex multibyte characters.  I could never get the options in FAQ #18 to work for me.  The only thing that did work for me was this StackOverflow answer, but that affects the entire system and can affect the fonts and GUIs of other programs, especially older programs.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

RandP

It's a bit weird cuz I tried another program ffmpeg, with the following command:
ffmpeg -i INPUT -f ffmetadata FFMETADATAFILE
and in Mp3tag Tools parameters, the above would be:
-i "%_path%" -f ffmetadata "%_folderpath%%_filename%.txt"
which seems to be working fine with Unicode characters path.

Is it the ">" part that's messing up the Unicode characters?:
exiftool -Lyrics "Like a Cat.mp3" >Lyrics.txt

Why does Exiftool require windows command line to work whereas some other programs don't (or seem to be able to bypass this Unicode limitation with Windows)? Is there any other way around this?

ryerman

Quote from: RandP on April 28, 2022, 10:29:10 PM
How do I extract the Lyrics content (encoded in Unicode) including all the original EOL chars (CRLF), and export that as .lrc files with same filename and directory?
Return to the Mp3tag forums to see my solution here.
It produced the attached file.
Windows 10 Home 64 bit, Exiftool v12.61

StarGeek

Quote from: RandP on May 02, 2022, 06:42:49 AM
Is it the ">" part that's messing up the Unicode characters?:
exiftool -Lyrics "Like a Cat.mp3" >Lyrics.txt

If you are using Powershell and not CMD, then yes.  Powershell is known to corrupt binary data.

QuoteWhy does Exiftool require windows command line to work whereas some other programs don't (or seem to be able to bypass this Unicode limitation with Windows)? Is there any other way around this?

Exiftool is a command line program and mutli-platform, written in Perl.  As for why the problems, I don't know.  Maybe it's a Windows Perl thing.  Linux/Mac don't have problems with UTF8 characters at all.  As I said, I never was able to deal with UTF8 characters until I set the whole system to UTF8 as linked above.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).