#!/usr/bin/env sh
# select X tracks for a given genre and create a playlist

num=50
playlist="/var/lib/mopidy/media/music/playlists/$1 Today.m3u8"
echo "#EXTM3U" > ${playlist}
for uri in $(sqlite3 /var/lib/mopidy/local/library.db "SELECT uri FROM track WHERE Genre like '%$1%' ORDER BY RANDOM() LIMIT $num;"); do
    name=$(sqlite3 /var/lib/mopidy/local/library.db "SELECT name FROM track WHERE uri = '$uri';")
    echo "#EXTINF:-1,$name"
    echo "$uri"
done >> ${playlist}
