Action to import the content of a txt file


#1

After searching I found that the latest development build has an action
for what sounds like the thing I'm after, but I don't know how to make it work.
I want to import the content of the text file into my Comments tag, there's usually
one .TXT file only in the folder I'm working with. It is usually named info.text or
foldername.txt...
Is there an easy way to do this? I think there is...
Best
---Hank


#2

I think not. Mp3tag needs to know the name of the text file.


#3

Hi - thanks.
OK, maybe I can make three different actions that will cover
most of these. Say the the file is named info.txt, how can i
make an action to import the text into my Comments tag?

Best
---Hank


#4

Well ..., you can make an action to import the text into your Comments tag in the same way as you can work with all the other Mp3tag actions (hint: see helpfile, search this forum).

General method:
Choose the right action (hint: you want to import a text file), fill in the proper values into the action form dialog (hint: your filename is 'info.txt' and you want to import the data into the comments tagfield).
Run the action against the trackfiles you want to change.

Good luck!

DD.20071128.1334


#5

Thank you for taking your time to answer me at length and especially for
providing me with the hints, very useful and I will go back to where I started
and search the forum and help file again, since I couldn't find it and couldn't
get it to work the first time. But now, with your help, I will probably find out.
---Hank


#6

I have now gone back to the Help file and searched the forum again.

The Help file didn't provide me with any info about importing a .txt file,
and neither did a search of the forum. But in the action dialogue is a preformatted
action "import from text file". All references to this new action (in the latest
development build) that I find here in the forum is more or less directed to people
who already have a detailed understanding of how it works.

Please, how do I use the different alternatives:

%_extension%
%_filename%.txt
%filetype%=TXT
%origfilename%

Seems like this is already prepared for to make it simple and easy, I just need
the description of how to go ahead.

Thanks in advance
---Hank


#7

I think you do not need any of the above listed 'different alternatives' to use 'action import' in it's normal standard simple basically mode.

You have to input only two values.

  1. The name of the tagfield you want to be filled with the data from your textfile.
  2. The filepath to the storage place of your textfile.
    The action dialog has no built in filesystem search dialog, therefore you have to type in manually the filepath or you can use copy&paste functionality by copying the proper filepath from anywhere else and pasting it into the editfield.

The german help file says:
Text-Dateien importieren
Mit dieser Aktion können Sie Inhalte einer Text-Datei in Tag-Felder übernehmen.
Als Formatstring für den Dateinamen können Sie neben einem festen Dateinamen auch Platzhalter verwenden.
Um zum Beispiel den Inhalt der Datei lyrics.txt in das Feld 'UNSYNCEDLYRICS' zu importieren, geben Sie als Feldname UNSYNCEDLYRICS und als Formatstring lyrics.txt an.

My approach of translation:
Import text files
With this action you can put data from an external text file into a tagfield.
As a format string for the filename you can use a given filepath and also use Mp3tag placeholders and scripting functions.
For example, to import the content of the file 'lyrics.txt' into the tag field 'UNSYNCEDLYRICS', enter as a field name "UNSYNCEDLYRICS" and as a format string "lyrics.txt" (without the double quotes).
Make sure that the file can be found and read from the given resp. calculated filepath.

DD.20071128.1624


#8

THANKS, this fixed a lot of my text files!

I have a follow up questions since I will now import and tag a large number of files,
they are all in folders named

artistyear-month-day.source.band.flac

This is also the way that each file is named, but
inserting "t01" etc before the "flac" at the end.

The text file is also named like this, but with .txt at the end.
artistyear-month-day.source.band.txt

My question:
I import all the folders in to the MP3tag screen and would like to
use an action to import the text file in to the Comments field...

Thanks
---Hank


#9

Hmm ..., now it looks rather simple:
Get the folder name (%directory%),
replace ".flac" by ".txt" ($replace(%directory%,.flac,.txt)),
use this as a format string and
use COMMENT as a field name in the action dialog (as described in previous post).

DD.20071203.1824.CET


#10

Thanks DetlevD, this made me understand, I can use this formula
for other things as well.

Seems like there are cases where I need to delete one part of
the folder name, to get the text file name.
Say that "band" has to be deleted as well as changing the flac to txt in
artistyear-month-day.source.band.flac

Can I do that in the same action - I tried but couldn't work it out.
How do I delete that part of the folder name?
THANKS


#11

You use filenames which are built from a bunch of items which are structured in the first level by a point and in the second level by a hyphen. Each item can have constant and/or varying content.

