This code is to read the tags from MP3's and then move them into directories based on that. That works just peachy, but my problem is, what if I want to move them into dirs according to album, not artist? I have sat and thought on this extensively and have come up with nothing except putting the album tag into an array or hash (I'm clueless on hashes) and checking against it. If the album is already in the array/hash check for corresponding artists, if so, make your dirs. The other problem with my solution is, what about soundtracks and such, where more than one artist appears on the CD?
#!/usr/bin/perl -w
use MP3::Info;
use File::Find;
use File::Basename;
find(\&wanted, "/MP3");
sub wanted
{
/\.mp3$/ && do
{
my $tag = &MP3::Info::get_mp3tag($File::Find::name,1,1);
$artist = $tag->{ARTIST} or die "$File::Find::name has no TAG info
+";
$prev_artist = "me";
my($dir) = $File::Find::dir;
$artist =~ s/ /\\ /g;
if ($artist ne $prev_artist)
{
$FName = "\"" . $File::Find::name . "\"";
print "I shall be making these directories\: $dir/$artist\n";
qx { mkdir $dir/$artist ; mv $FName $dir/$artist };
$prev_artist = $artist;
}
}
}
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.