def gui_rename(self, playlist_id=None): if not playlist_id: playlist_id = self.nid if not playlist_id: logger.warn('Can\'t rename playlist without id') return False node = getNode(Flag.PLAYLIST, parameters={'nid': playlist_id}) data = node.fetch() if not data: logger.warn('Something went wrong while renaming playlist') return False self.data = data currentname = self.get_name() newname = ask(currentname, lang(30080)) if newname is None: return False if newname == '': notify_error(dialogHeading, 'Don\'t u call ure child something?') return False if newname == currentname: return True res = api.playlist_update(playlist_id=playlist_id, name=newname) if not res: logger.warn('Cannot rename playlist with name %s' % newname) return False self.delete_cache(playlist_id) notify_log(lang(30080), u'%s: %s' % (lang(30165), currentname)) executeBuiltin(containerRefresh()) return True
def gui_rename(self, playlist_id=None): if not playlist_id: playlist_id = self.nid if not playlist_id: warn(self, "Can't rename playlist without id") return False from qobuz.gui.util import Keyboard data = api.get('/playlist/get', playlist_id=playlist_id) if not data: warn(self, "Something went wrong while renaming playlist") return False self.data = data currentname = self.get_name() k = Keyboard(currentname, lang(30080)) k.doModal() if not k.isConfirmed(): return False newname = k.getText() newname = newname.strip() if not newname: notify_error(dialogHeading, "Don't u call ure child something?") return False if newname == currentname: return True res = api.playlist_update(playlist_id=playlist_id, name=newname) if not res: warn(self, "Cannot rename playlist with name %s" % (newname)) return False self.delete_cache(playlist_id) notify_log(lang(30080), (u"%s: %s") % (lang(30165), currentname)) executeBuiltin(containerRefresh()) return True
def _add_tracks(self, playlist_id, nodes): if len(nodes) < 1: warn(self, 'Empty list...') return False step = 50 start = 0 numtracks = len(nodes) if numtracks > 1000: notify_error('Qobuz', 'Max tracks per playlist reached (1000)' '\nSkipping %s tracks' % (numtracks - 1000)) numtracks = 1000 while start < numtracks: if (start + step) > numtracks: step = numtracks - start str_tracks = '' info(self, "Adding tracks start: %s, end: %s" % (start, start + step)) for i in range(start, start + step): node = nodes[i] if node.nt != Flag.TRACK: warn(self, "Not a Node_track node") continue str_tracks += '%s,' % (str(node.nid)) if not api.playlist_addTracks( playlist_id=playlist_id, track_ids=str_tracks): return False start += step return True
def gui_remove(self, playlist_id=None): playlist_id = self._get_playlist_id(playlist_id=playlist_id) if not playlist_id: notify_error(dialogHeading, 'Invalid playlist %s' % (str(playlist_id))) return False data = api.get('/playlist/get', playlist_id=playlist_id, limit=self.limit, offset=self.offset) if data is None: logger.error('Cannot get playlist with id %s', playlist_id) return False name = '' if 'name' in data: name = data['name'] ok = xbmcgui.Dialog().yesno( lang(30166), lang(30054), color('FFFF0000', name)) if not ok: return False if data['owner']['name'] == user.username: res = api.playlist_delete(playlist_id=playlist_id) else: res = api.playlist_unsubscribe(playlist_id=playlist_id) if not res: logger.warn('Cannot delete playlist with id ' + str(playlist_id)) notify_error(lang(30183), lang(30186) + name) return False self.delete_cache(playlist_id) executeBuiltin(containerRefresh()) notify_log(lang(30183), (lang(30184) + ' %s ' + lang(30185)) % name) return True
def _add_tracks(cls, playlist_id, nodes): if len(nodes) < 1: logger.warn('Empty list...') return False step = 50 start = 0 numtracks = len(nodes) if numtracks > 1000: notify_error('Qobuz', 'Max tracks per playlist reached (1000)' '\nSkipping %s tracks' % (numtracks - 1000)) numtracks = 1000 while start < numtracks: if (start + step) > numtracks: step = numtracks - start str_tracks = '' for i in range(start, start + step): node = nodes[i] if node.nt != Flag.TRACK: logger.warn('Not a Node_track node') continue str_tracks += '%s,' % (str(node.nid)) if not api.playlist_addTracks(playlist_id=playlist_id, track_ids=str_tracks): return False start += step return True
def gui_remove_track(self): qid = self.get_parameter('qid') if not self.remove_tracks(qid): notify_error(dialogHeading, 'Cannot remove track!') return False self.delete_cache(self.nid) notify_log(dialogHeading, 'Track removed from playlist') executeBuiltin(containerRefresh()) return True
def get(self, *a, **ka): """Wrapper that cache query to our raw api. We are enforcing format because cache entry key are made based on *a and **ka parameters. ('artist/get' and '/artist/get' will generate different key) Path are mapped to raw api and raise InvalidQuery on error ::example from qobuz.api import api from qobuz.cache import cache cache.base_path = '/srv/qobuz/cache/' data = api.get('/artist/get') data = api.get('/user/login', username=api.username, password=api.password) :: note Named parameters are sorted before we generate our key ::return Pyton Dictionary on success None on error ::note api.error will contain last error message """ key_to_del = [] for key, value in ka.items(): if value is None or value == '': key_to_del.append(key) for key in key_to_del: del ka[key] if not a[0] or not a[0].startswith('/'): raise InvalidQuery("Missing starting << / >>") path = '/'.join(a) path.replace('//', '/') # Defected for n / ... path = path[1:] if path.endswith('/'): raise InvalidQuery('Invalid trailing << / >>') xpath = path.split('/') if len(xpath) < 1: raise InvalidQuery(path) methname = '%s_%s' % (xpath[0], xpath[1]) if not hasattr(self, methname): raise InvalidQuery(path) # Passing user_id create different key for the cache... for label in self.__clean_ka(xpath[0], xpath[1], **ka): del ka[label] response = getattr(self, methname)(**ka) if self.status_code != 200: logger.warn('Method: %s/%s: %s', methname, self.error, self.status_code) if self.notify: notify_error( 'API Error/{method} {status_code}'.format( method=methname, status_code=self.status_code), '{error}'.format(error=self.error)) return response
def gui_remove_track(self): qid = self.get_parameter('qid') print "Removing track %s from playlist %s" % (qid, self.nid) if not self.remove_tracks(qid): notify_error(dialogHeading, 'Cannot remove track!') return False self.delete_cache(self.nid) notify_log(dialogHeading, 'Track removed from playlist') executeBuiltin(containerRefresh()) return True
def toggle_privacy(self): if self.data is None: self.data = self.fetch() privacy = not self.get_property('is_public', to='bool') res = api.playlist_update( playlist_id=self.nid, is_public=str(privacy).lower()) if res is None: notify_error('Qobuz', 'Cannot toggle privacy') return False self.delete_cache(self.nid) notify_log(dialogHeading, 'Privacy changed public: %s' % privacy) executeBuiltin(containerRefresh()) return True
def gui_add_as_new(self, _=None): nodes = [] qnt = int(self.get_parameter('qnt')) qid = self.get_parameter('qid') name = self.get_parameter('query', to='unquote', default=None) if qnt & Flag.SEARCH: self.del_parameter('query') if qnt & Flag.TRACK == Flag.TRACK: node = getNode(qnt, parameters={'nid': qid}) node.data = node.fetch() nodes.append(node) else: render = renderer( qnt, parameters=self.parameters, depth=-1, whiteFlag=Flag.TRACK, asList=True) render.run() nodes = render.nodes if len(nodes) == 0: return False if name is None: name = ask('Playlist name? (i8n)') if name is None: return False ret = xbmcgui.Dialog().select('Create playlist %s' % name, [node.get_label() for node in nodes]) if ret == -1: return False playlist = self.create(name) if not playlist: notify_error('Qobuz', 'Playlist creationg failed') logger.warn('Cannot create playlist...') return False if not self._add_tracks(playlist['id'], nodes): notify_error('Qobuz / Cannot add tracks', '%s' % name) return False self.delete_cache(playlist['id']) notify_log('Qobuz / Playlist added', '[%s] %s' % (len(nodes), name)) executeBuiltin(containerRefresh()) return True
def gui_remove(self, playlist_id=None): if not playlist_id: playlist_id = self.nid if not playlist_id: notify_error(dialogHeading, 'Invalid playlist %s' % (str(playlist_id))) return False login = getSetting('username') offset = 0 limit = getSetting('pagination_limit') data = api.get('/playlist/get', playlist_id=playlist_id, limit=limit, offset=offset) name = '' if 'name' in data: name = data['name'] ok = xbmcgui.Dialog().yesno(lang(30166), lang(30054), color('FFFF0000', name)) if not ok: info(self, "Deleting playlist aborted...") return False res = False if data['owner']['name'] == login: info(self, "Deleting playlist: " + str(playlist_id)) res = api.playlist_delete(playlist_id=playlist_id) else: info(self, 'Unsuscribe playlist' + str(playlist_id)) res = api.playlist_unsubscribe(playlist_id=playlist_id) if not res: warn(self, "Cannot delete playlist with id " + str(playlist_id)) notify_error(lang(30183), lang(30186) + name) return False self.delete_cache(playlist_id) notify_log(lang(30183), (lang(30184) + "%s" + lang(30185)) % (name)) url = self.make_url(nt=Flag.USERPLAYLISTS, mode=Mode.VIEW, nm='', nid='') executeBuiltin(containerUpdate(url, True)) return False
def gui_add_as_new(self, name=None): nodes = [] qnt = int(self.get_parameter('qnt')) qid = self.get_parameter('qid') if qnt & Flag.SEARCH: self.del_parameter('query') if qnt & Flag.TRACK == Flag.TRACK: node = getNode(qnt, {'nid': qid}) node.fetch(None, None, None, Flag.NONE) nodes.append(node) else: render = renderer(qnt, self.parameters) render.depth = -1 render.whiteFlag = Flag.TRACK render.asList = True render.run() nodes = render.nodes if name is None: name = self.get_parameter('query', unQuote=True, default=None) \ or self.get_label() ret = xbmcgui.Dialog().select('Create playlist %s' % (name), [ node.get_label() for node in nodes ]) if ret == -1: return False playlist = self.create(name) if not playlist: notify_error('Qobuz', 'Playlist creationg failed') warn(self, "Cannot create playlist...") return False if not self._add_tracks(playlist['id'], nodes): notify_error('Qobuz / Cannot add tracks', "%s" % (name)) return False self.delete_cache(playlist['id']) notify_log('Qobuz / Playlist added', '[%s] %s' % (len(nodes), name)) executeBuiltin(containerRefresh()) return True