Text files export/import, with 1 text file by folder

Hi,

Haven't been there for a while, but let me say first that MP3Tag is nicer than ever. :music: However, there's something I can't seem to achieve, probably because I'm doing it the wrong way.

My goal is to save in a text file any tag that can't be deduced from the path/filename (musicians, band members, producer etc.). I can't use a single file for the whole collection because I often reorganize it (add or delete folders etc.). So I went the "1 folder = 1 file" way.

Here's my folder structure:

<Artist><Album Artist> ¦ ¦ ¦ <Disc> ¦ ¦ .wv

To export my tags, I'm using this filename:

%_folderpath%%_directory%.txt

And the script code is (reduced to 3 tags for this example):

$loop(%_path%)%producer%|$meta_sep(musicians,\\\\)|%label%
$loopend()

All is well: the result is one text file in each folder (album, single, EP etc.), formatted like this, with one line by track:

Nile Rodgers|Tommy Mandell\\\\Steve Ferrone|Reprise
Don Was|Sara Lee\\\\Philippe Saisse\\\\Sonny Emory|Reprise
Don Was|Sara Lee\\\\Sonny Emory\\\\|Reprise
(etc.)

Now's the problem: how can I reimport these tags?

If I understand correctly, the "Convert > Text file - Tag" is only working with one text file for the whole operation. But my way is to have one text file by folder, and I have more than 3000 folders. <_<

The "Import text file" action, is very nice, but again it seems I can't use it: the whole text is added to one field only. I thought I would import each line to its track, in a tag named "Whole" or something, than use a "Split fields by separator" action. But to achieve this, I need each line in the text file to be added to the right track, instead of every line added to all tracks.

I'm pretty sure there's a workaway. Maybe I'm doing the export the wrong way? If anybody can put me on track with this problem...

QUOTE (BoraBora @ Apr 10 2009, 12:32) <{POST_SNAPBACK}>
... To export my tags, I'm using this filename:
%_folderpath%%_directory%.txt

And the script code is (reduced to 3 tags for this example):

$loop(%_path%)%producer%|$meta_sep(musicians,\\\\)|%label%
$loopend()

All is well: the result is one text file in each folder (album, single, EP etc.), formatted like this, with one line by track:

Nile Rodgers|Tommy Mandell\\\\Steve Ferrone|Reprise
Don Was|Sara Lee\\\\Philippe Saisse\\\\Sonny Emory|Reprise
Don Was|Sara Lee\\\\Sonny Emory\\\\|Reprise
(etc.)

Now's the problem: how can I reimport these tags?
...


Well, you are on the right way ...
Saving tag field content into a file is not your problem, you've managed this already.

In order to store back each entry line from your exported textfile to the correspondend physical file in your music folder (that means to restore tag field content into the right file) there have to be a unique link between the source entry line and the target file.

This link or binding is realized by putting the fully qualified filepath string of the current file into the export textfile along with the tag fields content (easy done while exporting) and refer to this path value while restoring.

Your example export/import file should be changed to the following structure:

Nile Rodgers|Tommy Mandell\\\\Steve Ferrone|Reprise|%_path%

Don Was|Sara Lee\\Philippe Saisse\\Sonny Emory|Reprise|%_path%
Don Was|Sara Lee\\Sonny Emory\\|Reprise|%_path%


with %_path% actually replaced by the current filepath of the correspondend file.

You have to change your export script code:

$loop(%_path%)%producer%|$meta_sep(musicians,\\\\)|%label%|%_path%

$loopend()

Using Mp3tag/converter/textfile-tag
Filename : %_folderpath%%_directory%.txt
Formatstring: %producer%|%musicians%|%label%|%path%
you should be able to restore all the tag fields content you've saved before.

DD.20090410.2036.CEST

Thanks a lot for this very complete answer, DetlevD. :slight_smile:

Unfortunately, I still have a problem: trying to importing the file with "Convert-->Text file - Tag" produces this error:

Maybe I need to create a custom action because the "Convert text file-Tag" can't interpret the "%_folderpath%%_directory%" part?

Importing tags from a text file "%_folderpath%%_directory%.txt" looks feasible to me.

