jaedb / Iris

Discover, explore and manage your music library across multiple sources with this beautiful web-based interface. Iris is a Mopidy frontend extension.
Apache License 2.0
1.14k stars 133 forks source link

Quicker "add random" #598

Open arthurlutz opened 4 years ago

arthurlutz commented 4 years ago

Follow up of the great #546 feature recently implemented, thanks a lot! I'm really enjoying listening to my collection using this features!

Is your feature request related to a problem? Please describe.

To play some random tracks, a number of "clicks" need to be done, it would be nice to reduce them.

Right now :

Describe the solution you'd like

Would be nice :

replaces the playlist and starts playing the first track.

If you think some users want to add to existing playlist or not start automatically maybe there could be options for that. "Add random, replace and play" ?

gwm commented 3 years ago

This kinda works already - just click "Add", then "Find Random Tracks" you can add them at the end of current playlist or right after the current track.

Personally, I generate a random playlist with a cron job every night of 100 tracks. This pretty much does it for me. I've also thought of creating shorter random playlists and possibly one or two "random album" playlists. Should be straightforward to do.

arthurlutz commented 3 years ago

@gwm your solution seems nice but will be mostly inacessible to most non-geek users. It could serve as inspiration for features in tools such as iris though, thanks for the feedback.

gwm commented 3 years ago

@arthurlutz well yes, but then anyone rolling their own system with mopidy/iris etc. is likely to have some geek creds! And as I had an enquiry off-list, here is the nasty cron job that compiles my random list:

g@borg:~$ cat /etc/cron.daily/createplaylist 
#!/bin/sh
#select 100 tracks at random and create a playlist

OIFS=$IFS

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}

IFS=$OIFS

I should perhaps point out that I am not 100% certain how random the sqlite ORDER BY RANDOM() actually is... and I'm aware this could be greatly improved but was the result of a few minutes hacking and reading man pages!

fmarzocca commented 3 years ago

@gwm Thank you!

fmarzocca commented 3 years ago

@gwm, I first need to manually create an empty "random100" playlist, otherwise the playlist created by the script is not shown in the frontend.

kingosticks commented 3 years ago

Doesn't Iris provide a facility to refresh the m3u playlists it displays?

gwm commented 3 years ago

@fmarzocca I don't have an issue seeing updated playlists perhaps just the initial creation?

fmarzocca commented 3 years ago

@gwm if the playlist is not manually created before launching the script, it will be created in the playlists folder, but not shown in the frontend. If the playlist already exists in Iris fontend, the script will correctly update it (but you need to refresh the playlist)

gwm commented 3 years ago

@fmarzocca interesting! as I only run this daily it gets run in the early hours of the morning so I guess by the time I look at it in Iris, the view gets refreshed.

gwm commented 3 years ago

I whipped up another script for "random album" that I drop into /etc/cron.hourly/

g@borg:~$ cat /etc/cron.hourly/random_album
#!/bin/bash
db="/var/lib/mopidy/local/library.db"
playlist="/var/lib/mopidy/m3u/random_album.m3u8"

album=$(/usr/bin/sqlite3 $db "SELECT uri FROM albums ORDER BY RANDOM() LIMIT 1")
echo "#EXTM3U" > ${playlist}

for track in $(/usr/bin/sqlite3 $db "SELECT uri FROM tracks WHERE album_uri = \"${album}\""); do
    name=$(/usr/bin/sqlite3 $db "SELECT name FROM tracks WHERE uri = \"$track\"")
    echo "#EXTINF:-1,$name"
    echo "$track"
done >> ${playlist}
/usr/bin/chown mopidy:audio ${playlist}

It is a shame that you can't add artwork to a playlist as it would make sense here to put the cover art on it. However I don't think its possible in the m3u8 format and Iris does not support this.

gwm commented 3 years ago

just note to say that I also confirm that Iris does not show the playlists created until you "Add" them. However, I notice that mopidy-mobile on android picked them up straight away. @fmarzocca

Chaphasilor commented 3 years ago

@arthurlutz maybe you could do this using a mopidy command? Iris supports adding custom commands; there might be a way to have it "replace the queue with random tracks".
Just a random thought, I haven't looked into commands yet :)