#!/usr/bin/perl # # Copyright (c) 2004 - Jason L. Buberel - jason@buberel.org # Licensed under the GNU GPL. use Getopt::Long; use File::stat; #$sourceDirPrefix = "/cygdrive/z/flac_encoded"; #$destDirPrefix = "/cygdrive/z/ogg_encoded"; $sourceDirPrefix = "/home/shared/Audio/music/flac_Sorted"; $destDirPrefix = "/home/shared/Audio/music/mp3_96"; $quality = 96; GetOptions ( "source:s" => \$sourceDirPrefix, "dest:s" => \$destDirPrefix, "quality:i" => \$quality, "force" => \$force ); # Commands #$oggCommand = "/cygdrive/f/Program Files/vorbis-tools-1.0.1-win32/bin/oggdec.exe"; #$oggCommand = "oggenc.exe"; #$oggCommand = "oggenc"; $convertCommand = "lame"; #$flacCommand = "/cygdrive/f/Program Files/flac-1.1.0-win/bin/flac.exe"; #$flacCommand = "flac.exe"; $flacCommand = "flac"; #$cygpathCommand = "cygpath.exe"; $cygpathCommand = ""; @dirs = `cd "$sourceDirPrefix" && find . -type d -print`; @files = `cd "$sourceDirPrefix" && find . -type f -name "*.flac" -print`; # Check to see if our find command found anything to convert. if ( scalar @files == 0 ) { die "Found no .flac files to convert!"; } # recreate the directory hierarchy foreach $dir (@dirs) { $dir =~ s/\n$//; $dir =~ s/^\.\///; # check to see if the destination dir already exists if ( !(stat ("$destDirPrefix/$dir")) ) { # stat failed so create the directory print "Creating output dir:\n $destDirPrefix/$dir\n"; $dir =~ s/\`/\'/g; $result = `cd "$destDirPrefix" && mkdir -p "$dir"`; } } # now process the actual sound files. foreach $file (@files) { $file =~ s/\n$//; $file =~ s/^\.\///; #print "F: $destDirPrefix/$file\n"; # figure out what the destination file would be... $destinationFile = $file; $destinationFile =~ s/\.flac*/\.mp3/; #print "D: $destinationFile\n"; # now stat the destinationFile, and see if it's date is more recent # than that of the original file. If so, we re-encode. # we also re-encode if the user supplied --force $srcInfo = stat ("$sourceDirPrefix/$file"); $srcModTime = $srcInfo->mtime; $destInfo = stat ("$destDirPrefix/$destinationFile"); if ( $destInfo ) { $destModTime = $destInfo->mtime; print "DEST_MOD: $destModTime :: SRC_MOD: $srcModTime :: FORCE: $force\n"; } # if the destination file does not exist, or the user specified force, # or the srcfile is more recent then the dest file, we encode. if ( !$destInfo || $force || ( $srcModTime > $destModTime) ) { $file =~ s/\`/\'/g; # we need to dosify the paths... # $inFile = `$cygpathCommand --windows "$sourceDirPrefix/$file"`; $inFile = $sourceDirPrefix . '/' . $file; # chop ($inFile); # $outFile = `$cygpathCommand --windows "$destDirPrefix/$destinationFile"`; $outFile = $destDirPrefix . '/' . $destinationFile; # chop ($outFile); print "ENCODE: $inFile ==> $outFile\n"; $inFile =~ s/\0//g; $outFile =~ s/\0//g; # $result = `$oggCommand -q $quality -o "$outFile" "$inFile"`; $result = `flac -dcs "$inFile" | $convertCommand -b $quality - "$outFile"`; } }