Create a random playlist

Hi… after messing around with mopidy for a while I wanted to implement the “50 random tracks” idea from Clementine which I really liked. So I wrote a little cron job. It is hacky and clunky and would be better in something like python but for a quick sketch someone might find it useful. I should point out that I am using mopidy-local.

put into /etc/cron.daily/

#!/bin/sh
# select 100 tracks at random and create a playlist

num=100
playlist="/var/lib/mopidy/m3u/random${num}.m3u8"
echo "#EXTM3U" > ${playlist}
for uri in $(/usr/bin/sqlite3 /var/lib/mopidy/local/library.db "SELECT uri FROM track ORDER BY RANDOM() LIMIT $num;"); do
	name=$(/usr/bin/sqlite3 /var/lib/mopidy/local/library.db "SELECT name FROM track WHERE uri = \"$uri\";")
	echo "#EXTINF:-1,$name"
	echo "$uri"
done >> ${playlist}
/usr/bin/chown mopidy:audio ${playlist}

If anyone wants to suggest improvements, let me know!

G