From 3407d47f9ccb8f2ac16b1846b20539a0256109a1 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Fri, 22 Jul 2016 16:55:57 +0200 Subject: [PATCH] Reduce boilerplate --- resources/lib/entrypoint.py | 83 +++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index cc2bcd82..df68c029 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -1299,6 +1299,7 @@ def getVideoFiles(plexId, params): xbmcplugin.endOfDirectory(int(sys.argv[1])) +@utils.CatchExceptions(warnuser=False) def getExtraFanArt(plexid, plexPath): """ Get extrafanart for listitem @@ -1314,51 +1315,45 @@ def getExtraFanArt(plexid, plexPath): utils.logMsg(title, 'Could not get a plexid, aborting', -1) return xbmcplugin.endOfDirectory(int(sys.argv[1])) - try: - # We need to store the images locally for this to work - # because of the caching system in xbmc - fanartDir = utils.tryDecode(xbmc.translatePath( - "special://thumbnails/plex/%s/" % plexid)) - if not xbmcvfs.exists(fanartDir): - # Download the images to the cache directory - xbmcvfs.mkdirs(utils.tryEncode(fanartDir)) - xml = PlexFunctions.GetPlexMetadata(plexid) - if xml is None: - utils.logMsg('Could not download metadata for %s' % plexid, -1) - return xbmcplugin.endOfDirectory(int(sys.argv[1])) + # We need to store the images locally for this to work + # because of the caching system in xbmc + fanartDir = utils.tryDecode(xbmc.translatePath( + "special://thumbnails/plex/%s/" % plexid)) + if not xbmcvfs.exists(fanartDir): + # Download the images to the cache directory + xbmcvfs.mkdirs(utils.tryEncode(fanartDir)) + xml = PlexFunctions.GetPlexMetadata(plexid) + if xml is None: + utils.logMsg('Could not download metadata for %s' % plexid, -1) + return xbmcplugin.endOfDirectory(int(sys.argv[1])) - API = PlexAPI.API(xml[0]) - backdrops = API.getAllArtwork()['Backdrop'] - for count, backdrop in enumerate(backdrops): - # Same ordering as in artwork - if os.path.supports_unicode_filenames: - fanartFile = os.path.join(fanartDir, - "fanart%.3d.jpg" % count) - else: - fanartFile = os.path.join( - utils.tryEncode(fanartDir), - utils.tryEncode("fanart%.3d.jpg" % count)) - li = xbmcgui.ListItem("%.3d" % count, path=fanartFile) - xbmcplugin.addDirectoryItem( - handle=int(sys.argv[1]), - url=fanartFile, - listitem=li) - xbmcvfs.copy(backdrop, fanartFile) - else: - utils.logMsg(title, "Found cached backdrop.", 1) - # Use existing cached images - dirs, files = xbmcvfs.listdir(fanartDir) - for file in files: - fanartFile = os.path.join(fanartDir, utils.tryDecode(file)) - li = xbmcgui.ListItem(file, path=fanartFile) - xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), - url=fanartFile, - listitem=li) - - except Exception as e: - utils.logMsg(title, "Error getting extrafanart: %s" % e, -1) - import traceback - utils.logMsg("Traceback:\n%s" % traceback.format_exc(), 0) + API = PlexAPI.API(xml[0]) + backdrops = API.getAllArtwork()['Backdrop'] + for count, backdrop in enumerate(backdrops): + # Same ordering as in artwork + if os.path.supports_unicode_filenames: + fanartFile = os.path.join(fanartDir, + "fanart%.3d.jpg" % count) + else: + fanartFile = os.path.join( + utils.tryEncode(fanartDir), + utils.tryEncode("fanart%.3d.jpg" % count)) + li = xbmcgui.ListItem("%.3d" % count, path=fanartFile) + xbmcplugin.addDirectoryItem( + handle=int(sys.argv[1]), + url=fanartFile, + listitem=li) + xbmcvfs.copy(backdrop, fanartFile) + else: + utils.logMsg(title, "Found cached backdrop.", 1) + # Use existing cached images + dirs, files = xbmcvfs.listdir(fanartDir) + for file in files: + fanartFile = os.path.join(fanartDir, utils.tryDecode(file)) + li = xbmcgui.ListItem(file, path=fanartFile) + xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), + url=fanartFile, + listitem=li) xbmcplugin.endOfDirectory(int(sys.argv[1]))