Exemplo n.º 1
0
 def dispatch(self):
     '''Routing'''
     if self.MODE == Mode.PLAY:
         from qobuz.player import QobuzPlayer
         player = QobuzPlayer()
         if player.play(self.params['nid'], self.params):
             return True
         return False
     elif self.MODE == Mode.VIEW:
         r = renderer(self.nodeType, self.params)
         return r.run()
     elif self.MODE == Mode.VIEW_BIG_DIR:
         r = renderer(self.nodeType,
                      parameters=self.params,
                      whiteFlag=Flag.TRACK | Flag.ALBUM,
                      depth=-1)
         return r.run()
     elif self.MODE == Mode.SCAN:
         r = renderer(self.nodeType,
                      parameters=self.params,
                      mode=self.MODE,
                      whiteFlag=Flag.TRACK,
                      depth=-1)
         return r.scan()
     else:
         raise exception.UnknownMode(self.MODE)
Exemplo n.º 2
0
 def dispatch(self):
     '''Routing'''
     if self.MODE == Mode.PLAY:
         from qobuz.player import QobuzPlayer
         player = QobuzPlayer()
         if player.play(self.params['nid'], self.params):
             return True
         return False
     elif self.MODE == Mode.VIEW:
         r = renderer(self.nodeType, self.params)
         return r.run()
     elif self.MODE == Mode.VIEW_BIG_DIR:
         r = renderer(
             self.nodeType,
             parameters=self.params,
             whiteFlag=Flag.TRACK | Flag.ALBUM,
             depth=-1)
         return r.run()
     elif self.MODE == Mode.SCAN:
         r = renderer(
             self.nodeType,
             parameters=self.params,
             mode=self.MODE,
             whiteFlag=Flag.TRACK,
             depth=-1)
         return r.scan()
     else:
         raise exception.UnknownMode(self.MODE)
Exemplo n.º 3
0
 def gui_add_to_current(self):
     cid = self.get_current_playlist()
     qnt = int(self.get_parameter('qnt'))
     qid = self.get_parameter('qid')
     nodes = []
     if qnt & Flag.SEARCH == 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
     ret = xbmcgui.Dialog().select('Add to current playlist', [
         node.get_label() for node in nodes
     ])
     if ret == -1:
         return False
     ret = self._add_tracks(cid, nodes)
     if not ret:
         notify_warn('Qobuz', 'Failed to add tracks')
         return False
     self.delete_cache(cid)
     notify_log('Qobuz / Tracks added', '%s added' % (len(nodes)))
     return True
Exemplo n.º 4
0
 def gui_add_to_current(self):
     cid = self.get_current_playlist()
     qnt = int(self.get_parameter('qnt'))
     qid = self.get_parameter('qid')
     nodes = []
     if qnt & Flag.SEARCH == 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
     ret = xbmcgui.Dialog().select('Add to current playlist',
                                   [node.get_label() for node in nodes])
     if ret == -1:
         return False
     ret = self._add_tracks(cid, nodes)
     if not ret:
         notify_warn('Qobuz', 'Failed to add tracks')
         return False
     self.delete_cache(cid)
     notify_log('Qobuz / Tracks added', '%s added' % (len(nodes)))
     executeBuiltin(containerRefresh())
     return True
Exemplo n.º 5
0
 def list_albums(self, qnt, qid):
     ''' List albums givent a node type and a node id
     '''
     album_ids = {}
     nodes = []
     if qnt & Flag.ALBUM == Flag.ALBUM:
         node = getNode(Flag.ALBUM, {'nid': qid})
         node.data = node.fetch()
         album_ids[str(node.nid)] = 1
         nodes.append(node)
     elif qnt & Flag.TRACK == Flag.TRACK:
         render = renderer(qnt, self.parameters)
         render.depth = 1
         render.whiteFlag = Flag.TRACK
         render.blackFlag = Flag.NONE
         render.asList = True
         render.run()
         if not render.nodes:
             node = getNode(Flag.ALBUM)
             node.data = render.nodes[0].data['album']
             album_ids[str(node.nid)] = 1
             nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.ALBUM
         render.blackFlag = Flag.STOPBUILD & Flag.TRACK
         render.asList = True
         render.run()
         for node in render.nodes:
             if node.nt & Flag.ALBUM and str(node.nid) not in album_ids:
                 album_ids[str(node.nid)] = 1
                 nodes.append(node)
             if node.nt & Flag.TRACK:
                 render = renderer(qnt, self.parameters)
                 render.depth = 1
                 render.whiteFlag = Flag.TRACK
                 render.blackFlag = Flag.NONE
                 render.asList = True
                 render.run()
                 if not render.nodes:
                     newnode = getNode(
                         Flag.ALBUM, data=render.nodes[0].data['album'])
                     if not str(newnode.nid) in album_ids:
                         nodes.append(newnode)
                         album_ids[str(newnode.nid)] = 1
     return nodes
