diff --git a/resources/lib/ampache_plugin.py b/resources/lib/ampache_plugin.py index dc32353..fd8098f 100644 --- a/resources/lib/ampache_plugin.py +++ b/resources/lib/ampache_plugin.py @@ -251,6 +251,9 @@ def addPlayLinks(elem, object_type , object_subtype=None): elif elem_type == "podcast_episode": xbmcplugin.addSortMethod(int(sys.argv[1]),xbmcplugin.SORT_METHOD_LABEL) + allid=set() + albumTrack={} + for node in elem.iter(elem_type): object_id = node.attrib["id"] if not object_id: @@ -267,8 +270,15 @@ def addPlayLinks(elem, object_type , object_subtype=None): if elem_type == "song": image_url = node.findtext("art") try: + #speed up art management for album songs, avoid duplicate + #calls album_id = getNestedTypeId(node,"album") - albumArt = art.get_art(album_id,"album",image_url) + if album_id not in allid: + allid.add(album_id) + albumArt = art.get_art(album_id,"album",image_url) + albumTrack[album_id]=albumArt + else: + albumArt=albumTrack[album_id] except: albumArt = art.get_art(None,"album",image_url) diff --git a/resources/lib/art.py b/resources/lib/art.py index 6fffff7..03877bb 100644 --- a/resources/lib/art.py +++ b/resources/lib/art.py @@ -20,9 +20,10 @@ cacheDir = os.path.join( user_mediaDir , 'cache' ) def cacheArt(imageID,elem_type,url=None): - cacheDirType = os.path.join( cacheDir , elem_type ) - if not imageID: + if not imageID or not url: raise NameError + + cacheDirType = os.path.join( cacheDir , elem_type ) possible_ext = ["jpg", "png" , "bmp", "gif", "tiff"] for ext in possible_ext: @@ -40,8 +41,6 @@ def cacheArt(imageID,elem_type,url=None): try: if(int(ampache.getSetting("api-version"))) < 400001: - if not url: - raise NameError #old api version headers,contents = ampacheConnect.handle_request(url) else: @@ -68,6 +67,7 @@ def cacheArt(imageID,elem_type,url=None): fname = imageID + ".jpg" else: fname = imageID + '.' + subtype + pathImage = os.path.join( cacheDirType , fname ) with open( pathImage, 'wb') as f: f.write(contents) @@ -94,10 +94,8 @@ def get_artLabels(albumArt): def get_art(object_id,elem_type,url=None): albumArt = "DefaultFolder.png" - if object_id == None: - return albumArt #no url, no art, so no need to activate a connection - if not url: + if not object_id or not url: return albumArt try: albumArt = cacheArt(object_id,elem_type,url)