[ale] Ripping CD's
James CE Johnson
jcej at tragus.org
Fri Jan 23 18:13:09 EST 2004
Chris Fowler wrote:
>I have made the decision to convert my huge CD collection to MP3 now
>that I have a DVD burner. My CD's take up too much room and I can just
>store them in my attic. I normally use mp3c but I would still like to
>use it but in script form to create a structure like this on disk:
>
><genre>/<artist>/<album>/<mp3>
>
>Has anyone written scripts that can do this?
>
The attached perl script is a quick hack I did in December to organize
my collection in three different ways: ByAlbum/abum/song.mp3,
ByArtist/artist/album/song.mp3, ByGenre/genre/artist/album/song.mp3. cd
to the top of a directory full of mp3s and let it go to work. It tries
to be clever with symlinks and doesn't always get things right but, hey,
it *is* a quick hack :-)
>Maybe even a perl script
>that can read the information from the mp3 file and place it in those
>directores. Maybe even outmut a
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale
>
>
-------------- next part --------------
#!/usr/bin/perl
# jcej - 12/2003
# A quick script to organize a set of MP3s
# into directories ByArtist, ByAlbum, ByGenre
use File::Basename;
use File::Find;
use File::Path;
use Getopt::Std;
use MP3::Tag;
# Additional genre's not known by MP3::Tag
my $gl = { 141 => "Christian Rock"
};
my %cl = ();
getopts("Vvg", \%cl);
if($cl{g}) {
my $genres = MP3::Tag->genres;
print join(", ", sort @$genres) . "\n";
exit 0;
}
foreach my $catalog ("ByArtist", "ByAlbum", "ByGenre") {
mkpath($catalog, 1, 0755);
}
my $options =
{
wanted => \&catalog,
no_chdir => 1,
};
find($options, @ARGV);
sub catalog {
my $file = $File::Find::name;
return if( ! -f $file || -l $file || $file !~ m/\.mp3$/ );
print "$file\n" if($cl{v} || $cl{V});
my $mp3 = MP3::Tag::->new($file);
return if( ! $mp3 );
my ($song, $track, $artist, $album) = $mp3->autoinfo();
if($cl{V}) {
my @tags = $mp3->get_tags;
foreach my $tagType (@tags) {
my $tag = $mp3->{$tagType};
while ( my ($key, $value) = each %$tag) {
print "$tagType\t$key\t$value\n";
}
}
}
my $genre = $mp3->{ID3V1}->{genre};
if($genre eq '') {
my $genreID = $mp3->{ID3v1}->{genreID};
$genre = $mp3->genres($genreID);
if($genre eq '') {
$genre = $gl->{$genreID};
}
if($genre eq '' || ref($genre)) {
$genre = 'UNKNOWN';
}
}
my $byAlbum = "$album/$song" . "\.mp3";
my $byArtist = "$artist/$byAlbum";
my $byGenre = "$genre/$byArtist";
makeLink($file, "ByArtist/$byArtist");
makeLink($file, "ByAlbum/$byAlbum");
makeLink($file, "ByGenre/$byGenre");
}
sub makeLink {
my($from, $to) = @_;
my $dir = dirname($to);
mkpath($dir, 1, 0755);
my $prefix = calculatePrefix($to);
symlink($prefix . $from, $to);
}
sub calculatePrefix {
my $file = shift;
my $pfx = "";
while(($file = dirname($file)) ne '.') {
$pfx .= "../";
}
return $pfx;
}
More information about the Ale
mailing list