#!/usr/bin/perl -w
use strict;
use MP3::Info;
use File::Copy;
use File::Spec::Functions;
#Doesn't understand about compilation CDs.
my $format_for_priya = 0;
foreach my $tagged_mp3 (@ARGV) {
my $tags_hashref = get_mp3tag($tagged_mp3) or die "No TAG info";
my $track_number = 0 + $tags_hashref->{TRACKNUM};
#Convert strings to numbers
$track_number = "0" . $track_number unless ($tags_hashref->{TRACKNUM} > 9);
#Add leading zero to single digits
# my $new_file_name = "$tags_hashref->{ARTIST}/$tags_hashref->{ALBUM}/$track_number - $tags_hashref->{ARTIST} - $tags_hashref->{TITLE}.mp3";
my $new_file_name = catfile($tags_hashref->{ARTIST}, $tags_hashref->{ALBUM}, "$track_number - $tags_hashref->{ARTIST} - $tags_hashref->{TITLE}.mp3");
if ($format_for_priya == 1) {
#Don't include the artist, and truncate filename to 27 chars + extension
my $priya_name = "$track_number-$tags_hashref->{TITLE}";
$priya_name =~ s/(.{0,27}).*/$1/;
$new_file_name = catfile($tags_hashref->{ARTIST}, $tags_hashref->{ALBUM}, $priya_name . ".mp3");
}
$new_file_name = lc($new_file_name);
# print $new_file_name;
my $artist_dir = lc($tags_hashref->{ARTIST});
unless (-d $artist_dir) {
mkdir($artist_dir, 0755) || die "Cannot mkdir $artist_dir: $!";
}
# my $album_path = $artist_dir . "/" . lc($tags_hashref->{ALBUM});
my $album_path = catfile($artist_dir , lc($tags_hashref->{ALBUM}));
unless (-e $album_path) {
mkdir($album_path, 0755) || die "Cannot mkdir $album_path: $!";
}
print "$tagged_mp3 Changed To:
";
print $new_file_name . "
";
copy ($tagged_mp3, $new_file_name) or die "couldnt copy files because $!";
#system ("cp $tagged_mp3 $new_file_name");
}
snippets |
December 24, 2011
Move MP3s into Artist/Album folders
Leave a Reply Cancel reply
You must be logged in to post a comment.