#!/usr/bin/perl -w # # empegload: # # Copyright (c) 2002 Paul Warren # use Empeg; use MP3::ID3v1Tag; use Getopt::Long; # # Root directory for uploaded files # my $ROOT = "artists"; # # Directories to sort artists into. Set to undef to avoid this # functionality. These directories must exist on the Empeg. # my $ALPHA_SPLIT = [ "A-F", "G-L", "M-R", "S-Z" ]; # # usage: display usage message # sub usage() { print< \$verbose, "verbose" => \$verbose)) { usage(); } if(!@ARGV) { usage(); } my $et = new Empeg::Emptool(); foreach my $file (@ARGV) { if(! -f $file) { print "$file is not a regular file\n"; next; } if($verbose) { print "Processing \"$file\"\n"; } if(!$et->chdir("/".$ROOT)) { die "Couldn't change to root directory"; } my $mp3_file = new MP3::ID3v1Tag($file); if(!$mp3_file->got_tag()) { print "No tag found in \"$file\". Skipping.\n"; next; } (my $album = $mp3_file->get_album()) =~ s/\//-/g; (my $artist = $mp3_file->get_artist()) =~ s/\//-/g;; my $title = $mp3_file->get_title(); if($verbose) { print $mp3_file->get_artist() . " // " . $mp3_file->get_album() . " // " . $mp3_file->get_title() ."\n"; } if($ALPHA_SPLIT) { my $ch = lc(substr $artist, 0, 1); my $file; foreach(@$ALPHA_SPLIT) { if($ch ge lc(substr $_, 0, 1) and $ch le lc(substr $_, $#_, 1)) { $file = $_; last; } } if(!$file) { die "Could figure out where to file: $artist"; } if(!$et->chdir($file)) { die "Couldn't change to $file"; } if($verbose) { print "Filing in $file\n"; } } # # Change to artist directory # if($et->chdir($artist)) { if($verbose) { print "Artist \"$artist\" found\n"; } } else { print "Creating \"$artist\"\n"; if(!$et->mklist($artist)) { die "Could not create $artist"; } if(!$et->chdir($artist)) { die "Could not change to newly created list \"$artist\""; } } # # Change to album directory # if($album) { if($et->chdir($album)) { if($verbose) { print "Album \"$album\" found\n"; } } else { print "Creating \"$album\"\n"; if(!$et->mklist($album)) { die "Could not create $album"; } if(!$et->chdir($album)) { die "Could not change to newly created list \"$album\""; } } } else { print "No album\n"; } if($et->exists($title)) { print "Title \"$title\" already exists\n"; } else { print "Uploading file $file\n"; if(!$et->upload($file)) { die "Error uploading file\n"; } } } $et->sync();