📜 ⬆️ ⬇️

Creating cue playlists for a list of mp3 files from a folder

Very often, after downloading the latest music from torrents, I see that the author of the distribution either did not register the tags in mp3, or did not register them correctly. If you fix these mp3-files and register normal tags in them, then I will not be able to sit just downloaded. Which is not very good. On the other hand, I collect my musical statistics in last.fm and I want to keep tags up to date. There is, of course, the option to copy just downloaded music to a separate place and fix tags there, but this is somehow unsportsmanlike.

The first ten times I created the cue-playlist manually, but then I remembered that I still had a connection with programming and wrote a small Perl script that creates a cue-playlist in the list of mp3 files. Now you can change the information about the artist, album, song titles in it, without physically touching the mp3-shki. These playlists are perfectly readable by foobar.

The script has one parameter: pattern - the code that is executed for each file. In this code snippet, the variables $ track, $ title and $ performer should be set - this is the track number, song title and artist, respectively.
For example, for file names like “22. Baby I Need Your Loving - Four Tops.mp3 "script should be called like this:
perl c: \ util \ playlist_cue.pl "--pattern = ($ track, $ title, $ performer) = $ f = ~ / (\ d \ d) \. (. +) - (. +) \. mp3 /; " >> playlist.cue
It is believed that the playlist.cue file already contains information about the album.
')

 use strict;
 use warnings;
 use Getopt :: Long;

 my ($ track, $ performer, $ title);
 my $ pattern = '($ track, $ title) = $ f = ~ / (\ d *) - (. +) \. mp3 /';
 GetOptions ("pattern = s" => \ $ pattern);

 for my $ f (<*. mp3>) {
 eval ($ pattern);
 print << ITEM;
   FILE "$ f" MP3
	 TRACK $ track AUDIO
	 TITLE "$ title"
 ITEM
 if (defined $ performer) {
	 print "\ tPERFORMER \" $ performer \ "\ n";
 }
 print << ITEMEND
	 INDEX 01 00:00:00
 ITEMEND
 }


As a result of the script, it turns out something like (the cap was written manually):
 REM GENRE Motown
 REM DATE 1992
 PERFORMER "Various Artists"
 TITLE "Hitsville USA: The Motown Singles Collection 1959-1971 (disc 1)"  
    FILE "01. Money (That's What I Want) - Barrett Strong.mp3" MP3
	 TRACK 01 AUDIO
	 TITLE "Money (That's what i want)"
	 PERFORMER "Barrett Strong"
	 INDEX 01 00:00:00
   FILE "02. Shop Around - The Miracles.mp3" MP3
	 TRACK 02 AUDIO
	 TITLE "Shop Around"
	 PERFORMER "The Miracles"
	 INDEX 01 00:00:00
   FILE "03. Please Mr. Postman - The Marvelettes.mp3" MP3
	 TRACK 03 AUDIO
	 TITLE "Please Mr. Postman"
	 PERFORMER "The Marvelettes"
	 INDEX 01 00:00:00
   FILE "04. Jamie - Eddie Holland.mp3" MP3
	 TRACK 04 AUDIO
	 TITLE "Jamie"
	 PERFORMER "Eddie Holland"
	 INDEX 01 00:00:00


Now the names of tracks and artists can be corrected without affecting the original mp3-shki.

In this way, you can leave even those mp3-files in tags that you are not satisfied with.

Corrections, notices and normal simple solutions are welcome.

Source: https://habr.com/ru/post/65259/


All Articles