Make a random selection from a playlist #3803
Replies: 2 comments 5 replies
-
Hi @TomKranenburg. I think it's not a usual use case, that's why it's not in a book (actually you can see something similar on pages 85-86). Some thinking should be made, which I've tried to do)) Should work. radio = playlist("default_playlist)
# Define playlist_1 as a path to `playlist file`
playlist_1 = "path/to/playlist_1.m3u"
# Good old `time_queue`
time_queue = request.queue()
# Here we are loading a random track from playlist_1
def queue_music_from_playlist() =
# Reading lines from the playlist
playlist_lines = process.read.lines("cat #{playlist_1}")
# Getting random track from the lines
random_track = list.nth(playlist_lines, random.int(min=0, max=list.length(playlist_lines)))
# Pushing a random track
time_queue.push(request.create(random_track))
end
# At 11:47:20 we push a random track from playlist to request.queue()
thread.when(predicate.activates({11h47m20s}), queue_music_from_playlist)
radio = fallback(track_sensitive=false, [time_queue, radio])
radio = mksafe(radio)
output.dummy(radio) |
Beta Was this translation helpful? Give feedback.
-
Wild workarounds appearing here! ;-) My heretic 2 cents: Couldn’t this be achieved much easier using the builtin functions?
You can test this using a time predicate of You can even specify nice transitions with |
Beta Was this translation helpful? Give feedback.
-
So I've been going through the documentation. How can I change the below single track, to a random single selection from a playlist?:
I've been going through the documentation and the book and there's not much to go on.
Beta Was this translation helpful? Give feedback.
All reactions