Class: Somadic::Channel::DI
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- Somadic::Channel::DI
- Defined in:
- lib/somadic/channel/di.rb
Constant Summary
Constants inherited from BaseChannel
BaseChannel::API_TIMEOUT, BaseChannel::ONE_DAY
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
-
#find_channel(name) ⇒ Object
Overrides BaseChannel.
-
#initialize(options) ⇒ DI
constructor
A new instance of DI.
-
#stop ⇒ Object
Overrides BaseChannel.
-
#update(time, song) ⇒ Object
Observer callback.
Methods inherited from BaseChannel
Constructor Details
#initialize(options) ⇒ DI
Returns a new instance of DI.
6 7 8 9 10 11 12 13 14 |
# File 'lib/somadic/channel/di.rb', line 6 def initialize() url = if [:premium_id] "http://listen.di.fm/premium_high/#{[:channel]}.pls?#{[:premium_id]}" else "http://listen.di.fm/public3/#{[:channel]}.pls" end @channels = load_channels super(.merge({ url: url })) end |
Instance Method Details
#find_channel(name) ⇒ Object
Overrides BaseChannel
17 18 19 20 21 |
# File 'lib/somadic/channel/di.rb', line 17 def find_channel(name) Somadic::Logger.debug("DI#find_channel(#{name})") @channels.each { |c| return c if c[:name] == name } nil end |
#stop ⇒ Object
Overrides BaseChannel.
45 46 47 48 |
# File 'lib/somadic/channel/di.rb', line 45 def stop Somadic::Logger.debug('DI#stop') @mp.stop end |
#update(time, song) ⇒ Object
Observer callback.
TODO: time isn’t used, song isn’t required
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/somadic/channel/di.rb', line 26 def update(time, song) return unless @channel @song = song if song aa = Somadic::AudioAddict.new(@channel[:id]) songs = aa.refresh_playlist if songs.first[:track] != @song # try again songs = poll_for_song end @listeners.each do |l| Somadic::Logger.debug("DI#update: updating listener #{l}") l.update(@channel, songs) if l.respond_to?(:update) end rescue => e Somadic::Logger.error("DI#update: error #{e}") end |