Iris icon indicating copy to clipboard operation
Iris copied to clipboard

Quicker "add random"

Open arthurlutz opened this issue 4 years ago • 12 comments

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 :

  • click on Clear Playlist
  • click on Add
  • click on Add Random
  • scroll down
  • click on Add
  • double click on first track to start playing

Describe the solution you'd like

Would be nice :

  • click Add
  • click "Add random"

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" ?

arthurlutz avatar Aug 28 '20 10:08 arthurlutz

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.

gwm avatar Dec 09 '20 18:12 gwm

@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.

arthurlutz avatar Dec 09 '20 18:12 arthurlutz

@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!

gwm avatar Dec 10 '20 09:12 gwm

@gwm Thank you!

fmarzocca avatar Dec 10 '20 10:12 fmarzocca

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

fmarzocca avatar Dec 10 '20 11:12 fmarzocca

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

kingosticks avatar Dec 10 '20 11:12 kingosticks

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

gwm avatar Dec 10 '20 11:12 gwm

@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)

fmarzocca avatar Dec 10 '20 11:12 fmarzocca

@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 avatar Dec 10 '20 12:12 gwm

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 avatar Dec 22 '20 12:12 gwm

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

gwm avatar Jan 01 '21 18:01 gwm

@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 :)

Chaphasilor avatar Oct 24 '21 20:10 Chaphasilor