2016-03-06

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:

  1. take a number as an argument
  2. get a list of all Mermen tunes from Wind
  3. pick a random index in the tune list
  4. starting at the index, have Wind queue X number in a row from the list

Enter the ruby

#!/usr/bin/env ruby
require 'open-uri'
require 'json'

#how many tracks are going to be played?
num ARGV[0].to_i
num 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 openurl ).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
  opennew_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.

Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
4 minus 1
Answer:
required
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008