Sha256: 1524b7aaf801685ad7a884df3c10c248adf9560c9428131823fe64ea40d1ad47
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module Somadic class BaseChannel attr_reader :channels, :song API_TIMEOUT = 60 ONE_DAY = 86400 def initialize(options) @url = options[:url] playlist = @url.split('/').last name = playlist[0..playlist.index('.pls') - 1] @channel = find_channel(name) @mp = Mplayer.new(options) @mp.add_observer(self) @listeners = options[:listeners] end # Let's go already. def start Somadic::Logger.debug('BaseChannel#start') @mp.start rescue => e Somadic::Logger.error("BaseChannel#start error: #{e}") end # Enough already. def stop Somadic::Logger.debug('BaseChannel#stop') @mp.stop end def stopped? @mp.stopped? end # Observer callback, and also one of the simplest displays possible. 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 def find_channel(name) raise NotImplementedError end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
somadic-0.0.2 | lib/somadic/base_channel.rb |
somadic-0.0.1 | lib/somadic/base_channel.rb |