Exemplo n.º 6
0
 def render_nodes(self, nt, parameters, lvl=1, whiteFlag=Flag.ALL,
                  blackFlag=Flag.TRACK & Flag.STOPBUILD):
     render = renderer(nt, parameters)
     render.depth = -1
     render.whiteFlag = whiteFlag
     render.blackFlag = blackFlag
     render.asList = True
     render.run()
     return render
Exemplo n.º 7
0
 def render_nodes(cls,
                  nt,
                  parameters,
                  lvl=1,
                  whiteFlag=Flag.ALL,
                  blackFlag=Flag.TRACK & Flag.STOPBUILD):
     render = renderer(nt, parameters)
     render.depth = -1
     render.whiteFlag = whiteFlag
     render.blackFlag = blackFlag
     render.asList = True
     render.run()
     return render
Exemplo n.º 8
0
 def list_tracks(self, qnt, qid):
     track_ids = {}
     nodes = []
     if qnt & Flag.TRACK == Flag.TRACK:
         node = getNode(Flag.TRACK, {'nid': qid})
         node.fetch(None, None, None, Flag.NONE)
         track_ids[str(node.nid)] = 1
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.TRACK
         render.asList = True
         render.run()
         for node in render.nodes:
             if not str(node.nid) in track_ids:
                 nodes.append(node)
                 track_ids[str(node.nid)] = 1
     return nodes
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 def list_tracks(self, qnt, qid):
     '''List tracks given a node type and a node id
     '''
     track_ids = {}
     nodes = []
     if qnt & Flag.TRACK == Flag.TRACK:
         node = getNode(Flag.TRACK, parameters={'nid': qid})
         node.data = node.fetch()
         track_ids[str(node.nid)] = 1
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.TRACK
         render.asList = True
         render.run()
         for node in render.nodes:
             if str(node.nid) not in track_ids:
                 nodes.append(node)
                 track_ids[str(node.nid)] = 1
     return nodes
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
 def list_artists(self, qnt, qid):
     artist_ids = {}
     nodes = []
     if qnt & Flag.ARTIST == Flag.ARTIST:
         node = getNode(Flag.ARTIST, {'nid': qid})
         node.fetch(None, None, None, Flag.NONE)
         artist_ids[str(node.nid)] = 1
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.ALBUM & Flag.TRACK
         render.blackFlag = Flag.TRACK & Flag.STOPBUILD
         render.asList = True
         render.run()
         for node in render.nodes:
             artist = getNode(Flag.ARTIST, {'nid': node.get_artist_id()})
             if not artist.fetch(None, None, None, Flag.NONE):
                 continue
             if not str(artist.nid) in artist_ids:
                 nodes.append(artist)
                 artist_ids[str(artist.nid)] = 1
     return nodes
Exemplo n.º 13
0
 def list_artists(self, qnt, qid):
     artist_ids = {}
     nodes = []
     if qnt & Flag.ARTIST == Flag.ARTIST:
         node = getNode(Flag.ARTIST, {'nid': qid})
         node.fetch(None, None, None, Flag.NONE)
         artist_ids[str(node.nid)] = 1
         nodes.append(node)
     else:
         render = renderer(qnt, self.parameters)
         render.depth = -1
         render.whiteFlag = Flag.ALBUM & Flag.TRACK
         render.blackFlag = Flag.TRACK & Flag.STOPBUILD
         render.asList = True
         render.run()
         for node in render.nodes:
             artist = getNode(Flag.ARTIST, {'nid': node.get_artist_id()})
             if not artist.fetch(None, None, None, Flag.NONE):
                 continue
             if not str(artist.nid) in artist_ids:
                 nodes.append(artist)
                 artist_ids[str(artist.nid)] = 1
     return nodes