Feature Request: Batch Export Lyrics into Individual Files (.txt / .lrc)

I actually just found a ffprobe (from FFmpeg) command line that dumps a single frame into a text file, this seems like exactly what I was looking for. from the source, the command line is:
ffprobe in.mp3 -show_entries format_tags=title -of compact=p=0:nk=1 -v 0 > title.txt
in which, supposedly, "title.txt will have just the title terminated with a newline."
so I modified it for Mp3tag's parameters:
"%_path%" -show_entries format_tags=title -of compact=p=0:nk=1 -v 0 > "%_folderpath%%_filename%.txt"
But when I tested in Mp3tag using "Tools", nothing happened. Am I missing something or did I do anything wrong here?

Vast majority of my mp3 file paths aren't even using any organized path unfortunately.

Speaking of "filename (%_path%) and the folderpath (%_folderpath%)", I just tested those with a ffprobe command (see my previous comment, it's supposed to extract single frame/tag, so it should also work for lyrics) but it didn't work.

Are you familiar with ffprobe by any chance?

This is the MP3tag forum. If you have questions about 3rd party programs please ask in their support.

As every file has to have some kind of path it should be possible to move that file to a folder right below the original location which means that it now resides exclusively in a folder of its own.
Once this has been achieved, the lrc export can be started.
And after the lrc export has happened, it should be possible to move the audio file and the lrc file back to the original location.
So far you have given general statements about what is (allegedly) not possilbe but no details that could have lead to a solution.
I find this not very cooperative esp. as it is your problem, not mine.

To get some more substance into the whole thing I just did the following to 5 files, some of which were in the same folder, others were in different folders:
I used Converter>Tag-Filename with
Format string: %_folderpath%%_counter%\%_filename%
I then executed the export "lrc" with the option set to create 1 file per folder
Filename: %_folderpath%%_filename%
which lead to the message that 5 files got processed and 5 export files had been created.
I then used Converter>Tag-Tag for _DIRECTORY with
Format string: $regexp(%_folderpath%,(.*)\d,$1)
and all the files went back to their original location, taking the lrc file with them.

Wow, it is a real pain to deal with Unicode using Windows cmd.exe.
I checked with Notepad only, which displayed the characters correctly and reported the encoding as UTF-16. I have no explanation for that.
I finally found a way to create correctly encoded text by using powershell from cmd.exe, but the command line is relatively long.

Also, I found a way to write mult-line text to a file, using Windows cmd.exe
I used this format:
(ECHO line1 & ECHO line2 & ECHO line3) > "C:\path\file.txt"
But any parentheses in the lyrics caused problems, so I replaced ( with [ and replaced ) with ].

Now, the parameter is this:
/U /c (echo $regexp($regexp($regexp($replace(%unsyncedlyrics%,'(','[',')',']'),^\w+\|\|,),\r\n, & echo ),\s&\secho\s$,)) > "%_folderpath%%_filename%.tmp" && powershell -windowstyle hidden -command "Get-content -Encoding Unicode -Path ''$replace(%_folderpath%%_filename%,'','''').tmp'' | Out-File -FilePath ''$replace(%_folderpath%%_filename%,'','''').txt'' -Encoding UTF8" && del /q "%_folderpath%%_filename%.tmp"

I've attached a text file containing the parameter for easier copying:
Parameter for Tool to write lyrics to file.txt (414 Bytes)

This will create a TXT file even if there are no lyrics in the audio file.
The file list can be filtered so that such files are not displayed.

I bet there is another more elegant command line.

Using the export feature seems to avoid encoding problems.
Maybe you would be sucessful by using the method suggested by @ohrenkino.
I'm unclear how multi-lines from a TXT file can all be imported into UNSYNCEDLYRICS but it sounds as if that is not a problem for you.
Maybe you use something other than Mp3tag

Maybe this Tool:

Name: Write UNSYNCEDLYRICS to file
Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parameter: -windowstyle hidden -command "Write-Output ''$regexp($regexp($regexp($replace(%unsyncedlyrics%,'',''''),^\w+\|\|,),\r\n,'' ''),''\s''$,)'' | Out-File -FilePath ''$replace(%_folderpath%%_filename%,'','''').txt'' -Encoding Unicode"

-Encoding Unicode is the default for PowerShell 5.1 so is not needed in the command if you use PowerShell 5.1.
Other encoding can be specified. See here.

For later PowerShell versions, the encoding options and the default may be different.

My apologies if I I didn't sound very cooperative, there're a few reasons that I prefered the "Tools" method:

I found the folder-renaming method to be a bit of hacky and was worried about the limitations it might have in certain situations (e.g. duplicate audio files with same metadata and filenames (but different paths), files in paths that are close to the Windows' path length limit, etc.). I was also not good at the Mp3tag syntax (didn't know what you meant by "counter" until I saw "%_counter%") or regex stuff, so I couldn't really follow you exactly unless given clear/specific/detailed instructions. The "Tools" method just seemed a bit more intuitive to me (as it simply runs on each audio file without editing the path) and it was supposed to take just 1 click to finish everything once it's set up.

So I just tested your method (changed "%_folderpath%%_filename%" to "%_folderpath%%_filename%.lrc" to include the extention), it works on simple situations, but when I tried to upscale-testing it in more complex situations (e.g. folders with numbers as names, more levels of subfolders, duplicate files, etc.), it started to behave unintendedly (e.g. more than one .lrc file for same audio file in same path, extra folders named "1" created with audio files not moved to their original paths, etc.).

I've eventually found a way to batch export lyrics (USLT frame) into individual .lrc files using the "Tools" method, so it's all good now. I do appreciate your help so far.

I will reply to ryerman's response next.

It would have been nice to see real examples and not just mirky allegations. Honestly, if you have any number of files in any folders, you select them all and start to add a folder to the filename that is an increasing number for each file you cannot get duplicate files in such a folder. This is voodoo.

And that the tools method

is a strange impression as you had to ask for each command line and could not develop it yourself.

This shows to me that a feature request without the better knowledge of MP3tag functions is often enough not really to the point.
Of course there is only just one click possible, if you create an action group that includes the 3 steps I outlined. I used the converters as they have a preview function so that you could follow the results better.

I don't understand why you did that - the lyrics file gets created with the call of the export script, and resides then in the same folder as the selected file. And as soon as you rename the folder, all files in that folder are moved to the new location.

That is why I cannot understand why you claim that there are

which cannot be handled.

TBH and IMHO it is a much sleeker way to stay within 1 program than to rely on 3rd party programs.
But you have found your way. Fine.

I'm unclear how multi-lines from a TXT file can all be imported into UNSYNCEDLYRICS but it sounds as if that is not a problem for you.
Maybe you use something other than Mp3tag

I'm indeed using Mp3tag (without anything else) to do the import (so it's weird that the reverse action (export) is way trickier to do), anyways here is the instruction:
Create a new action and add "Import text file" as the action type
Set field name to UNSYNCEDLYRICS (or whatever field you wanna import to) and filename to %_filename%.lrc (or your own filename).
*Run the action, done.