Can you elaborate how you have created this string?

File "K:\B\B-52's\B-52's (The) ¦ 1998-05 ¦ Time Capsule ¦ LP\\%_folderpath%%_directory%.txt" cannot be opened for reading.

This string seems to contain a pipe character which is a forbidden character in the filesystem.

DD.20090411.0849.CEST

I use it as separator between fields in my files. That's the "Alt+0166" character and so far never caused a problem, either in Windows, MP3Tag or Foobar. Still, I wanted to be sure, so I copied 2 folders with 2 files each to a "test" folder, simplified my structure and deleted any potentially problematic character. I even deleted the multivalued tag, just in case. Here's the rundown:

My files :

K:\Tests\B-52s _ 1990 _ Dance This Mess Around _ LP\06 _ B-52s _ Dance This Mess Around.wv
K:\Tests\B-52s _ 1990 _ Dance This Mess Around _ LP\10 _ B-52s _ Song For A Future Generation.wv

K:\Tests\B-52s _ 1998 _ Time Capsule _ LP\04 _ B-52s _ Quiche Lorraine.wv
K:\Tests\B-52s _ 1998 _ Time Capsule _ LP\05 _ B-52s _ Mesopotamia.wv

The export script filename:

%_folderpath%%_directory%.txt

The export script:

$loop(%_path%)%track%|%title%|%year%|%_path%
$loopend()

The result: 1 text file in each folder:

K:\Tests\B-52s _ 1990 _ Dance This Mess Around _ LP\B-52s _ 1990 _ Dance This Mess Around _ LP.txt

06|Dance This Mess Around|1990|K:\Tests\B-52s _ 1990 _ Dance This Mess Around _ LP\06 _ B-52s _ Dance This Mess Around.wv
10|Song For A Future Generation|1990|K:\Tests\B-52s _ 1990 _ Dance This Mess Around _ LP\10 _ B-52s _ Song For A Future Generation.wv

K:\Tests\B-52s _ 1998 _ Time Capsule _ LP\B-52s _ 1998 _ Time Capsule _ LP.txt

04|Quiche Lorraine|1998|K:\Tests\B-52s _ 1998 _ Time Capsule _ LP\04 _ B-52s _ Quiche Lorraine.wv
05|Mesopotamia|1998|K:\Tests\B-52s _ 1998 _ Time Capsule _ LP\05 _ B-52s _ Mesopotamia.wv

So far, everything's fine. :slight_smile: Now the import. "Convert" --> "Text File - Tag".

File name:

%_folderpath%%_directory%.txt

The format string:

%track%|%title%|%year%|%path%

And again this error:

I'm at a loss... :frowning:

Because the filepath contains white spaces which break the filepath into multiple components, you have to put quote chars " around the filepath, e. g. instead of %_path% use"%_path%".

DD.20090412.0957.CEST

Thanks for your patience, DetlevD. :slight_smile:

I put quotation marks, but the error was still there. I then shuffled a bit my files and switched the path placeholder in the first position and... nothing. Here's my last try:

The text files after the export, each in the right place :

K:\B\B-52s\B-52s _ 1990 _ Dance This Mess Around _ LP\B-52s _ 1990 _ Dance This Mess Around _ LP.txt

"K:\B\B-52s\B-52s _ 1990 _ Dance This Mess Around _ LP\06 _ B-52s _ Dance This Mess Around.wv"|06|Dance This Mess Around|1990
"K:\B\B-52s\B-52s _ 1990 _ Dance This Mess Around _ LP\10 _ B-52s _ Song For A Future Generation.wv"|10|Song For A Future Generation|1990

K:\B\B-52s\B-52s _ 1998 _ Time Capsule _ LP\B-52s _ 1998 _ Time Capsule _ LP.txt

"K:\B\B-52s\B-52s _ 1998 _ Time Capsule _ LP\04 _ B-52s _ Quiche Lorraine.wv"|04|Quiche Lorraine|1998
"K:\B\B-52s\B-52s _ 1998 _ Time Capsule _ LP\05 _ B-52s _ Mesopotamia.wv"|05|Mesopotamia|1998

