class Player(object): def __init__(self, config): cdir = os.path.expanduser('~/.radiocrepe/songs/') if not os.path.exists(cdir): os.makedirs(cdir) self._client = Client(config.server, content_dir=cdir) self._exit = False self._content_dir = cdir self._config = config self._playing = False self._index = 0 def initialize(self, config): """ Overload this """ def run(self): self._client.initialize() self.initialize() last_ts = None while not self._exit: for song in self._client.iter_songs(): if song and song['time'] != last_ts: self._enqueue(song) last_ts = song['time'] if not self._playing: self._play_index(self._index) else: time.sleep(5) def on_song_start(self): self._playing = True self._index += 1 self._client.notify_start() def on_stop(self): self._client.notify_stop() def shutdown(self): self._client.shutdown()
class Player(object): def __init__(self, config): self._client = Client(config.server) self._exit = False self._config = config self._playing = False self._index = 0 def initialize(self, config): """ Overload this """ def run(self): self.initialize() last_ts = None while not self._exit: for song in self._client.iter_songs(): if song and song['ts_add'] != last_ts: self._enqueue(song) last_ts = song['ts_add'] if not self._playing: self._play_index(self._index) else: time.sleep(5) def on_song_start(self): self._playing = True self._index += 1 self._client.notify_start() def on_stop(self): self._client.notify_stop() def shutdown(self): self._client.shutdown()