The script below will search through a given directory for all mp3 files, determine the artist and title from the filename, and then group them into directories by artist. It makes sorting MP3's a lot less tedious. Be sure to check all the directory paths before you run it on your collection.
Update: Now bases information on ID tags of MP3 file instead of title.
#!/usr/bin/perl
use warnings;
use strict;
use File::Copy;
use MP3::Info;
chdir "d:\\music\\new";
my ($artist, $song, $dirname, $wait, $info);
while(glob("*.mp3"))
{
$info = get_mp3tag($_);
($artist, $song) = ($info->{ARTIST}, $info->{TITLE});
next unless $artist and $song;
$dirname = "..\\" . $artist;
$dirname =~ s/the//g;
$dirname =~ s/ /_/g;
$dirname =~ s/^\s*//g;
$dirname =~ s/\s*$//g;
$dirname = lc $dirname;
if(!(-e $dirname and -d $dirname))
{
print "Create $dirname folder?";
mkdir $dirname if <STDIN> =~ /^y/;
}
if(-e $dirname and -d $dirname)
{
print "moving $artist - $song.mp3 to $dirname folder.\n";
move($_, "$dirname\\$artist - $song.mp3");
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.