Class: Somadic::Channel::DI

Inherits:
BaseChannel show all
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

#channels, #song

Instance Method Summary collapse

Methods inherited from BaseChannel

#start, #stopped?

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(options)
  url = if options[:premium_id]
    "http://listen.di.fm/premium_high/#{options[:channel]}.pls?#{options[:premium_id]}"
  else
    "http://listen.di.fm/public3/#{options[:channel]}.pls"
  end
  @channels = load_channels
  super(options.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

#stopObject

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