Skip to content

Instantly share code, notes, and snippets.

@pfactum
Created March 29, 2012 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfactum/2236617 to your computer and use it in GitHub Desktop.
Save pfactum/2236617 to your computer and use it in GitHub Desktop.
flac2
#!/bin/bash
#By DsTr wink.gif
#`kdialog --passivepopup "Добавление в коллекцию..." 1`
if [ "$1" == '' ]; then
shellDir="$PWD"
else
shellDir="$1"
fi
cd "$shellDir"
find |while read dir; do
if [ -f "$dir" ]; then
dirName="`dirname "$dir"`"
cd "`dirname "$dir"`"
tsFile=`echo "$dir" | sed -ne 's!^.*\/!!p'`
ext=`echo "$dir" | sed -ne 's!^.*\.!!p' | tr '[:upper:]' '[:lower:]'` &> /dev/null
base=`echo "$tsFile" | sed -e 's!\.[^.]*$!!'` &> /dev/null
if [ "$ext" = "ape" ]; then
#`kdialog --passivepopup "$dir converting to $base.flac..." 2`
mac "$tsFile" "$base.wav" -d
flac "$base.wav"
rm -f "$tsFile" "$base.wav"
fi
if [ "$ext" = "bin" ]; then
#`kdialog --passivepopup "Converting $dir to $base.flac... " 2`
`flac --force-raw-format --channels=2 --sample-rate=44100 --bps=16 --sign=signed --endian=little "$tsFile"`
fi
if [ "$ext" = "wav" ]; then
#`kdialog --passivepopup "Converting $dir to $base.flac... " 2`
`flac --force-raw-format --channels=2 --sample-rate=44100 --bps=16 --sign=signed --endian=little "$tsFile"`
fi
cd "$shellDir"
fi
done
find |while read dir; do
if [ -f "$dir" ]; then
cd "`dirname "$dir"`"
tsFile=`echo "$dir" | sed -ne 's!^.*\/!!p'`
ext=`echo "$dir" | sed -ne 's!^.*\.!!p' | tr '[:upper:]' '[:lower:]'` &> /dev/null
base=`echo "$dir" | sed -e 's!\.[^.]*$!!'` &> /dev/null
if [ "$ext" = "cue" ]; then
#`kdialog --passivepopup "Recoding $dir tags to unicode... " 2`
pathtoflac=`ls | grep .flac`
mv "$pathtoflac" "tmp.flac"
mv "$tsFile" "tmp.cue"
shnsplit -o wav "tmp.flac" -f "tmp.cue" -t '%n-%t'
numTracks=`cueprint "tmp.cue" --disc-template %N`
while (( numTracks > 0 ))
do
perfomer=`cueprint "tmp.cue" -n "$numTracks" --track-template %p`
title=`cueprint "tmp.cue" -n "$numTracks" --track-template %t`
album=`cueprint "tmp.cue" --disc-template %T`
if (( ${#numTracks} == 2 )); then
flac --replay-gain --force-raw-format --channels=2 --sample-rate=44100 --bps=16 --sign=signed --endian=little --best "$numTracks-$title.wav"
splitname="$numTracks-$title.flac"
rm -f "$numTracks-$title.wav"
else
flac --replay-gain --force-raw-format --channels=2 --sample-rate=44100 --bps=16 --sign=signed --endian=little --best "0$numTracks-$title.wav"
splitname="0$numTracks-$title.flac"
rm -f "0$numTracks-$title.wav"
fi
cueprint -n $numTracks -t 'ARRANGER=%A\nCOMPOSER=%C\nGENRE=%G\nMESSAGE=%M\nTRACKNUMBER=%n\nARTIST=%p\nTITLE=%t\nALBUM=%T\n' "tmp.cue" | egrep -v '=$' | metaflac "$splitname" --import-tags-from=-
let "numTracks-=1"
done
rm -f "tmp.cue" "tmp.flac"
fi
cd "$shellDir"
fi
done
#`kdialog --passivepopup "Завершено..." 1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment