Reduce boilerplate

This commit is contained in:
tomkat83 2016-07-22 16:55:57 +02:00
parent bc7be04fc2
commit 3407d47f9c

View file

@ -1299,6 +1299,7 @@ def getVideoFiles(plexId, params):
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))
@utils.CatchExceptions(warnuser=False)
def getExtraFanArt(plexid, plexPath): def getExtraFanArt(plexid, plexPath):
""" """
Get extrafanart for listitem Get extrafanart for listitem
@ -1314,51 +1315,45 @@ def getExtraFanArt(plexid, plexPath):
utils.logMsg(title, 'Could not get a plexid, aborting', -1) utils.logMsg(title, 'Could not get a plexid, aborting', -1)
return xbmcplugin.endOfDirectory(int(sys.argv[1])) return xbmcplugin.endOfDirectory(int(sys.argv[1]))
try: # We need to store the images locally for this to work
# We need to store the images locally for this to work # because of the caching system in xbmc
# because of the caching system in xbmc fanartDir = utils.tryDecode(xbmc.translatePath(
fanartDir = utils.tryDecode(xbmc.translatePath( "special://thumbnails/plex/%s/" % plexid))
"special://thumbnails/plex/%s/" % plexid)) if not xbmcvfs.exists(fanartDir):
if not xbmcvfs.exists(fanartDir): # Download the images to the cache directory
# Download the images to the cache directory xbmcvfs.mkdirs(utils.tryEncode(fanartDir))
xbmcvfs.mkdirs(utils.tryEncode(fanartDir)) xml = PlexFunctions.GetPlexMetadata(plexid)
xml = PlexFunctions.GetPlexMetadata(plexid) if xml is None:
if xml is None: utils.logMsg('Could not download metadata for %s' % plexid, -1)
utils.logMsg('Could not download metadata for %s' % plexid, -1) return xbmcplugin.endOfDirectory(int(sys.argv[1]))
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
API = PlexAPI.API(xml[0]) API = PlexAPI.API(xml[0])
backdrops = API.getAllArtwork()['Backdrop'] backdrops = API.getAllArtwork()['Backdrop']
for count, backdrop in enumerate(backdrops): for count, backdrop in enumerate(backdrops):
# Same ordering as in artwork # Same ordering as in artwork
if os.path.supports_unicode_filenames: if os.path.supports_unicode_filenames:
fanartFile = os.path.join(fanartDir, fanartFile = os.path.join(fanartDir,
"fanart%.3d.jpg" % count) "fanart%.3d.jpg" % count)
else: else:
fanartFile = os.path.join( fanartFile = os.path.join(
utils.tryEncode(fanartDir), utils.tryEncode(fanartDir),
utils.tryEncode("fanart%.3d.jpg" % count)) utils.tryEncode("fanart%.3d.jpg" % count))
li = xbmcgui.ListItem("%.3d" % count, path=fanartFile) li = xbmcgui.ListItem("%.3d" % count, path=fanartFile)
xbmcplugin.addDirectoryItem( xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]), handle=int(sys.argv[1]),
url=fanartFile, url=fanartFile,
listitem=li) listitem=li)
xbmcvfs.copy(backdrop, fanartFile) xbmcvfs.copy(backdrop, fanartFile)
else: else:
utils.logMsg(title, "Found cached backdrop.", 1) utils.logMsg(title, "Found cached backdrop.", 1)
# Use existing cached images # Use existing cached images
dirs, files = xbmcvfs.listdir(fanartDir) dirs, files = xbmcvfs.listdir(fanartDir)
for file in files: for file in files:
fanartFile = os.path.join(fanartDir, utils.tryDecode(file)) fanartFile = os.path.join(fanartDir, utils.tryDecode(file))
li = xbmcgui.ListItem(file, path=fanartFile) li = xbmcgui.ListItem(file, path=fanartFile)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=fanartFile, url=fanartFile,
listitem=li) 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)
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))