koditidal2.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:plugin.audio.tidal2 作者: arnesongit 项目源码 文件源码
def update_albums_in_items(self, items, forceAll=False):
        if self._config.cache_albums:
            # Step 1: Read all available Albums from Cache
            self.albumQueue = Queue()
            missing_ids = []
            missing_items = []
            track_count = 0
            self.abortAlbumThreads = False
            for item in items:
                if isinstance(item, TrackItem):
                    track_count += 1
                    isAlbum = True
                    try:
                        # In Single Tracks the Album-ID is Track-ID - 1
                        if not forceAll and item.name == item.album.name and item.trackNumber == 1 and (int('%s' % item.id) - int('%s' % item.album.id)) == 1:
                            isAlbum = False
                    except:
                        pass
                    if item.available and not item.album.releaseDate and isAlbum:
                        #(item.title <> item.album.title or item.trackNumber > 1):
                        # Try to read Album from Cache
                        json_obj = self.albumJsonBuffer.get('%s' % item.album.id, None)
                        if json_obj == None:
                            json_obj = self.metaCache.getAlbumJson(item.album.id)
                        if json_obj != None:
                            item.album = self._parse_album(json_obj)
                        else:
                            missing_items.append(item)
                            if not item.album.id in missing_ids:
                                missing_ids.append(item.album.id)
                                self.albumQueue.put('%s' % item.album.id)
            # Step 2: Load JSon-Data from all missing Albums
            if len(missing_ids) <= 5 or self._config.max_http_requests <= 1:
                # Without threads
                self.get_album_json_thread()
            else:
                log('Starting Threads to load Albums')
                runningThreads = []
                while len(runningThreads) < self._config.max_http_requests:
                    try:
                        worker = Thread(target=self.get_album_json_thread)
                        worker.start()
                        runningThreads.append(worker)
                    except Exception, e:
                        log(str(e), xbmc.LOGERROR)
                log('Waiting until all Threads are terminated')
                for worker in runningThreads:
                    worker.join(20)
                    if worker.isAlive():
                        log('Worker %s is still running ...' % worker.ident, xbmc.LOGWARNING)
            # Step 3: Save JsonData into MetaCache
            if len(missing_items) > 0:
                numAlbums = self.save_album_cache()
                log('Cached %s from %s missing Albums for %s TrackItems' % (numAlbums, len(missing_items), track_count))
                # Step 4: Fill missing Albums into the TrackItems
                for item in missing_items:
                    json_obj = self.albumJsonBuffer.get('%s' % item.album.id, None)
                    if json_obj != None:
                        item.album = self._parse_album(json_obj)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号