cybrkyd

Make a quick-and-dirty m3u playlist in Linux

 Sun, 19 May 2024 10:47 UTC
Make a quick-and-dirty m3u playlist in Linux
Vinyl disc: Meul | This image: CC BY-SA 3.0 by cybrkyd

To make a quick-and-dirty m3u playlist in Linux, one can simply list the files in an album directory and write them to file:

ls > playlist.m3u

That’s all there is to it; you now have a playlist which lists all the files in that directory.

playlist.m3u
Weather Report - A Remark You Made.flac
Weather Report - Birdland.flac
Weather Report - Harlequin.flac
Weather Report - Havona.flac
Weather Report - Heavy Weather.jpg
Weather Report - Palladium.flac
Weather Report - Rumba Mama.flac
Weather Report - Teen Town.flac
Weather Report - The Juggler.flac

Normally, your audio player will ignore the non-audio files in a playlist, e.g. the album art. As per the above example, we also see the files playlist.m3u and Weather Report - Heavy Weather.jpg listed from the directory.

NOTE: Make sure to remove playlist.m3u from the playlist file otherwise you will start an endless loop!

A much safer way to write a simple playlist is as follows, where the audio file-type is specified:

find . -type f -iname "*.flac" > playlist.m3u

find lists items in the order that they are reported by the underlying file system. Notice how the files are in a different order to the alphabetical list, previously:

./Weather Report - Teen Town.flac
./Weather Report - Rumba Mama.flac
./Weather Report - A Remark You Made.flac
./Weather Report - Birdland.flac
./Weather Report - Havona.flac
./Weather Report - Palladium.flac
./Weather Report - Harlequin.flac
./Weather Report - The Juggler.flac

Shuffle playlist

To make a shuffle playlist, do this:

find . -type f -iname "*.flac" | shuf > playlist.m3u

Your playlist is now shuffled and contains only the .flac files from the directory.

./Weather Report - The Juggler.flac
./Weather Report - Rumba Mama.flac
./Weather Report - Birdland.flac
./Weather Report - Havona.flac
./Weather Report - Palladium.flac
./Weather Report - A Remark You Made.flac
./Weather Report - Teen Town.flac
./Weather Report - Harlequin.flac

To shuffle through your entire music collection which contains .mp3s, .flac and .m4a files, and return only 200 songs, this will work:

find -type f -iname "*.mp3" -or -iname "*.flac" -or -iname "*.m4a" | shuf | head -n 200 > playlist.m3u

Have fun, press play.

»
Tagged in:

Visitors: Loading...