Wow, it is a real pain to deal with Unicode using Windows cmd.exe.

I would agree with that 100%, this was part of the reason why I was looking for a third-party program to do the nasty work.

Maybe this Tool:

I tried it and it works! Ain't no way I could have figured all that complex code by myself lol. Great work.

This will create a TXT file even if there are no lyrics in the audio file.

Tested your last command and it's true. But I have some good news: earlier I contacted the author of Kid3 and he confirmed it was a bug that the output file wasn't in Unicode, so he fixed it and released the new development snapshot builds, if you're interested you can try it with the same earlier command:
-c select "%_path%" -c "get USLT:''%_filename%.lrc''"
and it should produce .lrc files (or .txt if you change the extention) that uses UTF-8 as encoding, CRLF as EOL characters (standard for Windows), and no file produced if the lyrics (USLT) frame is empty.

start to add a folder to the filename that is an increasing number for each file

Like I said in my last reply, I didn't even know it was possible because I "didn't know what you meant by "counter" until I saw "%_counter%"" in your detailed instruction (i.e. I didn't know automatically increased number for each file was possible).
I was originally thinking about using the filenames or the titles, but using titles can be tricky due to audio files with duplicate titles in the same path (or empty titles, or no metadata at all), whereas for using filenames (it doubles the part of path length created by filenames, which can be trouble for long file names due to Windows path length limit).

is a strange impression as you had to ask for each command line and could not develop it yourself.

By "intuitive" I meant I like the approch of leaving the audio files untouched (e.g. path) for a process that's supposed to be read-only, and how it deals with each audio file one at a time instead of moving them around (so the logic of process is simpler to me, and also more similar to how I would do them manually (i.e. "intuitive")). I'm not good at command line by any means, but I also didn't expect it to be this tricky (due to Unicode and parsing problems).

Of course there is only just one click possible, if you create an action group that includes the 3 steps I outlined.

Again, I'm just an average Mp3tag user without the expertise, I didn't know it's possible (e.g. Which action type should I use to put the converter into an action?)

