def load_radio(self, song, radio_item): '''Load Radio song. song from radio, only contains name, artist, rid, artistid Remember to update its information. ''' self.play_type = PlayType.RADIO self.stop_player() self.curr_radio_item = radio_item self.curr_song = song self.scale.set_sensitive(False) self.async_song = Net.AsyncSong(self.app) self.async_song.connect('chunk-received', self.on_chunk_received) self.async_song.connect('can-play', self.on_song_can_play) self.async_song.connect('downloaded', self.on_song_downloaded) self.async_song.get_song(song)
def do_cache_song_pool(self): def _move_song(): try: liststore.remove(liststore[path].iter) except IndexError: pass Gdk.Window.process_all_updates() def _on_disk_error(widget, song_path, eror=None): self.cache_enabled = False GLib.idle_add(Widgets.filesystem_error, self.app.window, song_path) def _on_network_error(widget, song_link, error=None): self.cache_enabled = False GLib.idle_add(Widgets.network_error, self.app.window, _('Failed to cache song')) def _on_downloaded(widget, song_path, error=None): if song_path: GLib.idle_add(_move_song) if self.cache_enabled: GLib.idle_add(self.do_cache_song_pool) if not self.cache_enabled: return list_name = 'Caching' liststore = self.tabs[list_name].liststore path = 0 if len(liststore) == 0: print('Caching playlist is empty, please add some songs') self.switch_caching_daemon() Notify.init('kwplayer-cache') notify = Notify.Notification.new( 'Kwplayer', _('All songs in caching list have been downloaded.'), 'kwplayer') notify.show() return song = Widgets.song_row_to_dict(liststore[path], start=0) print('will download:', song) self.cache_job = Net.AsyncSong(self.app) self.cache_job.connect('downloaded', _on_downloaded) self.cache_job.connect('disk-error', _on_disk_error) self.cache_job.connect('network-error', _on_network_error) self.cache_job.get_song(song)
def do_cache_song_pool(self): def _remove_song(): try: liststore.remove(liststore.get_iter(path)) except IndexError: logger.error(traceback.format_exc()) Gdk.Window.process_all_updates() def _on_disk_error(widget, song_path, eror=None): def on_disk_error(): logger.warn('Playlist.on_disk_error: %s, %s' % (song_path, error)) self.stop_caching_daemon() Widgets.filesystem_error(self.app.window, song_path) GLib.idle_add(on_disk_error) def _on_network_error(widget, song_link, error=None): def on_network_error(): logger.warn('Playlist.on_network_error: %s, %s' % (song_link, error)) self.stop_caching_daemon() Widgets.network_error(self.app.window, _('Failed to cache song')) GLib.idle_add(on_network_error) def _on_chunk_received(widget, percent): def on_chunk_received(): self.cache_local_count += 1 self.cache_speed_label.set_text('{0} %'.format( int(percent * 100))) GLib.idle_add(on_chunk_received) def _on_downloaded(widget, song_path, error=None): def on_downloaded(): if song_path: _remove_song() if self.cache_enabled: self.do_cache_song_pool() GLib.idle_add(on_downloaded) if not self.cache_enabled: return self.cache_local_count = 0 self.cache_global_count = 0 self.cache_speed_label.set_text('0 %') list_name = 'Caching' liststore = self.tabs[list_name].liststore path = 0 if len(liststore) == 0: logger.info('Caching playlist is empty, please add some songs') self.stop_caching_daemon() Notify.init('kwplayer-cache') notify = Notify.Notification.new( 'Kwplayer', _('All songs in caching list have been downloaded.'), 'kwplayer') notify.show() return song = Widgets.song_row_to_dict(liststore[path], start=0) logger.debug('will download: %s' % song) self.cache_job = Net.AsyncSong(self.app) self.cache_job.connect('chunk-received', _on_chunk_received) self.cache_job.connect('downloaded', _on_downloaded) self.cache_job.connect('disk-error', _on_disk_error) self.cache_job.connect('network-error', _on_network_error) self.cache_job.get_song(song)