How to reverse $loop to add tags from csv.

Here's what I'm trying to do.
I used musicbrainz to tag my files. But it set the genre per song. Not band. So when I organize the files on my hard drive by genre each band has files all over the place. It's annoying.

I was able to export tags to a csv. And I limited it to 1 per artist:

More after I go through and double check the groupings and genres are correct. How do I get mp3tag to pull those tags from the csv to tag every file based the csv file.

Csv file:
Metallica;metal;Heavy Metal
Savatage;Metal;Power Metal
Motley Crue;Rock;Hard Rock

The csv only has each band listed once.
But I want to apply that to every mp3 for that band.

Is that possible?

I think that Musicbrainz is right - every artist features several genres.
When you created the export, limited to one record per artist but the files feature different genres - which genre was taken for the csv-export? The first? or a random one? is this correct?
You would have to create an export where the number of records matches the number of files.

Or you filter by each group name and enter the favoured genre manually.

Musicbrainz allows grouping and genre. There's why I exported both. Grouping is the main genre. Rock, metal, rap, etc. Then the second is the sub genre. Hard rock, Southern rock, heavy metal, death metal, power metal, etc.. So really I want to add both of those back to the tags but keep them the same for the artist in the csv file.

So I can cycle through the artist tags and limit the export by 1 per artist. But I can't then import and check each artist to set the same genre using the exported csv file?

It would a lot easier, if we could see the export script.

Now: if you have several genres per artist

Of couse you can group the export by artist. But then? You can apply the same to genre. But the restriction to "1" means that only one record is created per unique entry.
But as the genres may be different, you would still get a list with all the different genres per artist.

Would create one record per file.
Still: if the genre varies, even with the limitation to "1", you would still get various genres per artist. MP3tag does not compare between files.

And again: I would revise the storing criteria. You are quite right when you say that using genre as superior ordering criterion, files of a group get spread all over the file system.
So why don't you leave the grouping by genre to the player and use the shipping unit "artist, album" as the way to create the folders in the file system. Then you have all the files from one artist in one place.

So here is my export script:


The reason i'm wanting to do this, is i'd rather go through and fix the GenreGroup, and the Genre on 2,700 Artists, instead of doing it for 44,000 files.

The problem with Having the player decide the genre and sort them by artist/album. is my car won't read genre tag info from the USB Drive. So by organizing by GenreGroup/Genre/Band/Album. I can easily find songs/bands/albums I want to listen to, or even just put the whole genre folder on random. and sure some bands have different genres. but some the data is just wrong. like Godsmack is in: Metal/Heavy Metal, Rock/Hard Rock, Classic Rock/Hard Rock, Rock/Post-Grunge, Metal/Nu-Metal. when it should probably all be in Metal/Heavy Metal. Or Like Metallica's Mama Said. is very country inspired. but cause it's Metallica it probably shouldn't have that song in the country folder.

You would have to rewrite the 44,000 files anyway as otherwise the data would stay the same.

Doesn't the car stereo support playlists? These could be created with MP3tag even from the data on a thumb drive.

Looking at your export script I would say that the resulting genre is more or less random and you could end up with Metallica getting "Country" as this could be the first entry that the export generator comes across.
I am sure that you have to set a sort of "master" genre for each artist. Otherwise you become the slave of the entry which ever comes first.
I still think that you would have to decide manually anyway what you think the appropriate genre for each group would be.

You could run an export that lists all the genres for an artist just to see what data is already there.
So I would run my suggestion of a script first to get an overview.

Then you could modify the script and set your default genre for each file.
Then run the import.

And by that you could just as well filter for each artist and do it manually for each artist... that would save you the export and import.

Mp3tag works with files.
If you want to import data from an external text file into tagfields within a music file, then you have to provide a text file, which contains data for each music file separately.

Now you have a text file, which contains data related to the artist name on a per line basis.
The standard data import functionality cannot handle this situation, because it relies on and works with the relation to an unique filepath.

But you can import all lines of data from the external text file into one helper tagfield into each target file.

Then apply the $regexp function or some other functions from the Mp3tag scripting language, to search and to fetch out the one and only text line from within the helper tagfield, which fits to the artist name from within the tag of the current music file.

If there is a match between the artist name and the artist name within the CSV helper tagfield, then update the related tagfields within the musicfile by the CSV data from the helper tagfield.

After all searching and replacing has been done, then remove the helper tagfield.


That sounds like a great solution to my issue. Though the scripting/process and regex to do it is well beyond my abilities for sure. But I do see the logic behind it.

Well, ... it is a technical solution but is it also practical?
You would add a helper field with the data for all the 2,400 artists to every of the 40,000 files. This will increase the size of each file and take quite some time
Then you adapt the genre field,
then you delete the helper field again.

The question that is still unresolved: how do you know that the record you have for each artist actually shows the correct genre and not just any random genre that happened to be the first one to be found for an artist. So you would have to check each of the records first and see if the pair of artist and genre is correct.

And as I said before: this check would probably take just as long as doing it manually for each group with filtering and writing the correct genre straightaway.

So it might be a good idea to find just those artists that feature more than one genre with an export

would show each artist and all the genres for that artist.

With a suitable external program (like Excel or Access) you can check for duplicates - and have to treat only those artists that appear as duplicates as only those have multiple genres.

I assume that Mp3tag does all such action work within physical RAM memory, and the resulting tag-structure with only one tagfield changed will be written only once into the musicfile.