Class: ShoutcastStatus

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

Defined Under Namespace

Classes: StreamInfo

Constant Summary collapse

DEFAULT_INFO_URL =
"http://%s/cast/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. If two parameters are given, they are interpreted as the station host and station name; the information URL will be inferred from this.



18
19
20
21
22
23
24
# File 'lib/shoutcast_status.rb', line 18

def initialize(url_or_host, station=nil)
  if station
    @info_url = DEFAULT_INFO_URL % [url_or_host, station]
  else
    @info_url = url_or_host
  end
end

Instance Method Details

#stream_infoObject

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



28
29
30
31
32
33
# File 'lib/shoutcast_status.rb', line 28

def stream_info
  open @info_url do |f|
    js = f.read
    return StreamInfo.new(Johnson.evaluate(DUMMY_CALLBACK + js))
  end
end