/ Published in: Perl
Given a directory of MP3s, read the ID3 tags and reorganize the directory so that all of the MP3s reside in folders that are nested in the order: Artist/Album/File.mp3
Expand |
Embed | Plain Text
#!/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 $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"); } # print $new_file_name; unless (-d $artist_dir) { } # my $album_path = $artist_dir . "/" . lc($tags_hashref->{ALBUM}); unless (-e $album_path) { } print "$tagged_mp3 Changed To:\n"; #system ("cp $tagged_mp3 $new_file_name"); }
You need to login to post a comment.