As you can see, the path is now between quotes. Now the import:

The filename

%_folderpath%%_directory%.txt

The script:

%path%|%track%|%title%|%year%

End result:

What's weird in the error message is that the placeholders are not converted, as if the action couldn't understand it. :huh:

Ok, now it's time to rebuild your example in my environment.
My Folder:
"O:\Tests\B-52s _ 1998 _ Time Capsule _ LP"

  • including files:
    "04 _ B-52s _ Quiche Lorraine.wv"
    "05 _ B-52s _ Mesopotamia.wv"
  • including control textfile:
    "B-52s _ 1998 _ Time Capsule _ LP.txt"

Content of control textfile:

04|Quiche Lorraine|1998|"O:\Tests\B-52s _ 1998 _ Time Capsule _ LP\04 _ B-52s _ Quiche Lorraine.wv"
05|Mesopotamia|1998|"O:\Tests\B-52s _ 1998 _ Time Capsule _ LP\05 _ B-52s _ Mesopotamia.wv"

Using converter dialog:

Convert | Text file - Tag | ALT+4
Select format string
Filename:
O:\Tests\B-52s _ 1998 _ Time Capsule _ LP\B-52s _ 1998 _ Time Capsule _ LP.txt
Format string:
%track%|%producer%|%year%|"%_path%"

gives preview:

"O:\Tests\B-52s _ 1998 _ Time Capsule _ LP\04 _ B-52s _ Quiche Lorraine.wv" ->
track: 04
producer: Quiche Lorraine
year: 1998

"O:\Tests\B-52s _ 1998 _ Time Capsule _ LP\05 _ B-52s _ Mesopotamia.wv" ->
track: 05
producer: Mesopotamia
year: 1998

This works.

Next try.
Same dialog using filename "%_folderpath%%_directory%.txt" gives error message:

File "O:Tests\B-52s _ 1990 Dance This Mess Around _ LP\\%_folderpath%%_directory%.txt" cannot be opened for reading.

So what's going wrong?

There seems to be something going wrong with the creation of the proper working path.
The error the message speeks about a "%_folderpath% ..." situated in the folder structure down under the files home directory, well, such a path cannot work.
This fault guides us to several assumptions, ... after hours of speculative investigations ..., at last we look again at the dialog window.

We easily can see: right away from the filename entry field there is button to invoke a file browse dialog. Note: There is no option to open a tag field variable pick list!
It seems so, better to say, it is obvious, that the programmer has not designed or allowed to use tag field variables for assembling the filename!
The error message makes it obvious: an emebdded %variable% is not substituted by any value.

Result of exploration:
The dialog "Textfile - Tag" does not allow any tag field variable within the filename edit field.
In other words: This dialog's filename entry is not scriptable.

This is a bit of a shame, because consequently the use of system variables such as USERNAME or APPDATA is not feasible in the composition of the filename (but this should be allowed anyway!).

DD.20090413.1715.CEST

Now I know I was doomed from the beginning. :smiley:

I guess there's only two ways to achieve what I want to do, right now:

  • Use some utility to concatenate my text files in 1 big file, then use the Alt+4 action. Not really easy if I want some of them only to be processed.

  • Use the "Import text file" action, which will import every line of the text file in every folder track. Then parse it with a regular expression to delete any line not related to each track. Then parse this line with a "Split fields by separator" action. The second part is quick and easy, but the first one is way beyond my pathetic scripting skills (or sould I say: my total lack of scripting skills :smiley: ).

I'll post a feature request in the appropriate forum. Maybe Florian could plan such a feature for a future version, if it seems appropriate to him.

Thanks again for your time, DetlevD, you've been very helpful. :slight_smile:

Clever idea - should not be too complicated to implement as you can use the content of %_path% variable to identify resp. to isolate the correct line of text, and split it by "guess values" afterwards.

You are welcome, I'm pleased to help you.

DD.200900413.1755.CEST

Long time ago I have envolved a procedure to do a lookup in a table.
Maybe you can need this to do your work.
Add composer if title matches from text file?

DD.20090414.1011.CEST

NowI know what I'll be doing tonight. :smiley: