Here’s what I needed:
I have a huge amount of music and for some reason, I just like it to play shuffled. When I hit play on the Sonos, I just want it to randemly go through and play the music on the NAS. This actually works beautifully on the Sonos. It doesn’t really need this. But I@m working on something interesting using HomeAssistant at the moment and it doesn’t support the simple requirement of playing all music in a folder. IT requires a playlist.
I already have a Linux server so each day at 3am, when everyone is in bed, a script will run to recreate and re-shuffle the playlist. So when new music is added, it will get added to the playlist and the order is always different.
first of all, put this in /etc/cron.daily but obviously, replace the parts in [] brackets to match your own values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
mountpoint -q /media/nas_music || mount -t cifs //[YourNasIPGoesHere/Music /media/nas_music -o username=[YourUserNameGoesHere,password=[YourPasswordGoesHere if mount | grep -q '/media/nas_music'; then find /media/nas_music/* | grep -i .mp3 > /media/nas_music/autotrad.m3u find /media/nas_music/* | grep -i .m4a >> /media/nas_music/autotrad.m3u find /media/nas_music/* | grep -i .wav >> /media/nas_music/autotrad.m3u awk '!/Duinnín/' /media/nas_music/autotrad.m3u > /tmp/temp.m3u && mv /tmp/temp.m3u /media/nas_music/autotrad.m3u awk '!/Álainn/' /media/nas_music/autotrad.m3u > /tmp/temp.m3u && mv /tmp/temp.m3u /media/nas_music/autotrad.m3u awk '!/christmas/' /media/nas_music/autotrad.m3u > /tmp/temp.m3u && mv /tmp/temp.m3u /media/nas_music/autotrad.m3u shuf /media/nas_music/autotrad.m3u -o /media/nas_music/autotrad.m3u mountpoint -q /media/nas_music || umount /media/nas_music else mail [YourEmailAddress] -s "[playlist script] Playlist creation failed! Could not mount NAS drive." fi |
Okay. you have that file created?
Now set permissions on it using chmod 755.
Finally, add something to your crontab for each day at 3am. First, open crontab by typing crontab -e then press enter.
1 |
0 3 * * * /etc/cron.daily/create_playlist.sh 2>&1 > /dev/null |
That’s all there is too it.
0 Comments