cat /home/kiorky/bin/wma2ogg.sh
#!/bin/sh
#tagreader and tagwriter are part of taglib examples
CWD=$(pwd)
i=$CWD
WMA=""
QUALITY="192"
encode(){
echo "encoding $WMA"
if [[ $(file "$WMA" |sed -re "s/.*ASF.*/sale/g") == "sale" ]]; then
echo "$WMA is a very dirty file that is in need to be reencoded, please stand by for"
OGG=`basename "$WMA" .wma`.ogg;TMP=`basename "$WMA" .wma`.wav;
ffmpeg -i "$WMA" -f ogg -aq $QUALITY "$OGG"
else
echo "$i appears to be clean and not WMA file"
fi
#remerging meta data
data=$(tagreader "$WMA")
TAGS="genre title artist album year comment track";
for val in $(echo "$TAGS");do
TOTAG="";TOWRITE=$(echo "$data"|grep $val|sed s/\"//g|sed "s/$val\s*-\s//")
if [[ $TOWRITE != "" ]] ; then
TOTAG=" --$val"
fi
echo $TOTAG "$TOWRITE"
if [[ $TOTAG != "" ]] ; then
audiotag $TOTAG "$TOWRITE" "$OGG"
fi
done
}
# scanning recursively for wma files
do_job(){
echo "entering directory '"$CWD"' and doing stuff"
#fucking trailing space replaced
for i in $(ls -1 .|sed -re "s/\s/\\\/g");do
echo "---- $i ---- "
#reputting traling spaces in filenames
i=$(echo $i|sed -re "s/\\\/ /g")
if [[ -d "$i" ]]; then
# echo "process "$i" directory"
CWD="$i";cd "$CWD";do_job;cd ..;
elif [[ $(echo "$i"|sed -re "s/.*wma/toprocess/") == "toprocess" ]]; then
WMA="$i"
encode
else
echo "the file '$i' is either an empty directory or not a wma file"
fi
done;
}
do_job