def on_song_downloaded(self, play=False): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore iter_ = self.curr_playing[1] path = liststore.get_path(iter_) song = Widgets.song_row_to_dict(liststore[path], start=0) Gdk.Window.process_all_updates()
def on_song_downloaded(self, play=False): # copy this song from current playing list to cached_list. list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song = Widgets.song_row_to_dict(liststore[path], start=0) self.append_cached_song(song) Gdk.Window.process_all_updates()
def on_treeview_row_activated(self, treeview, path, column): model = treeview.get_model() index = treeview.get_columns().index(column) song = Widgets.song_row_to_dict(model[path], start=0) if index == 0: self.app.playlist.play_song(song, list_name=self.list_name) elif index == 1: self.app.search.search_artist(song['artist']) elif index == 2: self.app.search.search_album(song['album'])
def on_treeview_row_activated(self, treeview, path, column): model = treeview.get_model() index = treeview.get_columns().index(column) song = Widgets.song_row_to_dict(model[path], start=0) if index == self.COL_NAME: self.app.playlist.play_song(song, list_name=self.list_name) elif index == self.COL_ARTIST: self.app.search.search_artist(song['artist']) elif index == self.COL_ALBUM: self.app.search.search_album(song['album'])
def do_cache_song_pool(self): def _remove_song(): try: liststore.remove(liststore[path].iter) except IndexError: logger.error(traceback.format_exc()) Gdk.Window.process_all_updates() def _on_disk_error(widget, song_path, eror=None): self.stop_caching_daemon() GLib.idle_add(Widgets.filesystem_error, self.app.window, song_path) def _on_network_error(widget, song_link, error=None): self.stop_caching_daemon() GLib.idle_add(Widgets.network_error, self.app.window, _('Failed to cache song')) def _on_chunk_received(widget, percent): GLib.idle_add(do_on_chunk_received, percent) def do_on_chunk_received(percent): self.cache_local_count += 1 self.cache_speed_label.set_text('{0} %'.format(int(percent * 100))) def _on_downloaded(widget, song_path, error=None): if song_path: GLib.idle_add(_remove_song) if self.cache_enabled: GLib.idle_add(self.do_cache_song_pool) 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)
def cache_next_song(self): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore path = self.curr_playing[1] if path == len(liststore) - 1: return path += 1 song = Widgets.song_row_to_dict(liststore[path], start=0) print('next song to cache:', song) self.cache_next_async_song = Net.AsyncSong(self.app) self.cache_next_async_song.get_song(song)
def on_treeview_row_activated(self, treeview, path, column): model = treeview.get_model() index = treeview.get_columns().index(column) song = Widgets.song_row_to_dict(model[path], start=0) if index == 0: self.app.playlist.play_song(song, list_name=self.list_name) elif index == 1: self.app.search.search_artist(song['artist']) elif index == 2: self.app.search.search_album(song['album']) elif index == 3: model.remove(model[path].iter)
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 on_treeview_row_activated(self, treeview, path, column): model = treeview.get_model() index = treeview.get_columns().index(column) song = Widgets.song_row_to_dict(model[path], start=0) if index == 0: self.app.playlist.play_song(song, list_name=self.list_name) elif index == 1: self.app.search.search_artist(song['artist']) elif index == 2: self.app.search.search_album(song['album']) elif index == 3: if self.list_name == 'Cached': self.app.playlist.remove_song_from_cached_db(song['rid']) model.remove(model[path].iter)
def do_export(button): num_songs = len(liststore) i = 0 export_dir = folder_chooser.get_filename() for item in liststore: song = Widgets.song_row_to_dict(item, start=0) song_link, song_path = Net.get_song_link(song, self.app.conf) if song_link is not True: continue shutil.copy(song_path, export_dir) i += 1 export_prog.set_fraction(i / num_songs) Gdk.Window.process_all_updates() dialog.destroy()
def play_song(self, song, list_name='Default'): if not song: return liststore = self.tabs[list_name].liststore rid = song['rid'] path = self.get_song_path_in_liststore(liststore, rid) if path is not None: # curr_playing contains: listname, path self.curr_playing = [list_name, path] song = Widgets.song_row_to_dict(liststore[path], start=0) self.app.player.load(song) return liststore.append(Widgets.song_dict_to_row(song)) self.curr_playing = [list_name, len(liststore)-1, ] self.app.player.load(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_can_play(widget, song_path, status, error=None): if status == 'OK': return # stop cache service when error occurs self.cache_enabled = False if status == 'URLError': Widgets.network_error( self.app.window, _('Failed to cache song')) elif status == 'FileNotFoundError': Widgets.filesystem_error(self.app.window, song_path) 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('can-play', _on_can_play) self.cache_job.connect('downloaded', _on_downloaded) self.cache_job.get_song(song)
def do_cache_song_pool(self): def _move_song(): self.append_cached_song(song) try: liststore.remove(liststore[path].iter) except IndexError: pass Gdk.Window.process_all_updates() def _on_can_play(widget, song_path, status, error=None): if status == 'OK': return # stop cache service when error occurs self.cache_enabled = False if status == 'URLError': Widgets.network_error(self.app.window, _('Failed to cache song')) elif status == 'FileNotFoundError': Widgets.filesystem_error(self.app.window, song_path) def _on_downloaded(widget, song_path, error=None): if song_path: GLib.idle_add(_move_song) if self.cache_enabled is True: GLib.idle_add(self.do_cache_song_pool) if self.cache_enabled is False: 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('song dict to download:', song) self.cache_job = Net.AsyncSong(self.app) self.cache_job.connect('can-play', _on_can_play) self.cache_job.connect('downloaded', _on_downloaded) self.cache_job.get_song(song)
def run(self): file_nums = len(self.liststore) for i, item in enumerate(self.liststore): if self.stop_flag: return song = Widgets.song_row_to_dict(item, start=0) cached, song_link, song_path = Net.get_song_link(song, self.conf) if not cached: continue shutil.copy(song_path, self.export_dir) if self.including_lrc: lrc_path, lrc_cached = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, self.export_dir) self.emit('copied', song['name'], i) self.emit('finished', file_nums)
def get_prev_song(self, repeat): list_name = self.curr_playing[0] if not list_name: return None liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if path == 0: if repeat: path = song_nums - 1 else: path = 0 else: path = path - 1 self.prev_playing = path return Widgets.song_row_to_dict(liststore[path], start=0)
def get_next_song(self, repeat, shuffle): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if shuffle: path = random.randint(0, song_nums-1) elif path == song_nums - 1: if not repeat: return None path = 0 else: path = path + 1 self.next_playing = path return Widgets.song_row_to_dict(liststore[path], start=0)
def get_next_song(self, repeat, shuffle): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if shuffle: path = random.randint(0, song_nums-1) elif path == song_nums - 1: if repeat is False: return None path = 0 else: path = path + 1 self.next_playing = path return Widgets.song_row_to_dict(liststore[path], start=0)
def get_prev_song(self, repeat): list_name = self.curr_playing[0] if list_name is None: return None liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if path == 0: if repeat: path = song_nums - 1 else: path = 0 else: path = path - 1 self.prev_playing = path return Widgets.song_row_to_dict(liststore[path], start=0)
def do_export(button): num_songs = len(liststore) export_dir = folder_chooser.get_filename() export_lrc = with_lrc.get_active() for i, item in enumerate(liststore): song = Widgets.song_row_to_dict(item, start=0) song_link, song_path = Net.get_song_link( song, self.app.conf) if song_link is not True: continue shutil.copy(song_path, export_dir) if export_lrc: (lrc_path, lrc_cached) = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, export_dir) export_prog.set_fraction(i / num_songs) Gdk.Window.process_all_updates() dialog.destroy()
def get_prev_song(self, repeat=False, shuffle=False): print('get prev song()') list_name = self.curr_playing[0] if list_name is None: return liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if shuffle: path = random.randint(0, song_nums-1) elif path == 0: # Already reach top of the list, maybe we can repeat from bottom path = 0 else: path = path - 1 self.curr_playing[1] = path return Widgets.song_row_to_dict(liststore[path], start=0)
def do_export(self, button): num_songs = len(self.liststore) export_dir = self.folder_chooser.get_filename() export_lrc = self.with_lrc.get_active() for i, item in enumerate(self.liststore): song = Widgets.song_row_to_dict(item, start=0) cached, song_link, song_path = Net.get_song_link( song, self.app.conf) if not cached: continue self.export_prog.set_fraction(i / num_songs) self.export_prog.set_text(song['name']) shutil.copy(song_path, export_dir) if export_lrc: lrc_path, lrc_cached = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, export_dir) Gdk.Window.process_all_updates() self.destroy()
def get_next_song(self, repeat=False, shuffle=False): print('get next song()') list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore path = self.curr_playing[1] song_nums = len(liststore) if song_nums == 0: return None if shuffle: path = random.randint(0, song_nums-1) elif path == song_nums - 1: if repeat is False: return None # repeat from the first song path = 0 else: path = path + 1 self.curr_playing[1] = path return Widgets.song_row_to_dict(liststore[path], start=0)
def play_song(self, song, list_name='Default', use_mv=False): if not song: return if not list_name: list_name = 'Default' liststore = self.tabs[list_name].liststore rid = song['rid'] path = self.get_song_path_in_liststore(liststore, rid) if path > -1: # curr_playing contains: listname, path self.curr_playing = [list_name, path] song = Widgets.song_row_to_dict(liststore[path], start=0) else: liststore.append(Widgets.song_dict_to_row(song)) self.curr_playing = [list_name, len(liststore)-1, ] self.locate_curr_song(popup_page=False) if use_mv is True: self.app.player.load_mv(song) else: self.app.player.load(song)
def get_prev_song(self, repeat): list_name = self.curr_playing[0] if not list_name: return None liststore = self.tabs[list_name].liststore song_nums = len(liststore) if song_nums == 0: return None iter_ = self.curr_playing[1] path = liststore.get_path(iter_) pos = int(str(path)) if pos == 0: if repeat: pos = song_nums - 1 else: pos = 0 else: pos = pos - 1 self.prev_playing = liststore.get_iter(Gtk.TreePath(pos)) return Widgets.song_row_to_dict(liststore[pos], start=0)
def get_next_song(self, repeat, shuffle): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore song_nums = len(liststore) if song_nums == 0: return None iter_ = self.curr_playing[1] path = liststore.get_path(iter_) pos = int(str(path)) if shuffle: pos = random.randint(0, song_nums - 1) elif pos == song_nums - 1: if not repeat: return None pos = 0 else: pos = pos + 1 self.next_playing = liststore.get_iter(Gtk.TreePath(pos)) return Widgets.song_row_to_dict(liststore[pos], start=0)
def get_next_song(self, repeat, shuffle): list_name = self.curr_playing[0] liststore = self.tabs[list_name].liststore song_nums = len(liststore) if song_nums == 0: return None iter_ = self.curr_playing[1] path = liststore.get_path(iter_) pos = int(str(path)) if shuffle: pos = random.randint(0, song_nums-1) elif pos == song_nums - 1: if not repeat: return None pos = 0 else: pos = pos + 1 self.next_playing = liststore.get_iter(Gtk.TreePath(pos)) return Widgets.song_row_to_dict(liststore[pos], start=0)
def play_song(self, song, list_name='Default', use_mv=False): if not song: return if not list_name: list_name = 'Default' liststore = self.tabs[list_name].liststore rid = song['rid'] path = self.get_song_path_in_liststore(liststore, rid) if path > -1: # curr_playing contains: listname, path self.curr_playing = [list_name, path] song = Widgets.song_row_to_dict(liststore[path], start=0) self.app.player.load(song) return liststore.append(Widgets.song_dict_to_row(song)) self.curr_playing = [list_name, len(liststore)-1, ] self.locate_curr_song(popup_page=False) if use_mv: self.app.player.load_mv(song) else: self.app.player.load(song)
def do_cache_song_pool(self): def _move_song(): self.append_cached_song(song) liststore.remove(liststore[path].iter) Gdk.Window.process_all_updates() def _on_downloaded(widget, song_path, error=None): self.cache_job = None GLib.idle_add(_move_song) list_name = 'Caching' liststore = self.tabs[list_name].liststore path = 0 if len(liststore) == 0: print('Caching playlist is empty, please add some') return song = Widgets.song_row_to_dict(liststore[path], start=0) print('song dict to download:', song) self.cache_job = Net.AsyncSong(self.app) self.cache_job.connect('downloaded', _on_downloaded) self.cache_job.get_song(song)
def run(self): selection = self.treeview.get_selection() liststore, selected_paths = selection.get_selected_rows() if self.export_all: file_nums = len(liststore) song_rows = liststore else: file_nums = len(selected_paths) song_rows = (liststore[path] for path in selected_paths) for i, item in enumerate(song_rows): if self.stop_flag: return song = Widgets.song_row_to_dict(item, start=0) cached, song_link, song_path = Net.get_song_link(song, self.conf) if not cached: continue shutil.copy(song_path, self.export_dir) if self.including_lrc: lrc_path, lrc_cached = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, self.export_dir) self.emit('copied', song['name'], i / file_nums) self.emit('finished', file_nums)
def run(self): selection = self.treeview.get_selection() liststore, selected_paths = selection.get_selected_rows() if self.export_all: file_nums = len(liststore) song_rows = liststore else: file_nums = len(selected_paths) song_rows = (liststore[path] for path in selected_paths) for i, item in enumerate(song_rows): if self.stop_flag: return song = Widgets.song_row_to_dict(item, start=0) cached, song_link, song_path = Net.get_song_link(song, self.conf) if not cached: continue shutil.copy(song_path, self.export_dir) if self.including_lrc: lrc_path, lrc_cached = Net.get_lrc_path(song) if lrc_cached: shutil.copy(lrc_path, self.export_dir) self.emit('copied', song['name'], i /file_nums) self.emit('finished', file_nums)
def do_cache_song_pool(self): def _move_song(): self.append_cached_song(song) liststore.remove(liststore[path].iter) Gdk.Window.process_all_updates() def _failed_to_download(song_path, status): self.cache_enabled = False if status == 'URLError': Widget.network_error(self.app.window, _('Failed to cache song')) elif status == 'FileNotFoundError': Widgets.filesystem_error(self.app.window, song_path) def _on_can_play(widget, song_path, status, error=None): if status == 'OK': return GLib.idle_add(_failed_to_download) def _on_downloaded(widget, song_path, error=None): self.cache_job = None if song_path: GLib.idle_add(_move_song) return list_name = 'Caching' liststore = self.tabs[list_name].liststore path = 0 if len(liststore) == 0: print('Caching playlist is empty, please add some') return song = Widgets.song_row_to_dict(liststore[path], start=0) print('song dict to download:', song) self.cache_job = Net.AsyncSong(self.app) self.cache_job.connect('can-play', _on_can_play) self.cache_job.connect('downloaded', _on_downloaded) 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)
def on_artist_mv_iconview_item_activated(self, iconview, path): model = iconview.get_model() song = Widgets.song_row_to_dict(model[path]) self.app.popup_page(self.app.lrc.app_page) self.app.player.load_mv(song)
def on_artist_mv_iconview_item_activated(self, iconview, path): model = iconview.get_model() song = Widgets.song_row_to_dict(model[path]) self.app.popup_page(self.app.lrc.app_page) self.app.playlist.play_song(song, use_mv=True)
def on_iconview_songs_item_activated(self, iconview, path): model = iconview.get_model() song = Widgets.song_row_to_dict(model[path]) self.app.popup_page(self.app.lrc.app_page) self.app.playlist.play_song(song, use_mv=True)