예제 #1
0
def list_track(kodi_directory, stats):
    root = kodi_directory.root
    total = 0
    tmp_directory = Directory(None, asList=True)
    final_directory = Directory(None, asList=True)
    if is_track(root):
        tmp_directory.add_node(root)
    else:
        options = helper.TreeTraverseOpts(xdir=tmp_directory,
                                          lvl=3,
                                          whiteFlag=Flag.ALL,
                                          blackFlag=Flag.STOPBUILD)
        populate_node(root, options)
    total = len(tmp_directory.nodes)
    if not total:
        logger.info('NoTrack')
        return []

    progress_update(kodi_directory, 'Begin', '', cyclic_progress(stats))
    seen = Struct(**{'albums': {}, 'tracks': {}})
    for node in tmp_directory.nodes:
        progress_update(kodi_directory, u'Scanning', node.get_label(),
                        cyclic_progress(stats))
        node.set_parameter('mode', Mode.SCAN)
        if is_track(node):
            _list_track_process_node_track(final_directory, seen, node)
        else:
            _list_track_process_node_other(final_directory, seen, node)

    return final_directory.nodes
예제 #2
0
 def run(self):
     '''Building our tree, creating root node based on our node_type
     '''
     if not self.set_root_node():
         logger.warn('Cannot set root node (%s, %s)', self.node_type,
                     self.root.get_parameter('nid'))
         return False
     if self.has_method_parameter():
         return self.execute_method_parameter()
     with Directory(self.root,
                    self.nodes,
                    handle=config.app.handle,
                    showProgress=True,
                    asList=self.asList) as kodi_directory:
         if config.app.registry.get('contextmenu_replaceitems', to='bool'):
             kodi_directory.replaceItems = True
         try:
             options = helper.TreeTraverseOpts(xdir=kodi_directory,
                                               lvl=self.depth,
                                               whiteFlag=self.whiteFlag,
                                               blackFlag=self.blackFlag)
             _ret = populate_node(self.root, options)
         except exception.QobuzError as e:
             kodi_directory.end_of_directory(False)
             logger.warn('Error while populating our directory: %s', e)
             return False
         if not self.asList:
             helper_kodi_directory_setup(kodi_directory,
                                         self.root.content_type)
         return kodi_directory.end_of_directory()
예제 #3
0
 def _populate_artists(self, options):
     self.content_type = 'artists'
     for artist in self.data['artists']['items']:
         node = getNode(Flag.ARTIST, data=artist)
         node.data = node.fetch(helper.TreeTraverseOpts(noRemote=True))
         self.add_child(node)
     return True if len(self.data['artists']['items']) > 0 else False
예제 #4
0
def _list_track_helper_populate_album(xdir, album_id):
    album = getNode(Flag.ALBUM,
                    parameters={
                        'nid': album_id,
                        'mode': Mode.SCAN
                    })
    album.populating(
        helper.TreeTraverseOpts(xdir=xdir,
                                lvl=1,
                                whiteFlag=Flag.TRACK,
                                blackFlag=Flag.STOPBUILD))
예제 #5
0
    def populate(self, options=None):
        skip_empty = not config.app.registry.get(
            'display_artist_without_album', to='bool')
        for data in self.data['artists']['items']:
            if skip_empty and data['albums_count'] < 1:
                continue
            artist = getNode(Flag.ARTIST, data=data)
            cache = artist.fetch(helper.TreeTraverseOpts(lvl=3, noRemote=True))

            if cache is not None:
                artist.data = cache
            self.add_child(artist)
        return True if len(self.data['artists']['items']) > 0 else False
예제 #6
0
 def _populate_albums(self, options):
     self.content_type = 'albums'
     for album in self.data['albums']['items']:
         node = getNode(Flag.ALBUM, data=album)
         if not node.get_displayable():
             logger.warn(
                 'Album not displayable: %s (%s)',
                 node.get_label().encode(
                     'ascii', errors='ignore'),
                 node.nid)
             continue
         cache = node.fetch(helper.TreeTraverseOpts(noRemote=True))
         if cache is not None:
             node.data = cache
         self.add_child(node)
     return True if len(self.data['albums']['items']) > 0 else False
