![]() Registered Member ![]()
|
Although amarok does play wma files with a properly compiled xine engine, taglib doesn\'t support reading tag info for them. This makes it impossible to use in your collection. So I wanted to post this script for everybody wanting to convert their wma files. Just get any mplayer packages. Mplayer plays wma files right out of the box, so don\'t worry about compiling it in any special way. This is just a script I threw together in a hour so it probably could use some modifications. This script only copies the Artist and Track Title tags. If there is a way to do a xine dump and get the wma tag information from xine please let me know. I set it up so that options and features can easily be added. Here\'s the script::
#!/bin/sh ## convert function convert () { for i in *.wma; do ##Begin audiodump mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader \'\'\"$i\"\'\' > audiodump.dat; ##Get song information title=$(sort audiodump.dat | grep \" name: \" | sed -e \"s/ name: //g\") name=$(sort audiodump.dat | grep \" author: \" | sed -e \"s/ author: //g\") rm audiodump.dat ##Begin Encoding lame -v -b 320 -q 0 --tt \"$title\" --ta \"$name\" audiodump.wav \'\'\"$i.mp3\"\'\'; rm audiodump.wav; NEWNAME=`echo \"$i.mp3\" | sed -e \"s/.wma//g\"`; mv \"$i.mp3\" \'\'\"$NEWNAME\"\'\'; rm -f \'\'\"$i\"\'\' done; } convert echo \"I have completed converting all $total of your .wma files to .mp3 . Hope you enjoy!!\"; ## |
![]() Registered Member ![]()
|
Updated code. This makes it a lot more user friendly and with more options.
Here it is: #!/bin/sh dialog --title \"WmaToMp3\" --msgbox \"Welcome to Wma to Mp3 Converter!!\" 9 28 dialog --msgbox \"Lets take a minute to setup some options...\" 9 28 dialog --title \"Pick One\" --menu \"Step one: Where would like for me to search for files?\" 10 60 3 1 \"Entire Computer\" 2 \"Current Directory and all subdirectories\" 3 \"Current Directory Only\" 2>_1.txt DIR_OPT=$(cat _1.txt) dialog --title \"Pick One\" --menu \"Step two: What would like for me to convert them to?\" 10 60 2 1 \"Mp3\" 2 \"Leave as wav\" 2>_1.txt CONVERT_OPT=$(cat _1.txt) if [ $CONVERT_OPT = 1 ]; then dialog --title \"Pick One\" --menu \"Step three: What bitrate would you like to use?\" 10 60 4 1 \"64 - Poor\" 2 \"128 - Better\" 3 \"192 - Recommended\" 4 \"320 - Insane\" 2>_1.txt BIT_OPT=$(cat _1.txt) fi dialog --title \"Pick One\" --yesno \"Step four: Would You like for me to remove the wma files after converting?\" 10 40 DEL_OPT=$? dialog --title \"Converting\" --infobox \"Converting... This usually takes a while. Just put on another pot of coffee.\" 10 60 if [ $BIT_OPT = 1 ]; then BIT_OPT=64 elif [ $BIT_OPT = 2 ]; then BIT_OPT=128 elif [ $BIT_OPT = 3 ]; then BIT_OPT=192 elif [ $BIT_OPT = 4 ]; then BIT_OPT=320 fi if [ $DIR_OPT = 1 ]; then find / -name *.wma > wmalist.dat elif [ $DIR_OPT = 2 ]; then find . -name *.wma > wmalist.dat elif [ $DIR_OPT = 3 ]; then ls *.wma > wmalist.dat fi ##Replace all spaces with underscore in file names cat wmalist.dat | sed -e \"s/ /##/g\" > wmalist rm -rf wmalist.dat for i in $(cat wmalist) do total=$((total+1)) ##Change all underscores back to spaces i=$(echo $i | sed -e \"s/##/ /g\") ##Begin audiodump mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader \'\'\"$i\"\'\' > audiodump.dat; if [ $CONVERT_OPT = 2 ]; then NEWNAME=`echo \"$i.wav\" | sed -e \"s/.wma//g\"` mv \"$i.wav\" \'\'\"$NEWNAME\"\'\' elif [ $CONVERT_OPT = 1 ]; then ##Get song information title=$(sort audiodump.dat | grep \" name: \" | sed -e \"s/ name: //g\") name=$(sort audiodump.dat | grep \" author: \" | sed -e \"s/ author: //g\") rm audiodump.dat ##Begin Encoding lame -v -b $BIT_OPT -q 0 --tt \"$title\" --ta \"$name\" audiodump.wav \'\'\"$i.mp3\"\'\'; rm audiodump.wav; NEWNAME=`echo \"$i.mp3\" | sed -e \"s/.wma//g\"`; mv \"$i.mp3\" \'\'\"$NEWNAME\"\'\'; fi ##Remove file if opted if [ $DEL_OPT = 0 ]; then rm -f \'\'\"$i\"\'\' fi done dialog --title \"All Done!!\" --msgbox \"I have finished converting all $total of your wma files. Enjoy!!\" 10 60 ##Clean up rm _1.txt rm wmalist exit 0 Post edited by: sleepkreep, at: 2005/02/15 09:18 Post edited by: sleepkreep, at: 2005/02/24 11:09 Post edited by: sleepkreep, at: 2005/02/25 04:17 |
![]() ![]()
|
I do not hava wma\'s I always have ignored them so no wma problem here. But I have a lot of mp3 files. Is it possible to make a script to convert a lot of directories with mp3 files to ogg ? It would increase the space on my hd without losing to much quality.
And if it would copy the tags it would be even better ![]() |
![]() Registered Member ![]()
|
Yes you should be able to use this to encode from mp3 to ogg. Be warned, I have not tested this so I don\'t know if this will work. I just made some quick adjustments. To be on the safe side re-encode a specific directory and opt not to delete the original files. Test them and make sure it works, tags and all. If not, post your problems here.
#!/bin/sh dialog --title \"WmaToMp3\" --msgbox \"Welcome to Mp3 to Ogg Converter!!\" 9 28 dialog --msgbox \"Lets take a minute to setup some options...\" 9 28 dialog --title \"Pick One\" --menu \"Step one: Where would like for me to search for files?\" 10 60 3 1 \"Entire Computer\" 2 \"Current Directory and all subdirectories\" 3 \"Current Directory Only\" 2>_1.txt DIR_OPT=$(cat _1.txt) dialog --title \"Pick One\" --menu \"Step two: What would like for me to convert them to?\" 10 60 2 1 \"Ogg\" 2 \"Leave as wav\" 2>_1.txt CONVERT_OPT=$(cat _1.txt) if [ $CONVERT_OPT = 1 ]; then dialog --title \"Pick One\" --menu \"Step three: What bitrate would you like to use?\" 10 60 4 1 \"64 - Poor\" 2 \"128 - Better\" 3 \"192 - Recommended\" 4 \"320 - Insane\" 2>_1.txt BIT_OPT=$(cat _1.txt) fi dialog --title \"Pick One\" --yesno \"Step four: Would You like for me to remove the wma files after converting?\" 10 40 DEL_OPT=$? dialog --title \"Converting\" --infobox \"Converting... This usually takes a while. Just put on another pot of coffee.\" 10 60 if [ $BIT_OPT = 1 ]; then BIT_OPT=64 elif [ $BIT_OPT = 2 ]; then BIT_OPT=128 elif [ $BIT_OPT = 3 ]; then BIT_OPT=192 elif [ $BIT_OPT = 4 ]; then BIT_OPT=320 fi if [ $DIR_OPT = 1 ]; then find / -name *.mp3 > wmalist.dat elif [ $DIR_OPT = 2 ]; then find . -name *.mp3 > wmalist.dat elif [ $DIR_OPT = 3 ]; then ls *.mp3 > wmalist.dat fi cat wmalist.dat | sed -e \"s/ /##/g\" > wmalist rm -rf wmalist.dat for i in $(cat wmalist) do total=$((total+1)) i=$(echo $i | sed -e \"s/##/ /g\") ##Begin audiodump mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader \'\'\"$i\"\'\' > audiodump.dat; if [ $CONVERT_OPT = 2 ]; then NEWNAME=`echo \"$i.wav\" | sed -e \"s/.mp3//g\"` mv \"$i.wav\" \'\'\"$NEWNAME\"\'\' elif [ $CONVERT_OPT = 1 ]; then ##Get song information title=$(sort audiodump.dat | grep \" Title: \" | sed -e \"s/ Title: //g\") name=$(sort audiodump.dat | grep \" Artist: \" | sed -e \"s/ Artist: //g\") album=$(sort audiodump.dat | grep \" Album: \" | sed -e \"s/ Album: //g\") year=$(sort audiodump.dat | grep \" Year: \" | sed -e \"s/ Year: //g\") genre=$(sort audiodump.dat | grep \" Genre: \" | sed -e \"s/ Genre: //g\") track=$(sort audiodump.dat | grep \" Track: \" | sed -e \"s/ Track: //g\") rm audiodump.dat ##Begin Encoding lame -v -b --ogg $BIT_OPT -q 0 --tt \"$title\" --ta \"$name\" --tl \"$album\" --ty \"$year\" --tn \"$track\" --tg \"$genre\" audiodump.wav \'\'\"$i.ogg\"\'\'; rm audiodump.wav; NEWNAME=`echo \"$i.ogg\" | sed -e \"s/.mp3//g\"`; mv \"$i.ogg\" \'\'\"$NEWNAME\"\'\'; fi ##Remove file if opted if [ $DEL_OPT = 0 ]; then rm -f \'\'\"$i\"\'\' fi done dialog --title \"All Done!!\" --msgbox \"I have finished converting all $total of your wma files. Enjoy!!\" 10 60 ##Clean up rm _1.txt rm wmalist exit 0 Post edited by: sleepkreep, at: 2005/02/25 00:39 |
![]() Registered Member ![]()
|
Marco wrote:
There is already something which will do this (including the tags). It is a Perl script called, mp32ogg. It is available Freshmeat.net. Just click the following link: http://freshmeat.net/projects/mp32ogg Rick |
![]() Registered Member ![]()
|
Marco wrote:
This is actualy wrong (depending on where you draw the line regarding "to much"). Copying from one lossy format to annother is _not_ good. And even if you have a lot of mp3\'s with near transparent quality, and transcode them to ogg\'s with a bittrate that should give near transparent quality, the resulting quality is _not_ near transparent. If you imagine that we register sound quality from 0.0 to 1, where 1 is 100% quality. Then transcoding from one file with 0.9 to another that should give 0.9 quality, would result in a file that has a soundquality poorer than (0.9*0.9). You should go for FLAC, then atleast one of the formats would be a 1 ![]() |
![]() ![]()
|
Thank you all ! I will try it.
I know its bat for the quality but I do not care to much I will keep the originals on a dvd but my ears are not that good that I can hear the differents. If my ears were that good I never had used mp3 ![]() |
![]() ![]()
|
Well, nice script there. Too bad it doesn\'t work for me; it just chews through the files REALLY fast and removes all the .wma-files if you choose that option. Good thing I had back-ups.
![]() |
![]() ![]()
|
\"./sh-converter.sh: line 19: [: =: unary operator expected
./sh-converter.sh: line 21: [: =: unary operator expected ./sh-converter.sh: line 23: [: =: unary operator expected ./sh-converter.sh: line 25: [: =: unary operator expected SSE2 supported but disabled mv: cannot stat `Kent - Dom andra.wma.wav\': No such file o\" This is an example of what the script spits out. |
![]() Registered Member ![]()
|
What the Hell? I\'ll look into it later. Obviously it shouldn\'t be doing that. And yeah, I guess it is a good thing you had backups. Off hand, my guess is that during your copy and paste you missed a quotation. If I can\'t find anything wrong with it I\'ll just attach the file to my next post. Give it a try again. I think I\'ll be rewriting it anyways to use the kdialog command for a more sophisticated look and feel.
|
![]() ![]()
|
|
![]() Registered Member ![]()
|
I found a space where I don\'t think there should be. What shell are you using?
If /bin/sh does not point to bash then please direct the script to bash. I\'m attaching a file to ensure this is not a copy and paste error thing. If I decide to rewrite it, I\'ll post it up here first. Oh yeah, I can only post zip or txt files on the amarok forum, so I\'m posting the script as a txt file. Just knock off the .txt extension and make sure it is executable before trying to run. Good Luck. [file name=wmatomp3.txt size=2365]http://amarok.kde.org/components/com_simpleboard/uploaded/files/wmatomp3.txt[/file] Post edited by: sleepkreep, at: 2005/03/28 22:27 |
![]() ![]()
|
OK, thanks. Anyway,I\'m using bash, so there shouldn\'t be any problems because of that. And the first version of the script works just perfect.
|
![]() Registered Member ![]()
|
Well, as long as the subject of conversion is here, I\'ll post a Python script I wrote that converts all my files from .flac to .mp3. Since this would take about a week to run on my files, I actually first create a text file that contains all the commands that actually do the work, then I work my way down that file. That way, when I needed to stop the program, I could easily pick up where I left off.
Oh, I\'m not a programmer--I\'m learning Python and this is only my second program, so don\'t make fun of the code! ![]() [code] import sys import os #Set the following directory to the top level of your music FileGen = os.walk(\"/home/mlmitton/Data/Music/Flac2\") ListOfFiles=[\'x\'] FoundList = 0 #The directories below should be where you want the command list to reside try: TranscodeList = file(\"/home/mlmitton/Data/Music/TranscodeList\",\"r\") FoundList = 1 except: FoundList = 0 TranscodeList = file(\"/home/mlmitton/Data/Music/TranscodeList\",\"a\") # CreateList() creates a text file of all the commands used in converting # all the files from flac to mp3. We keep this record so that the program # can be killed, then restarted without screwing around to keep from # reconverting all the files. def CreateList(): while 1: WalkTuple = FileGen.next() for i in range(len(WalkTuple[2])): try: FlacFile = os.path.join(WalkTuple[0],WalkTuple[2][i]) if FlacFile.count(\".flac\"): ToConvert = FlacFile else: ToConvert = \"None\" except IndexError: pass tc2 = \"\\\"\" + str(ToConvert) + \"\\\"\" try: if tc2.count(\".flac\"): TitleCommand = \"metaflac --show-vc-field=TITLE \" + tc2 + \" | cut -b 7-\" TitleforPath = os.popen(TitleCommand).read()[:-1] Title = \"\\\"\" + TitleforPath + \"\\\"\" ArtistCommand = \"metaflac --show-vc-field=ARTIST \" + tc2 + \" | cut -b 8-\" ArtistforPath = os.popen(ArtistCommand).read()[:-1] Artist = \"\\\"\" + ArtistforPath + \"\\\"\" AlbumCommand = \"metaflac --show-vc-field=ALBUM \" + tc2 + \" | cut -b 7-\" AlbumforPath = os.popen(AlbumCommand).read()[:-1] Album = \"\\\"\" + AlbumforPath + \"\\\"\" TrackCommand = \"metaflac --show-vc-field=TRACKNUMBER \" + tc2 + \" | cut -b 13-\" Track = \"\\\"\" + os.popen(TrackCommand).read()[:-1] + \"\\\"\" YearCommand = \"metaflac --show-vc-field=DATE \" + tc2 + \" | cut -b 6-9\" Year = \"\\\"\" + os.popen(YearCommand).read()[:-1] + \"\\\"\" GenreCommand = \"metaflac --show-vc-field=GENRE \" + tc2 + \" | cut -b 7-\" Genre = \"\\\"\" + os.popen(GenreCommand).read()[:-1] + \"\\\"\" CommentCommand = \"metaflac --show-vc-field=COMMENT \" + tc2 + \" | cut -b 8-\" Comment = \"\\\"\" + os.popen(CommentCommand).read()[:-1] + \"\\\"\" NewDir = \"\\\"/home/mlmitton/Data/Music/MP3transcode/\" + ArtistforPath + \"/\" + AlbumforPath CreateDirCommand = \"mkdir -p \" + NewDir + \"\\\"\\n\" print CreateDirCommand TranscodeList.writelines(CreateDirCommand) StringTrack = Track NumTrack = int(Track[1:-1]) if NumTrack < 10: StringTrack = \"0\" + StringTrack NewPath = NewDir + \"/\" + StringTrack+ \"_\" + TitleforPath + \".mp3\\\"\" WavPath = tc2.replace(\".flac\", \".wav\") DecodeCommand = \"flac -d \" + tc2 + \" \" + WavPath + \"\\n\" TranscodeList.writelines(DecodeCommand) EncodeCommand = \"lame --preset standard --add-id3v2 --tt \" + Title + \" --ta \" + Artist + \" --tl \" + Album + \" --tn \" + Track + \" --ty \" + Year + \" --tg \" + Genre + \" --tc \" + Comment + \" \" + WavPath + \" \" + NewPath + \"\\n\" TranscodeList.writelines(EncodeCommand) RemoveCommand = \"rm \" + WavPath + \"\\n\" TranscodeList.writelines(RemoveCommand) except IndexError: pass if FoundList == 1: pass else: CreateList() TranscodeList = file(\"/home/mlmitton/Data/Music/TranscodeList\",\"r\") # Set X to be the command number where you want the process to start. # For example, if you quit the program at command #1000, set x to 1000 # (minus 4, if you want to be sure you don\'t miss something). x=0 i=0 while i |
Registered users: Bing [Bot], Google [Bot], rockscient