a0224ef3c03567a0dc8b25b559ace381a90f7c7c
[feisty_meow.git] / examples / multimedia / wma2mp3.sh
1 #!/bin/bash
2
3 # wma to mp3 script by mtron
4 # from http://ubuntuforums.org/showthread.php?t=37793
5
6 # have found that soundconverter package on ubuntu works on more types
7 # and is a bit more polished, but mtron's script kicks ass anyhow, if all
8 # you need is wma -> mp3 conversions.
9 # --fred hamster
10
11 zenity --info \
12         --text="this script converts all wma files in the current folder
13 to mp3s and puts them in the folder output 
14
15 all lame command line options can be set in the next step. 
16
17 usage:
18         lame -m s: for stereo mp3 output
19         lame -m s V 3-4-5: for stereo mp3 output with VBR"
20
21 # Dialog box to choose output quality
22 FORMAT=$(zenity --list --title="Choose mp3 output quality" --radiolist --column="Check" --column="Quality (editable)" --editable "" "lame -m s" "" "lame -m s -V 3" "" "lame -m s -V 4" "" "lame -m s -V 5")
23
24 if [ $FORMAT -eq ""]; then    
25 zenity --error --text="mp3 output quality not defined or no wma file found
26
27 usage:
28         lame -m s: for stereo mp3 output
29         lame -m s V 3-4-5: for stereo mp3 output with VBR 
30  
31 type: lame --longhelp 
32 for all command line options "
33 exit 1
34 fi
35
36 mkdir -p output
37 cp *.wma output
38 cd output
39
40 # How many files to make the progress bar
41 PROGRESS=0
42 NUMBER_OF_FILES=$(find -iname "*.wma")
43 let "INCREMENT=100/$NUMBER_OF_FILES"
44
45 #remove spaces
46 (for i in *.wma; do mv "$i" $(echo $i | tr ' ' '_'); done
47
48 #remove uppercase
49 for i in *.[Ww][Mm][Aa]; do mv "$i" $(echo $i | tr '[A-Z]' '[a-z]'); done
50
51 #Rip with Mplayer / encode with LAME
52 for i in *.wma ; do 
53 echo "$PROGRESS";
54 echo "# Re-Coding $i";
55 mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $i && $FORMAT audiodump.wav -o $i;
56 let "PROGRESS+=$INCREMENT"
57 done
58
59 #convert file names
60 for i in *.wma; do mv "$i" "$(basename "$i" .wma).mp3"; 
61 done
62
63 rm audiodump.wav
64 let "PROGRESS+=$INCREMENT"
65 ) | zenity  --progress --title "$Recoding...encoding..." --percentage=0
66
67