M3u is brilliant in its simplicity

I was all like, “I need to write a perl script to make these M3u playlists”… then reality hit me and was all “Dumbass.  OS X is Unix.  Use IO redirection and pipes”.  This shell command creates a playlist from files in the current directory.

    ls | grep -v *.m3u | cat - > playlist.m3u

It’s not particularly clever, the only filtering prevents a recursive playlist which I’ve found to blow up VLC.  At least on OS X.  I don’t know if there is defined behavior with such an event, but VLC doesn’t like it and I’m doing this to feed playlists to VLC, so I have to make sure I don’t do it.

I’m not sure why the cat – is necessary.  The grep’d ls should keep out the m3u file, but it doesn’t unless I feed it to cat first.  This is probably a flaw in my understanding of how pipes work rather than anything else.  

I should make this into a BASH script and do some more extensive filtering.  I don’t think this needs Perl or another ‘proper’ programming language, though.

M3u being just a text file containing a list of filenames, with relative paths assumed when an absolute is not given, is dead simple and lets you do stuff like this.

Of course, if you want more complicated tricks you’d need something like XML.  But for basic cases, m3u is plenty, and it’s easy to work with.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s