artistyear-month-day.source.band.t01.flac

  • item 1: artistyear-month-day
    • item 1.1: artistyear
    • -
    • item 1.2: month
    • -
    • item 1.3: day
  • .
  • item 2: source
  • .
  • item 3: band
  • .
  • item 4: 't'01 (character constant with appended varying tracknumber)
  • .
  • item 5: 'flac' (string constant)
The filename including filename extension %_filename_ext% resp. _FILENAME can be read as a list of five items delimited by a point character.
To delete a specific item from the list you have to know resp. to find it's position and remove it.

How to do this with the Mp3tag toolbox without having such list oriented functions?

Hmm ..., it seems $regexp() function can help to solve the problem.

As a regular expression your %_filename_ext% resp. _FILENAME looks like:
(.?).(.?).(.?).(.?).(flac)

Each content of an item from within a pair of rounded brackets can be used for replacement by an indicated placeholder, e. g. $1 stands for the first item from the left, $2 for the second item and so on.
So the unaltered content of %_filename_ext% resp. _FILENAME can be rebuild by this replacement expression:
$1.$2.$3.$4.$5 gives artistyear-month-day.source.band.t01.flac

To delete the third item simply remove the placeholder $3:
$1.$2.$4.$5 gives artistyear-month-day.source.t01.flac

You can create following action to delete the third item from a filename of the given format:

Action #1:
Action type: Replace with regular expression
Field: _FILENAME
Regular expression: (.?).(.?).(.?).(.?).(flac)
Replace matches with: $1.$2.$4.$5

[ ] case-sensitive comparison

DD.20071205.1230


#12

Detlev, here *V2.39f) that fails to change artistyear-month-day.source.band.flac. I can't see why. But

Regular expression: (.?).(.?).(.?).(.?)(flac)

succeeds. Puzzling.

Also, here's a more concise (though less educational) solution:

Regular expression: (....).*.(flac)
Replace matches with: $1$2


#13

Chris, be aware that I've edit my first post and added one more item to the filename!
Please check it again.

DD.20071206.0148.CET


#14

Ah yes, that's what cought me out! Thanks.


#15

Hey!
THANKS
This is great, very useable, and I am learning
a little (not all though...) on the way.
Thanks for your help
---Hank


#16

One more question... :unsure:

This works for me but I can't understand how to
find a workaround for doing this:

  • the folder where my files are is named:
    "artistyear-month-day.source.band.flac"

  • the text file I am importing to my Comment field is named:
    "artistyear-month-day.source.txt" (band is deleted)

How do write my txt import formula to make this import?

Thanks in advance

Best wishes
---Hank


#17

Hmm ..., to combine what you have learned in Post#9 and Post #11:

folder: artistyear-month-day.source.band.flac
file: artistyear-month-day.source.txt

Action:

Import from Textfile

Field:
COMMENT

Filename:
$regexp(%_DIRECTORY%,^(.?).(.?).(.?).(.?)$,$1.$2.txt)

DD.20071209.1200.CET
Edit: Changed spelling mistake from "%DIRECTORY%" to "%_DIRECTORY%".
Edit: Added colors for better visual realization.
DD.200712091403.CET


#18
QUOTE (DetlevD @ Dec 9 2007, 12:00) <{POST_SNAPBACK}>
Hmm ..., to combine what you have learned in Post#9 and Post #11:
Action  : Import from Textfile
Field   : COMMENT
Filename: $regexp(%DIRECTORY%,^(.*?)\.(.*?)\.(.*?)\.(.*?)$,$1.$2.txt)

DD.20071209.1200.CET

Thanks...I don't really understand (sort of like before) but this time
I can't get it to work...

Hmmm...to make me understand - how would this formula look if I were to
delete the "source" part in the folder name instead, to get the txt file name right?
I can't really see the way the different parts of the file name is built up.

is this correct...?

$regexp(%DIRECTORY%,^(.?).(.?).(.?).(.?)$,$1.$3.txt)

I think I am doing something wrong.

Cheers
---H


#19

See my altered previous post and try again.

Yes, regardless of my spelling mistake on the system placeholder "%_DIRECTORY%".

folder: artistyear-month-day.source.band.flac
file: artistyear-month-day.band.txt

Action:

Import from Textfile

Field:
COMMENT

Filename:
$regexp(%_DIRECTORY%,^(.?).(.?).(.?).(.?)$,$1.$3.txt)

DD.20071209.1420


#20

Thank you, everything worked like a charm!
I really appreciate your help
Best wishes
---Hank