What I want, therefore is to be able to reduce the bitrate of nasty large bitrate songs so I can fit them all in...I like good quality music but I would prefer to have all my music rather than select some (the whole point of me buying an iPod in the first place).
So, like any good programmer I briefly tried the existing software but got bored far too quickly (tried Exaile, Amarok and Banshee all of which were rubbish and overcomplicated). I did previously try iTunes but that was taking days and I had to keep booting up into Windows which was a pain each time (spending more time updating than actually using!)
Anyway, I wrote this little snippet below that might be useful to someone somewhere in the world. It has a couple of dependencies:
- gnupod (downloaded from sources here: http://www.gnu.org/software/gnupod/)
- lame (installed from synaptic iirc)
- exiftool (also synaptic iirc)
Warning: this will erase everything on your ipod everytime you run it - I hope you're tech savvy enough to be able to comment out the offending lines. You'll have to update the IPOD_MOUNTPOINT variable yourself
This will loop through your currently working directory (to infinite depth) hunting out all the mp3s. It will then go through every single mp3 and copy them onto the ipod. If it hits an mp3 that is > 256 kbits it will convert it down to 128kbits. Simples.
In the future I would quite like to make this a bit faster, it currently takes a while sequentially converting and transferring every single song. It would be better to parallelise the conversion across all my cores (I couldn't find a copy of fpMP3Enc easily which is apparently multicore lame). Anyway, what might be nice would be to have the conversions done in a different thread whilst the master thread works through copying all the songs that don't converting. Perhaps make a queue of songs to convert and then do those in the background whilst the main copying takes place? Also, I have the problem that when I want to add songs to my library I will have to do it either by hand or with another script....obviously I won't want to be deleting my entire library each time!
EDIT: This can be parallelised using gnu parallel pretty easily however you get problems if you run more than one gnupod_addsong at once. So you'd probably require something a bit more involved, probably using python to get it working well :p Unless you can do locks in shell? I might investigate some of the stuff here when I get the chance.
#!/bin/bash export IPOD_MOUNTPOINT="/media/IPOD/" IFS=" " count=$(find . -type f -name '*.mp3' | wc -l) counter=0 for file in $(find . -type f -name '*.mp3'); do echo "Doing $counter of $count" filename=`echo $file | cut -c3-` res=`exiftool $filename | grep "Audio Bitrate" | awk '{ sub("Audio Bitrate : ",""); print}' | awk '{ sub(" .*",""); print}'` if [ "$res" -gt "256" ]; then rm /tmp/*.mp3 # convert this song echo "Converting $filename" lame --preset 128 "$filename" "/tmp/${filename##*/}" filename="/tmp/${filename##*/}" fi echo "adding $filename" gnupod_addsong $filename let counter=counter+1 done mktunes
No comments:
Post a Comment
Leave a comment!