#!/usr/bin/perl use strict; use File::Find; use File::Copy; use MP3::Info; use Getopt::Long; # Copyright 2003, # www.Geekuprising.com Internet Consultants # You are free to modify and distribute this script as long as # credit is given to the author. my $bitrate='96'; my $result=GetOptions( 'bitrate=i'=>\$bitrate, ); my $root=$ARGV[0]; my $new_root=$ARGV[1]; chomp($new_root); chomp($root); my $error = check_directory($root,"Source"); $error .= check_directory($new_root,"Destination"); if($error){ print < bitrate The bitrate to resample down to, default is 96. Source The directory to start from. Must end with a trailing slash. Destination The destination directory. Must end with a trailing slash. EOT } else { find(\&wanted,($root)); } ################################################################################ sub wanted { if (/\.mp3$/i) { my $full_name=$File::Find::name; my $dir=$File::Find::dir; my $new_dir=$dir; $new_dir=~ s/$root/$new_root/; my @path=split(/\//,$new_dir); my $path_to_make; foreach ((@path)) { $path_to_make.="/$_"; if (! -e $path_to_make) { mkdir ($path_to_make); } } my $info=get_mp3info($full_name); if (($info->{BITRATE} > $bitrate)) { print "\n$_ is at ".$info->{BITRATE}."kbps. Resampling!\n\n"; system('lame','-b',$bitrate,'-h',$full_name,$new_dir.'/'.$_); } else { print "$_ is already $info->{BITRATE} which is less than the desired bitrate of $bitrate. Copying.\n\n"; copy($full_name,$new_dir.'/'.$_); } # push @files,$full_name; } } ######################################## ################################################################################ sub check_directory{ my $directory=shift; my $type=shift; my $error; if(substr($directory,-1) ne '/'){ $error.="All directories MUST end with a trailing slash.\n"; } if(!$error && ! -e $directory){ $error.="$type directory doesn't exist.\n"; } return $error; } ########################################