#! /usr/bin/perl ########################################## # flac/shorten to ogg vorbis converter # stuff needed to run: shntool, vorbis-tools, flac # USE: "perl flac2ogg.pl" ########################################### # copyright (c) 2004 stateq2 # flac2ogg is released under the GPL. # http://www.gnu.org/copyleft/gpl.html ############################################ # version 0.3 ########################################### # to do: # search dirs...recursive style # ######################################### print "enter the dir containing .shn/.flac files to be converted: "; chop ($src_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"; opendir(checkdir, "$src_dir"); while ($src_file=readdir(checkdir)) { $orig_file=$src_file; if (($orig_file !~ /\.flac$/i) && ($orig_file !~ /\.shn$/i)) {next}; print "Checking file: $orig_file\n"; # if the file is .flac, convert it to .ogg if ($orig_file =~ /\.flac$/i) { $new_ogg_file=$orig_file;$new_ogg_file=~s/\.flac/\.ogg/; $flac_to_ogg=`oggenc -q$ogg_qual \"$src_dir/$orig_file\" -o $out_dir/$new_ogg_file`; print "1. FLAC-->OGG VORBIS: $flac_to_ogg\n"; $cmd=`$flac_to_ogg`; print "\n\n"; } # else, if the file is .shn, conver it to .wav, convert .wav to .ogg, then delete wav elsif ($orig_file =~ /\.shn$/i) { $new_wav_file=$orig_file;$new_wav_file=~s/\.shn/\.wav/; $convert_to_wav=`find $src_dir -iname "$orig_file" | shntool conv -o wav -d $out_dir`; print "1. 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/; $wav_to_ogg="oggenc -q$ogg_qual \"$out_dir/$new_wav_file\""; $remove_wav="rm -rf \"$out_dir/$new_wav_file\""; print "2. WAV-->OGG VORBIS: $wav_to_ogg\n"; $cmd=`$wav_to_ogg`; print "DELETE WAV: $remove_wav\n"; $cmd=`$remove_wav`; print "\n\n"; } } print "flac2ogg is done\n"