Scripting functions in Text file → Tag converter

Any chance this will be supported in the future?

Could you give an example?
Because there is already an action of the type "Import from Text file" (which is more or less the convert function) and as you can add further actions (which is the scripting) in that action group, you already have that.

Scripting functions for Convert "Text File - Tag".
Just curious ... which input data do you want to be scriptable in this interactive dialog?
Please provide an example.


Import text file action doesn't work for me because it imports the whole file into one field, and I use text files to backup tags for whole album (one line per track).

Right now I use "Convert > Text file - tag" and then an action group to clean up the formatting of some tags based on music format, but scripting would save me a step.

Specifically I'd like the replace function, to be able to replace delimiters in multi-value tags with \\ when importing to flac files so they get written as separate fields, and to replace line delimiters in lyrics with real line breaks.

This is exactly what a "Replace with regular expression" action can do.
So, I would say: no need for scripting during the import, but scripting may work afterwards.

As I said, that's what I currently do. Scripting in import would just save a step.

If you want to step over the interactive part of your workflow, the converter dialog, then you may use the action "Import text file". This action imports the content of the given text file into one specified tag-field. Once the data has been stored into the tag-field, you may use the Mp3tag actions and the Mp3tag scripting language to distribute the data to other tag-fields.


detlev, but that doesn't work with multiple files, does it? I mean, it just imports the whole file, not one line per track, right?

Have you tried it?
If the data you want to import has the filename then you can store as many records in the file as you want, only the line with the matching filename will get imported.
Even if you import data one data file per one audio file then you don't have to run the actions after each import but you can run them after you have imported the data for all files.
or another twist:
You can import the same data into a set of files, if you have only one record in the data file.
But for this I would use the tag panel or the extended tags dialogue.
it is all a question of workflow.

Sure, it works with multiple files.
Yes, you have to use functions from the Mp3tag Scripting Language by an "action group script", to fetch out the fitting data for the current track.
In other words ... you have to simulate the converter "Textfile - Tag".


ohrenkino, I tried it with filenames included (even with extension) and it still imports the whole file to each track.

Detlev, I can't figure out how I would "simulate" that.

What do you mean "the whole file to each track"? Of course, the whole file gets scanned but only the record is imported where the filenames match.
Please show us the pattern you use for import and at least 2 lines from the data file.
Also, tell us what you try to achieve with the concrete data: what does the file look before the import and after and what should it look like.

For short ...

  • Import by action the entire CSV or SSV text file into a temporary helper tag-field e. g. TEXT_SSV.
  • Extract by action the right fitting data-line from the tag-field TEXT_SSV for the current file, ...
    e. g. by using the currrent filepathname %_path%.
  • Import by action the tag-fields from the previously extracted data-line.

Something alike see there ...
TXT Import Dateiname = txtname


Attached is a zip-file, which contains a set of test-files.

  1. Extract all files into a folder of your wish.
  2. Move or copy the example mta file into your Mp3tag actions folder ...
  3. Invoke Mp3tag and load the files from the test folder.
  4. Select all test files and apply the example action.
  5. Check the tag-fields within the test files.
    Ready. ( 2.23K ) Number of downloads: 7
Attachment replaced by ...

DD.20150622.1900.CEST, DD.20150712.1100.CEST

Thanks, Detlev.
It works and now I get what you meant, but I can't wrap my head around that regular expression.

         "11";"Title One";"Album One";"File.11.mp3"
         "12";"Title One";"Album One";"File.12.mp3"

   FIND: '^.*\n(.+?)"'%_filename_ext%'"\r.*$'

         "12";"Title One";"Album One";

This part matches any lines from the beginning of tag field to the line that contains the %_filename_ext% of the current file.


But how can it match the end of line (EOL) with just \n when the imported text uses \r\n ?

Then this part matches the line needed for the current file and captures the text before %_filename_ext%, which will be used to replace the whole list later.


Why use \r here for line break when you used \n previously in the expression?

And, finally, this matches the remaining list all the way to the end of the field.


I also don't understand how you used single quotes. Why enclose both the expression and %_filename_ext% with them? Shouldn't that make %_filename_ext% unparsable?

'aax', you got a working example ... and it works, right?
Now you present your own rework and modification of the given example, ...
and you are asking, how it does not work?

The given example does work correct only, when the input text data file has line breaks as a pair of Carriage Return and Line Feed characters, and the file starts with a dummy header line or empty line.
Example: header line[CR][LF]any text[CR][LF]any text[CR][LF]any text[CR][LF]

In the given actionsgroup script there is an action "Format value", which uses the function $regexp() ...


Here is a little bit safer formatstring, which does not rely on an existing dummy header line or empty line in the import text file ...


This function with the given regular expression searches within the list of text lines, ...
where each line of text begins with [LF] and ends with [CR], ...
for a fitting part of text in one line, ...
dedicated by the current value of the %filename_ext% variable.

Your adaption and attempt of using the action "Replace with Regular expression" will not work, ...
because this type of action does not support the usage of Mp3tag internal variables ...
like here it is %_filename_ext%, ...
and this action does not need to have the literal parts of the parameters to be escaped by the single apostrophe.

I have attached a new example package, ...
including two example mta scripts, how to use the variables %_filename_ext% or %_path%. (7.45 KB)

DD.20150712.1055.CEST (7.45 KB)