Geoff Rivell on 9 May 2004 21:07:02 -0000 |
I'm hitting the tail end of this conversation, but if I'm reading this right... You want to recode flac's to mp3's and ogg's?? If so this may be of use: ######################################################################## # transcode # # A "front-end" script for transcoding from FLAC to either # FLAC, Ogg Vorbis, or MP3 # ######################################################################## #!/bin/bash ######################################################################## # User-Defined Variables: # Where do you want your transcoded files to go? TRANSCODED_DIR=/Music/ogg # FLAC command-line options FLAC_OPS="--best" # Ogg Vorbis (oggenc) command-line options VORBIS_OPS="-q 6" # MP3 (lame) command-line options (quality only; ID3 tag options are below) LAME_OPS="--alt-preset standard" ######################################################################## # Non-User-Defined Variables: # This part sorts out the copying of subdirectories in the tree TOP_WORKING_DIR=`pwd` TOP_WORKING_DIR_LENGTH=`expr length "$TOP_WORKING_DIR"` let "PATH_CUT_LENGTH=$TOP_WORKING_DIR_LENGTH+2" TODAY=`date -I` # This variable is set at the command line - flac, vorbis, mp3, or test OUTPUT_TYPE=$1 ######################################################################## # The transcoding functions # Function for transcoding FLAC to FLAC (useful for increasing compression) flac2flac () { EAC_LOG=`basename "$1" .log` if [ "$1" == "$EAC_LOG" ] then echo "Transcoding "$1" to $OUTPUT_TYPE" CURRENT_WORKING_DIR=`pwd` MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-` TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH" mkdir -p "$TOTAL_PATH" flac -d -c "$1" | flac "$FLAC_OPS" - -o "$TOTAL_PATH/$1" && metaflac --no-utf8-convert --export-vc-to=/tmp/tag.tmp "$1" && metaflac --import-vc-from=/tmp/tag.tmp "$TOTAL_PATH/$1" else cp "$1" "$TOTAL_PATH/.." echo "" >> "$TOTAL_PATH/../$1" echo "**********" >> "$TOTAL_PATH/../$1" echo "$TODAY - Transcoded album to flac $FLAC_OPS" >> "$TOTAL_PATH/../$1" fi return 0 } # Function for transcoding FLAC to Ogg Vorbis using oggenc flac2vorbis () { EAC_LOG=`basename "$1" .log` if [ "$1" == "$EAC_LOG" ] then echo "Transcoding "$1" to $OUTPUT_TYPE" CURRENT_WORKING_DIR=`pwd` MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-` TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH" mkdir -p "$TOTAL_PATH" newname="`basename "$1" .flac`.ogg" # flac -d -c "$1" | oggenc "$VORBIS_OPS" - -o "$TOTAL_PATH/$newname" && metaflac --no-utf8-convert --export-vc-to=/tmp/tag.tmp "$1" && vorbiscomment --raw -w "$TOTAL_PATH/$newname" -c /tmp/tag.tmp && rm /tmp/tag.tmp if `test -f "$TOTAL_PATH/$newname"` ;then return 0; else \ oggenc "$VORBIS_OPS" "$1" -o "$TOTAL_PATH/$newname" ; fi else cp "$1" "$TOTAL_PATH/.." echo "" >> "$TOTAL_PATH/../$1" echo "**********" >> "$TOTAL_PATH/../$1" echo "$TODAY - Transcoded album to Ogg Vorbis $VORBIS_OPS" >> "$TOTAL_PATH/../$1" fi return 0 } # Function for transcoding FLAC to MP3 using the LAME encoder flac2mp3 () { EAC_LOG=`basename "$1" .log` if [ "$1" == "$EAC_LOG" ] then echo "Transcoding "$1" to $OUTPUT_TYPE" CURRENT_WORKING_DIR=`pwd` MAGIC_PATH=`echo "$CURRENT_WORKING_DIR" | cut -b "$PATH_CUT_LENGTH"-` TOTAL_PATH="$TRANSCODED_DIR/$MAGIC_PATH" mkdir -p "$TOTAL_PATH" newname="`basename "$1" .flac`.mp3" TITLE=`metaflac --show-vc-field=TITLE "$1" | cut -b 7-` ARTIST=`metaflac --show-vc-field=ARTIST "$1" | cut -b 8-` ALBUM=`metaflac --show-vc-field=ALBUM "$1" | cut -b 7-` TRACK=`metaflac --show-vc-field=TRACKNUMBER "$1" | cut -b 13-` YEAR=`metaflac --show-vc-field=DATE "$1" | cut -b 6-9` GENRE=`metaflac --show-vc-field=GENRE "$1" | cut -b 7-` COMMENT=`metaflac --show-vc-field=COMMENT "$1" | cut -b 8` flac -d -c "$1" | lame-ha $LAME_OPS --add-id3v2 --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" --tn "$TRACK" --ty "$YEAR" --tg "$GENRE" --tc "$COMMENT" - "$TOTAL_PATH/$newname" else cp "$1" "$TOTAL_PATH/.." echo "" >> "$TOTAL_PATH/../$1" echo "**********" >> "$TOTAL_PATH/../$1" echo "$TODAY - Transcoded album to LAME mp3 $LAME_OPS" >> "$TOTAL_PATH/../$1" fi return 0 } flactest () { EAC_LOG=`basename "$1" .log` if [ "$1" == "$EAC_LOG" ] then echo "Testing $1 and silently writing log" flac -t -s "$1" 2>> "$TRANSCODED_DIR/flactest.log" fi return 0 } ######################################################################## # Function for finding files recursively recursive () { for i in * do if [ -d "$i" ] then cd "$i" recursive cd .. else if [ "flac" == "$OUTPUT_TYPE" ] then flac2flac "$i" elif [ "vorbis" == "$OUTPUT_TYPE" ] then flac2vorbis "$i" elif [ "mp3" == "$OUTPUT_TYPE" ] then flac2mp3 "$i" elif [ "test" == "$OUTPUT_TYPE" ] then flactest "$i" else echo "Output type not recognized - please specify \"flac\", \"vorbis\", \"mp3\", or \"test\"" fi fi done } ######################################################################## # The main body of the script...all it does is call the recursive function recursive ######################################################################## # End of script ########################################################################
|
|