I don't understand why you did that

All I did was adding a filename extension (.lrc for synced, or .txt for unsynced) to the lyrics file, so that the music players would know it's used for lyrics.

which cannot be handled.
TBH and IMHO it is a much sleeker way to stay within 1 program than to rely on 3rd party programs.
But you have found your way. Fine.

The "Tools" method seems to handle the complex situation acceptably (seems bug-free) so far (although it does eat up lots of resource due to too many command line windows being opened).
I'd love to stay within 1 program if possible too (which is why I requested the feature in OP from the beginning, so that other people don't have to go through the trouble like me), but sometimes if the 3rd party program can make my life a bit easier, I think it might be worth a try.

Thanks for the explanation.
I tried with the "Text file - Tag" converter, but that only imported the first line.

I tried it and it works as you say.
My only quibble is that "get USLT" is specific to ID3 tags.
This will be sufficient if all your files are MP3.
You can use "get Lyrics", which works for MP3 files and various other file types, but will still fail for APEv2 tags and files that use VorbisComments. (but "get unsyncedlyrics" usually works for these)

My method takes advantage of Mp3tag's internal mapping and works with all file types.
You can process only the files with lyrics by using a filter: unsyncedlyrics PRESENT

Anyway, you found a solution and I learned some stuff.

1 Like

Here is an Export script that will create Lyrics files for multiple tracks, without flashing the command window or writing empty files if %unsyncedlyrics% is empty.

It creates a VBS script that will execute if "Yes" is clicked when Mp3tag presents the question "Display Export file now?" after exporting is complete.

By default, Windows PowerShell is used to write the lyrics gotten from Mp3tag but the MTE file can be easily edited to use the Kid3 CLI to get the lyrics directly from the tracks.
Also, the file extension for the lyrics files can be specified by another simple edit.

Edit: See below for repaired MTE file: REPAIRED (May 20,2022)-Write Lyrics to Individual Files.mte

1 Like

Luckily my collections are all in MP3 (for ease of management). I tried the "get Lyrics" command but it produces empty files when there's no lyrics (guess I can use the unsyncedlyrics PRESENT filter, which does actually work).

APEv2 tags and files that use VorbisComments. (but "get unsyncedlyrics" usually works for these)

Unfortunately my collection doesn't have those (.flac, .ape, etc.) so can't confirm.

Anyway, you found a solution and I learned some stuff.

Yeah I'm also really grateful for all the detailed instructions you have offered to help me.

Seeing someone writting a dedicated script for my application has really made my day, thank you so much!
I tested your .mte and it works. (I want to add that you should uncheck both "Append data" (mentioned in your script) and "One file per directory" (otherwise the "Display Export file now?" window won't show up for some reason))
I added that minor comment mentioned above and here's the new .mte (if it matters to anyone)
Write Lyrics to Individual Files.mte (7.2 KB)

1 Like

You're welcome.
And nice catch re: "One file per directory"

Also, I should have included a reminder to enable a message when exporting.
(Options > Messages > check-mark for "at exporting tags")

1 Like

By the way, I also found that you can simplify the earlier parameters for kid3-cli.exe:
-c select "%_path%" -c "get USLT:''%_filename%.lrc''"
into
-c "get USLT:''%_filename%.lrc''" "%_path%"
(just give the path of the file as the last parameter)

Hey everyone!

Really great job by all parties involved! Have been waiting for this kind of tool for ages!

However, I do have one problem when using the provided ".mte" file.
.vbs throws an error: Expected end of statement
By looking at Line: and Char: I've pinpointed that's because the text of some lyrics has quotes in it. Like: He said: "Hi!".

How can I fix it (beside manually deleting them in each mp3 file that's involved)? I have close to zero knowledge in Visual Basic.

1 Like

Thanks for the feedback.
I should have known double quotes would be an issue.
Not only are they a problem in the VBS script, they need to be escaped on the Windows command line.

I made a correction and some improvements and tested for other special characters:)(^|&<>\/’‘
The attached MTE script should now work properly.
REPAIRED (May 20,2022)-Write Lyrics to Individual Files.mte (7.7 KB)

2 Likes

Thank you, that's a great job!
It finally works!
However, it doesn't export all the lyrics :cry:
I've pinpointed the problem here too, but again, I don't know how to fix it.
It's some apostrophes, which I don't even know how to type on a keyboard, so I'm just gonna copy/paste it:

and

Example in lyrics:

Ho fatto l’amore con me
‘Cause I never loved someone like you before