How can I generate an M3U playlist (http URL format) from the terminal?

I think the following one-liner should work:

for f in *.mp3; do echo "http://..../$f" >> play.m3u; done


This is @chronitis answer with some improvements :

  • stores the file name on the variable $playlist for later use
  • will delete the file if exists previously
  • writes the full path of the file on the playlist

The command

playlist='play.m3u' ; if [ -f $playlist ]; then rm $playlist ; fi ; for f in *.mp3; do echo "$(pwd)/$f" >> "$playlist"; done

To play it with mplayer on the command line also

mplayer -playlist play.m3u

You originally asked to create each entry as a web URL formatted line. In addition to replacing the local path with http://..., you'll also need to replace spaces with '%20'. So, long line, but here you go:

find /path/to/mp3s/ -name "*.mp3" | sed 's/ /%20/g' | sed 's|/path/to/mp3s/|http://www.server.com/serverpath/|g' > playlist.m3u