예제 #7
0
    def play(self, track_id, params=None):
        """ Playing track given a track id """
        params = {} if params is None else params
        track = getNode(Flag.TRACK, {'nid': track_id})
        data = track.fetch(helper.TreeTraverseOpts(
            lvl=1,
            whiteFlag=Flag.TRACK,
            blackFlag=Flag.NONE))
        if data is None:
            logger.warn('Cannot get track data')
            return False
        track.data = data
        if not track.is_playable():
            logger.warn('Cannot get streaming URL')
            return False
        if 'purchased' in params:
            track.parameters['purchased'] = True
        item = track.makeListItem()
        track.item_add_playing_property(item)
        # Some tracks are not authorized for stream and a 60s sample is
        # returned, in that case we overwrite the song duration
        if track.is_sample():
            item.setInfo('Music', infoLabels={'duration': 60, })
            # Don't warn for free account (all songs except purchases are 60s
            # limited)

            if not isFreeAccount():
                notify_warn("Qobuz / Free Account", "Sample returned")
            if track.is_uncredentialed():
                notify_warn("Qobuz / Uncredentialed", "Sample returned")
        xbmcgui.Window(10000).setProperty(keyTrackId, track_id)
        # Notify
        if config.app.registry.get('notification_playingsong', to='bool'):
            notify_restriction(track)
            notifyH(lang(30132), track.get_label(), image=track.get_image())
        # We are called from playlist...
        if config.app.handle == -1:
            super(QobuzPlayer, self).play(track.get_streaming_url(), item,
                                          False)
        else:
            setResolvedUrl(
                handle=config.app.handle, succeeded=True, listitem=item)
        return True
예제 #8
0
 def populate(self, options=None):
     options = options if options is None else helper.TreeTraverseOpts()
     if not self.data and len(self.data['genres']['items']) == 0:
         return self.populate_reco(options, self.nid)
     if self.nid is not None and self.data and len(
             self.data['genres']['items']) == 0:
         for genre_type in RECOS_TYPE_IDS:
             node = getNode(Flag.RECOMMENDATION, {
                 'genre-id': self.nid,
                 'genre-type': genre_type
             })
             node.populating(
                 helper.TraverseTreeOpts(xdir=options.xdir,
                                         lvl=1,
                                         whiteFlag=Flag.ALBUM,
                                         blackFlag=Flag.TRACK
                                         & Flag.STOPBUILD))
     else:
         for genre in self.data['genres']['items']:
             self.add_child(
                 Node_genre(parameters={'nid': genre['id']}, data=genre))
     return True
예제 #9
0
 def populating(self, options=None):
     options = options if options is not None else helper.TreeTraverseOpts()
     data = {} if options.data is None else options.data
     if options.lvl != -1 and options.lvl < 1:
         return False
     if self.nt & options.blackFlag != self.nt:
         new_data = self.fetch(options)
         if new_data is None:
             return False
         data.update(new_data)
         self.data = data
         self.__add_pagination(self.data)
     self.populate(options)
     new_options = options.clone()
     if options.lvl != -1:
         new_options.lvl -= 1
     self.__add_pagination_node(options.xdir, options.lvl,
                                options.whiteFlag)
     for child in self.childs:
         if (child.nt & options.whiteFlag
                 == child.nt) and not (options.xdir.add_node(child)):
             logger.error('Could not add node')
             continue
         child.populating(new_options)
예제 #10
0
def _list_track_process_node_other(final_directory, _seen, node):
    options = helper.TreeTraverseOpts(xdir=final_directory,
                                      lvl=1,
                                      whiteFlag=Flag.TRACK,
                                      blackFlag=Flag.STOPBUILD)
    populate_node(node, options)
예제 #11
0
 def populate(self, options=None):
     options = options if options is not None else helper.TreeTraverseOpts()
     return options.xdir.add_node(self)