#! /usr/bin/perl ########################################## # flac/shorten to ogg vorbis converter # stuff needed to run: perl, shntool, vorbis-tools and/or flac # USE: "perl flac2ogg.pl" ########################################### # copyright (c) 2004 stateq2 # flac2ogg is released under the GPL. # http://www.gnu.org/copyleft/gpl.html ############################################ # version 0.1 ########################################### print "enter the dir containing .shn/.flac files to be converted: "; chop ($in_dir=); print "\nenter the dir where you want the output(ogg's) to go: "; chop ($out_dir=); print "\nchoose a quality setting for the ogg vorbis files...\n"; print "(6 is a good choice for great quality and moderate filesize)\n\n"; print "0 ~= 64kbps | 5 ~= 160kbps | 10 ~= 400kbps\n"; print "choose(0-10): "; chop ($ogg_qual=); print "\n"; # if the file is .flac/.shn.... # 1.) covert .flac/.shn-->.wav # 2.) convert .wav-->.ogg # 3.) delete the .wav opendir(checkdir, "$in_dir"); while ($in_file=readdir(checkdir)) { $orig_file=$in_file; if (($orig_file !~ /\.flac$/i) and ($orig_file !~ /\.shn$/i)) {next}; print "Checking file: $orig_file\n"; if ($orig_file =~ /\.flac$/i) { $new_wav_file=$orig_file;$new_wav_file=~s/\.flac/\.wav/; } elsif ($orig_file =~ /\.shn$/i) { $new_wav_file=$orig_file;$new_wav_file=~s/\.shn/\.wav/; } # convert to wav and put it in the ouptut dir BEFORE opening the output dir # and converting the wav to ogg $convert_to_wav=`find $in_dir -iname "$orig_file" | shntool conv -o wav -d $out_dir`; ###################### # first command...in action ###################### print "1. FLAC/SHN-->WAV: $convert_to_wav\n"; $cmd=`$convert_to_wav`; if ($new_wav_file !~ /\.wav$/i) {next}; $new_ogg_file=$new_wav_file;$new_ogg_file=~s/\.wav/\.ogg/; # conver the wav to ogg, then delete the wav $convert_to_ogg="oggenc -q$ogg_qual \"$out_dir/$new_wav_file\""; $remove_wav="rm -rf \"$out_dir/$new_wav_file\""; ##################### # second and third commands...in action ##################### print "2. WAV-->OGG: $convert_to_ogg\n"; $cmd=`$convert_to_ogg`; print "DELETE WAV: $remove_wav\n"; $cmd=`$remove_wav`; print "\n\n"; } print "flac2ogg is done\n"