Python script to randomise an m3u playlist

While I’m blogging scripts for playlist manipulation here is one I use in a nightly cron job to shuffle our playlists so that various devices playing from them have some daily variety. All disclaimers apply, it’s rough and ready but WorksForMe (TM).

I have an entry in my crontab like this

which takes a static playlist and produces a nightly shuffled version.

  • 3

7 thoughts on “Python script to randomise an m3u playlist”

  1. This script looks like it does exactly what I’d like. I’m getting some errors when trying to run it, though.

    osmc@osmc:~$ ~/ -q -i /home/osmc/.kodi/userdata/playlists/video/test.m3u -o /home/osmc/.kodi/userdata/playlists/video/test_Shuffle.m3u
    File “/home/osmc/”, line 17
    ‘process the list of all playlist lines into three chunks’
    IndentationError: expected an indented block

    I don’t know how to write scripts, so if you could give me a hand that’d be great!


    1. Justin,

      I tried to reply a moment ago and it seemed to get lost, so apologies if you get two replies!

      The fault is entirely mine, the way I had pasted the code into the blog and the syntax highlighter I was using didn’t show the indentation in the code, which is critical in Python. In fact I just noticed this last Friday when showing some students.

      I have swapped over to a different highlighter and you should see the indentation, it even provides a button (hover over the area) to copy all the code to your clipboard.

      Let me know if you get success now or have any other problems.

      Thanks for the comment and the heads up.


Leave a Reply

Your email address will not be published. Required fields are marked *