Class: ShoutcastStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/shoutcast_status.rb

Defined Under Namespace

Classes: StreamInfo

Constant Summary collapse

DEFAULT_ENDPOINT =
"http://%s/cast/"
DEFAULT_INFO_PATH =
"js.php/%s/streaminfo"
DUMMY_CALLBACK =
<<-END
  function cc_streaminfo_get_callback(details){
    return details;
  }
END

Instance Method Summary collapse

Constructor Details

#initialize(url_or_host, station = nil) ⇒ ShoutcastStatus

Create a ShoutcastStatus instance for a given station. If one parameter is given, it is taken as the url to the now playing JSONP callback or the playlist. If two parameters are given, they are interpreted as the station host and station name; the information URL will be inferred from this.



20
21
22
23
24
25
26
27
28
# File 'lib/shoutcast_status.rb', line 20

def initialize(url_or_host, station=nil)
  if station
    @info_url = (DEFAULT_ENDPOINT % url_or_host) + (DEFAULT_INFO_PATH % station)
  elsif m = url_or_host.match(%r{^(.*?/)tunein.php/([^/]+)/playlist.pls$})
    @info_url = m[1] + (DEFAULT_INFO_PATH % m[2])
  else
    @info_url = url_or_host
  end
end

Instance Method Details

#stream_infoObject

Return a StreamInfo object containing the current state of the stream.



32
33
34
35
36
37
# File 'lib/shoutcast_status.rb', line 32

def stream_info
  open @info_url do |f|
    js = f.read
    return StreamInfo.new(V8::Context.new.eval(DUMMY_CALLBACK + js))
  end
end