Skip to content

Commit

Permalink
speed up art management avoiding duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
lusum committed Apr 9, 2021
1 parent d223303 commit dc520c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 11 additions & 1 deletion resources/lib/ampache_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
12 changes: 5 additions & 7 deletions resources/lib/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit dc520c2

Please sign in to comment.