#!/usr/bin/perl -w use strict; main(); sub main { if(@ARGV < 3) {die "Usage: wrapid3 author album filenames..\n";} my $author = $ARGV[0]; my $album = $ARGV[1]; my @fns; foreach my $ofn (@ARGV[2 .. $#ARGV]) { if( -f $ofn ) {push(@fns, $ofn);} elsif( -d $ofn ) { opendir(DIR, $ofn) || die "Internal error\n"; my @files = map {"$ofn/$_"} grep {!/^\./} readdir(DIR); closedir(DIR); push(@fns, @files); } } foreach my $fn (@fns) { my $mode; # print "$fn\n"; my $cfn = $fn; $cfn =~ s/^.*\///; # Remove path $cfn =~ s/^\d*-//; $cfn =~ s/^.*-//; # EXPERIMENTAL! if($cfn =~ s/\.mp3//i) {$mode = "mp3";} elsif($cfn =~ s/\.ogg//i) {$mode = "ogg";} else {warn "Skip unrecognized-typed file [$fn]\n";next;} $cfn =~ tr/_/ /; $cfn = join(' ', map{ucfirst($_)} split(/ /, $cfn)); # print "$fn => $cfn\n"; # print "\tauthor: $author\n\talbum: $album\n"; if($mode eq "mp3") { `id3v2 -D \"$fn\"`; `id3v2 -t \"$cfn\" -a \"$author\" -A \"$album\" \"$fn\"`; } elsif($mode eq "ogg") { `vorbiscomment -w -t "artist=$author" -t "album=$album" -t "title=$cfn" "$fn"`; } } }