Mopidy Discourse

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/

# select 100 tracks at random and create a playlist

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!


1 Like

Hey thanks for your little script. Using it on my mopidy setup. Small modification I had to do was to use /bin/chown instead of /usr/bin/chown (debian/raspbian on rasperrypi).

huh. ok. That script was hacked together on a server running debian 10.7. It is standard there to link /bin → /usr/bin:

lrwxrwxrwx 1 root root 7 Jun 21  2020 /bin -> usr/bin