A state of semi-focused relaxation, with a smidgeon of oomph, and a smattering of zing, is just the thing to help me unwind. For some reason, the tones of The Mermen always seem to direct me towards that state. Live recordings of Instrumental Surfadelic music puts my mind in a wonderful place for coding, crafting, sleeping, driving, creating, and simply breathing.
For the most part, music listening to me means "put everything on random". While this is fine for most things, there are times when I want to listen to more than one track at a time by any given artist. Since the majority of my music listening involves using MuttonChop! for playback, and most of that playback happens on Wind (damn, that old machine needs updating), a bit of code with HTTP requests should do what I need.
the Need
What I really wanted was a script that would:
- take a number as an argument
- get a list of all Mermen tunes from Wind
- pick a random index in the tune list
- starting at the index, have Wind queue X number in a row from the list
Enter the ruby
require 'open-uri'
require 'json'
#how many tracks are going to be played?
num = ARGV[0].to_i
num = 1 if num == 0
#what is the URL for all mermen tracks on wind?
url = "http://wind:2876/audio/search/mermen"
#get the text from the url
text = open( url ).read()
#parse the text to JSON data
data = JSON.parse(text)
files = data['files']
#base zero offset
bzo = num-1
#get a random number between 1 and the number of mermen tracks - the num we want to play
queue_index = rand(files.count-(num))
#loop from our random number to random number + our base zero offset
(queue_index..queue_index+bzo).each do |i|
# get the file at this index
file = files[i]
#get the id of the file at this index
id = file["id"]
#create a queue url for this file
new_url = "http://wind:2876/queue/add/audio/#{id}"
puts "#{i}: #{new_url}"
#call the url to add the file to the queue
open( new_url )
#don't go to fast
sleep 0.1
end
For easier copy/paste, the code is available at http://hoof.jezra.net/snip/os
So there you have it, a nice script to do exactly what I want. Now, when I need to get into that certain place, a quick 'wind_queue_mermen.rb 5
' does the trick.
Why stop there? A bit of blather config editing, and queuing five Mermen tunes is as easy as picking up the Cronos microphone and saying "queue five mermen". BOOYAH!
Now quite reading, and go to https://archive.org/details/Mermen for some wonderful live recordings.