def delete_from_list(self, sids, playlist_id=0): if playlist_id and nplayer.delete_from_onlinelist(sids, playlist_id): event_manager.emit('refresh-online-list', playlist_id) elif not playlist_id: self.delete_items([item for item in self.items if item.get_song()['id'] in sids]) event_manager.emit('save-playing-status')
def add_songs(self, songs, pos=None, sort=False, play=False): if not songs: return try: song_items = [ SongItem(song) for song in songs if song["id"] not in [exists_song["id"] for exists_song in self.get_songs()] ] except: song_items = [ SongItem(Song(song)) for song in songs if song not in [exists_song["id"] for exists_song in self.get_songs()] ] if song_items: if not self.items: self.emit_add_signal() self.add_items(song_items, pos, False) event_manager.emit("save-playing-status") if len(songs) >= 1 and play: song = songs[0] self.request_song(song, play=True)
def delete_from_list(self, sids, playlist_id=0): if playlist_id and nplayer.delete_from_onlinelist(sids, playlist_id): event_manager.emit('refresh-online-list', playlist_id) elif not playlist_id: self.delete_items( [item for item in self.items if item.get_song()['id'] in sids]) event_manager.emit('save-playing-status')
def handle_login_dialog_status(self, *kwargs): # When load finished if str(self.webview.get_load_status()) == "<enum WEBKIT_LOAD_FINISHED of type WebKitLoadStatus>": # Show current URL in terminal url = self.webview.get_property('uri') print "current url>>> ", url # Hide an element if 'https://api.weibo.com/oauth2/authorize' in url: self.webview.execute_script('document.getElementsByClassName("WB_btn_pass")[0].style.display="None"') elif 'http://music.163.com/back/weibo?error' in url: self.close() elif 'http://music.163.com/back/weibo?state=' in url: # load cookie cookie = {} with open(get_cookie_file(), 'r') as f: for line in f.readlines(): if "music.163.com" in line: line = line.split() cookie[line[5]] = line[6] nplayer.cookies = cookie nplayer.save_cookie(cookie) print 'login-success emit from LoginDialog' event_manager.emit("login-success") self.close()
def add_to_list(self, sids, playlist_id=0): if playlist_id and nplayer.add_to_onlinelist(sids, playlist_id): event_manager.emit("refresh-online-list", playlist_id) elif not playlist_id: event_manager.emit( "add-songs-to-playing-list", ([song for song in self.get_songs() if song["id"] in sids], False) )
def handle_login_dialog_status(self, *kwargs): # When load finished if str(self.webview.get_load_status() ) == "<enum WEBKIT_LOAD_FINISHED of type WebKitLoadStatus>": # Show current URL in terminal url = self.webview.get_property('uri') print "current url>>> ", url # Hide an element if 'https://api.weibo.com/oauth2/authorize' in url: self.webview.execute_script( 'document.getElementsByClassName("WB_btn_pass")[0].style.display="None"' ) elif 'http://music.163.com/back/weibo?error' in url: self.close() elif 'http://music.163.com/back/weibo?state=' in url: # load cookie cookie = {} with open(get_cookie_file(), 'r') as f: for line in f.readlines(): if "music.163.com" in line: line = line.split() cookie[line[5]] = line[6] nplayer.cookies = cookie nplayer.save_uid_and_cookies() print 'login-success emit from LoginDialog' event_manager.emit("login-success") self.close()
def SetLoginStatus(self, cookie, username, uid): print "login_type" self.cookie = cookie self.username = username self.uid = uid if self.cookie: event_manager.emit("login-success") self.save()
def render_onlinelist_songs(self, songs, thread_id): if songs and self.view_type == self.FAVORITE_LIST_TYPE: event_manager.emit('favorite-list-refreshed', songs) if self.onlinelist_thread_id != thread_id: return if songs: self.add_songs([Song(song) for song in songs])
def render_onlinelist_songs(self, songs, thread_id): if songs and self.view_type == self.FAVORITE_LIST_TYPE: event_manager.emit("favorite-list-refreshed", songs) if self.onlinelist_thread_id != thread_id: return if songs: self.add_songs([Song(song) for song in songs])
def add_to_list(self, sids, playlist_id=0): if playlist_id and nplayer.add_to_onlinelist(sids, playlist_id): event_manager.emit('refresh-online-list', playlist_id) elif not playlist_id: event_manager.emit( 'add-songs-to-playing-list', ([song for song in self.get_songs() if song['id'] in sids], False))
def fm_trash(self, current_item): if nplayer.fm_trash(current_item.get_song()['id']): event_manager.emit('refresh-favorite-list') if self.highlight_item == current_item: next_song = self.get_next_song() self.delete_items([current_item]) self.request_song(next_song) else: self.delete_items([current_item]) self.pre_fetch_fm_songs()
def fm_trash(self, current_item): if nplayer.fm_trash(current_item.get_song()["id"]): event_manager.emit("refresh-favorite-list") if self.highlight_item == current_item: next_song = self.get_next_song() self.delete_items([current_item]) self.request_song(next_song) else: self.delete_items([current_item]) self.pre_fetch_fm_songs()
def add_fm(self, songs, pos=None, sort=False, play=False): song_items = [SongItem(song) for song in songs] if song_items: if not self.items: self.emit_add_signal() self.add_items(song_items, pos, False) event_manager.emit("save-playing-status") if len(songs) >= 1 and play: song = songs[0] self.request_song(song, play=True)
def add_songs(self, songs, pos=None, sort=False, play=False): if not songs: return try: song_items = [ SearchSongItem(song) for song in songs if song not in self.get_songs() ] except: song_items = [ SearchSongItem(Song(song)) for song in songs if song not in self.get_songs() ] if song_items: if not self.items: self.emit_add_signal() self.add_items(song_items, pos, False) event_manager.emit("save-playing-status") if len(songs) >= 1 and play: song = songs[0] self.request_song(song, play=True)
def play_song(self, song, play=False): if not song: return None # update song info self.update_songitem(song) # clear current select status del self.select_rows[:] self.queue_draw() # set item highlight self.set_highlight_song(song) if play: # play song now Player.play_new(song) # set self as current global playlist self.set_current_source() event_manager.emit("save-playlist-status") return song
def __init__(self, list_data, is_online_list=False, is_login_item=False): TreeItem.__init__(self) self.column_index = 0 self.side_padding = 5 self.is_highlight = False self.padding_y = 0 self.padding_x = 8 if isinstance(list_data, basestring): self.title = list_data self.data = dict() self.list_type = self.PLAYING_LIST_TYPE else: self.title = list_data.get("name", "") self.data = list_data #self.list_id = list_data.get('id', '') self.data = list_data if is_online_list: if self.data['specialType'] == 5: self.list_type = self.FAVORITE_LIST_TYPE elif self.data['subscribed']: self.list_type = self.COLLECTED_LIST_TYPE else: self.list_type = self.CREATED_LIST_TYPE else: self.list_type = self.PLAYING_LIST_TYPE if is_login_item: self.list_type = self.LOGIN_LIST_TYPE self.has_separator = 1 self.separator_height = 4 self.item_width = CATEGROYLIST_WIDTH self.item_height = 26 + self.separator_height if self.has_separator else 26 self.init_pixbufs() self.song_view = MusicView(data=self.data, view_type=self.list_type) self.song_view.set_size_request(PLAYLIST_WIDTH, -1) if is_login_item: self.login_box = LoginBox(lambda w: event_manager.emit("login")) event_manager.connect("login", self.login) #event_manager.connect("login-success", self.on_event_login_success) self.main_box = gtk.VBox()
def __init__(self, list_data, list_type, is_online_list=False, has_separator=True): TreeItem.__init__(self) self.column_index = 0 self.side_padding = 5 self.is_highlight = False self.padding_y = 0 self.padding_x = 8 if list_type and list_type in [self.PLAYING_LIST_TYPE, self.PERSONAL_FM_ITEM, self.LOGIN_LIST_TYPE]: self.title = list_data else: self.title = list_data.get("name", "") self.data = list_data self.list_type= list_type if is_online_list: if self.data['specialType'] == 5: self.list_type = self.FAVORITE_LIST_TYPE elif self.data['subscribed']: self.list_type = self.COLLECTED_LIST_TYPE else: self.list_type = self.CREATED_LIST_TYPE self.has_separator = has_separator self.separator_height = 4 self.item_width = CATEGROYLIST_WIDTH self.item_height = 26 + self.separator_height if self.has_separator else 26 self.init_pixbufs() self.song_view = MusicView(data=self.data, view_type=self.list_type) self.song_view.set_size_request(PLAYLIST_WIDTH, -1) if self.list_type == self.LOGIN_LIST_TYPE: self.login_box = LoginBox(lambda w: event_manager.emit("login")) event_manager.connect("login", self.login) self.main_box = gtk.VBox()
def subscribe_playlist(self, current_item): if nplayer.subscribe_playlist(current_item.get_playlist_id): event_manager.emit('refresh-online-lists')
def AddSongs(self, dummy_songs): songs = self.parse_dummy_songs(dummy_songs) if songs: event_manager.emit("add-songs", songs)
def add_play_emit(self, songs): event_manager.emit("add-songs-to-playing-list", (songs, True))
def add_to_playlist(self, songs): self.add_and_play_songs = songs event_manager.emit("add-songs-to-playing-list")
def PlaySongs(self, songs): if songs: event_manager.emit("play-songs", songs)
def delete_playing_list_items(self, items): self.delete_items(items) event_manager.emit('save-playing-status')
def fm_like(self, song, flag): if nplayer.fm_like(song["id"], flag): event_manager.emit("refresh-favorite-list")
def FavoriteSongs(self, dummy_songs): songs = self.parse_dummy_songs(dummy_songs) if songs: event_manager.emit("collect-songs", songs)
def add_play_emit(self, songs): self.add_and_play_songs = songs event_manager.emit('add-and-play')
def fm_like(self, song, flag): if nplayer.fm_like(song['id'], flag): event_manager.emit('refresh-favorite-list')
def hover(self, column, offset_x, offset_y): event_manager.emit("update-playlist-tooltip", HTMLParser().unescape(self.title)); self.is_hover = True self.emit_redraw_request()
def FavoriteSongs(self, songs): if songs: event_manager.emit("collect-songs", songs)
def add_play_emit(self, sids): songs = nplayer.songs_detail(sids) songs = [Song(song) for song in songs] event_manager.emit('add-songs-to-playing-list', (songs, True))
def clear_items(self): self.clear() event_manager.emit("save-playing-list")
def add_to_list(self, sids, playlist_id=0): if playlist_id and nplayer.add_to_onlinelist(sids, playlist_id): event_manager.emit('refresh-online-list', playlist_id) elif not playlist_id: event_manager.emit('add-songs-to-playing-list', (nplayer.songs_detail(sids), False))
def add_to_playlist(self, songs): self.add_and_play_songs = songs event_manager.emit('add-to-playlist')
def login_success(self, args, *kwargs): event_manager.emit('login-success')
def add_play_emit(self, songs): event_manager.emit('add-songs-to-playing-list', (songs, True))
def add_play_emit(self, songs): self.add_and_play_songs = songs event_manager.emit('add-songs-to-playing-list-and-play')
def hover(self, column, offset_x, offset_y): event_manager.emit("update-song-tooltip", HTMLParser().unescape(self.tooltip_text)) self.is_hover = True self.emit_redraw_request()
def add_to_playlist(self, songs): self.add_and_play_songs = songs event_manager.emit('add-songs-to-playing-list')
def AddSongs(self, songs): if songs: event_manager.emit("add-songs", songs)
def inner(*args, **kwars): if nplayer.is_login: return func(*args, **kwargs) else: event_manager.emit('login-dialog-run')
def clear_items(self): self.clear() event_manager.emit("save-playing-status")
def PlaySongs(self, dummy_songs): songs = self.parse_dummy_songs(dummy_songs) if songs: event_manager.emit("play-songs", songs)
def delete_playing_list_items(self, items): self.delete_items(items) event_manager.emit("save-playing-status")