Much ado about scripting, Linux & Eclipse: card subject to change

2009-07-21

HOWTO: generate .m3u playlist from .mp3 directory

Been trying to find a solution to this one for ages. Turns out it's stupidly simple - just dump the results of a find into a file.

#!/bin/bash
dir="$1"
echo "Create playlist for $1 ..."
if [[ $2 ]]; then list="$2"; else list="$1"; fi

pushd "$dir" 2>&1 >/dev/null
find . -type f -name "*.mp3" > "$list.m3u"
echo "Found these files:"
cat "$list.m3u"
popd 2>&1 >/dev/null

With or without the "./" prefix on each found file, the resulting .m3u files work on my Blackberry (and are found automatically), including nested folders and paths with spaces. To run the above, just do this:

$ ./m3u.sh "artist folder/disc folder" "playlist name"

1 comments:

Anonymous said...

Cool. I found it works without pushd/popd, too, which allows the creation of M3Us in separate directories from the music files. (You need to CD to the M3U directory, though.) Another mod I made is making it find flac files as well—works for my M3U app!

Thanks!