Class: Somadic::BaseChannel
- Inherits:
-
Object
- Object
- Somadic::BaseChannel
- Defined in:
- lib/somadic/base_channel.rb
Direct Known Subclasses
Constant Summary collapse
- API_TIMEOUT =
60
- ONE_DAY =
86400
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#song ⇒ Object
readonly
Returns the value of attribute song.
Instance Method Summary collapse
- #channel_list ⇒ Object
- #find_channel(name) ⇒ Object
-
#initialize(options) ⇒ BaseChannel
constructor
A new instance of BaseChannel.
-
#start ⇒ Object
Let’s go already.
-
#stop ⇒ Object
Enough already.
- #stopped? ⇒ Boolean
-
#update(time, song) ⇒ Object
Observer callback, and also one of the simplest displays possible.
Constructor Details
#initialize(options) ⇒ BaseChannel
Returns a new instance of BaseChannel.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/somadic/base_channel.rb', line 8 def initialize() @url = [:url] playlist = @url.split('/').last if playlist.end_with?('.pls') name = playlist[0..playlist.index('.pls') - 1] elsif playlist.end_with?('.m3u') name = playlist[0..playlist.index('.m3u') - 1] else Somadic::Logger.error("BaseChannel#initialize: bad playlist #{playlist}") return end @channel = find_channel(name) @mp = Mplayer.new() @mp.add_observer(self) @listeners = [:listeners] end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
3 4 5 |
# File 'lib/somadic/base_channel.rb', line 3 def channels @channels end |
#song ⇒ Object (readonly)
Returns the value of attribute song.
3 4 5 |
# File 'lib/somadic/base_channel.rb', line 3 def song @song end |
Instance Method Details
#channel_list ⇒ Object
60 61 62 |
# File 'lib/somadic/base_channel.rb', line 60 def channel_list @channels end |
#find_channel(name) ⇒ Object
56 57 58 |
# File 'lib/somadic/base_channel.rb', line 56 def find_channel(name) raise NotImplementedError end |
#start ⇒ Object
Let’s go already.
27 28 29 30 31 32 |
# File 'lib/somadic/base_channel.rb', line 27 def start Somadic::Logger.debug('BaseChannel#start') @mp.start rescue => e Somadic::Logger.error("BaseChannel#start error: #{e}") end |
#stop ⇒ Object
Enough already.
35 36 37 38 |
# File 'lib/somadic/base_channel.rb', line 35 def stop Somadic::Logger.debug('BaseChannel#stop') @mp.stop end |
#stopped? ⇒ Boolean
40 41 42 |
# File 'lib/somadic/base_channel.rb', line 40 def stopped? @mp.stopped? end |
#update(time, song) ⇒ Object
Observer callback, and also one of the simplest displays possible.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/somadic/base_channel.rb', line 45 def update(time, song) Somadic::Logger.debug("BaseChannel#update: #{time} - #{song}") songs = [{ 'started' => Time.now.to_i - 1, 'duration' => 1, 'track' => song, 'votes' => { 'up' => 0, 'down' => 0 } }] @listeners.each do |l| l.update(@channel, songs) if l.respond_to?(:update) end end |