Fixes to getExtraFanart. If not using PKC repository, you will have to manually update plugin.video.plexkodiconnect.movies and plugin.video.plexkodiconnect.tvshows. Fixes #62

This commit is contained in:
tomkat83 2016-06-19 16:42:44 +02:00
parent 133741b567
commit 70ade15e8d

View file

@ -1282,68 +1282,66 @@ def getVideoFiles(plexId, params):
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))
##### GET EXTRAFANART FOR LISTITEM ##### def getExtraFanArt(plexid, plexPath):
def getExtraFanArt(plexid,embyPath): """
Get extrafanart for listitem
emby = embyserver.Read_EmbyServer() will be called by skinhelper script to get the extrafanart
art = artwork.Artwork() for tvshows we get the plexid just from the path
"""
# Get extrafanart for listitem utils.logMsg(title, 'getExtraFanArt called with plexid: %s, plexPath: %s'
# will be called by skinhelper script to get the extrafanart % (plexid, plexPath), 1)
try: if not plexid:
# for tvshows we get the plexid just from the path if "plugin.video.plexkodiconnect" in plexPath:
if not plexid: plexid = plexPath.split("/")[-2]
if "plugin.video.emby" in embyPath: if not plexid:
plexid = embyPath.split("/")[-2] utils.logMsg(title, 'Could not get a plexid, aborting', -1)
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
if plexid:
#only proceed if we actually have a emby id
utils.logMsg("EMBY", "Requesting extrafanart for Id: %s" % plexid, 0)
# We need to store the images locally for this to work try:
# because of the caching system in xbmc # We need to store the images locally for this to work
fanartDir = utils.tryDecode(xbmc.translatePath( # because of the caching system in xbmc
"special://thumbnails/emby/%s/" % plexid)) fanartDir = utils.tryDecode(xbmc.translatePath(
"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(fanartDir) xbmcvfs.mkdirs(utils.tryEncode(fanartDir))
item = emby.getItem(plexid) xml = PlexFunctions.GetPlexMetadata(plexid)
if item: if xml is None:
backdrops = art.getAllArtwork(item)['Backdrop'] utils.logMsg('Could not download metadata for %s' % plexid, -1)
tags = item['BackdropImageTags'] return xbmcplugin.endOfDirectory(int(sys.argv[1]))
count = 0
for backdrop in backdrops: API = PlexAPI.API(xml[0])
# Same ordering as in artwork backdrops = API.getAllArtwork()['Backdrop']
tag = tags[count] for count, backdrop in enumerate(backdrops):
if os.path.supports_unicode_filenames: # Same ordering as in artwork
fanartFile = os.path.join(fanartDir, "fanart%s.jpg" % tag) if os.path.supports_unicode_filenames:
else: fanartFile = os.path.join(fanartDir,
fanartFile = os.path.join( "fanart%.3d.jpg" % count)
utils.tryEncode(fanartDir), else:
"fanart%s.jpg" % utils.tryEncode(tag)) fanartFile = os.path.join(
li = xbmcgui.ListItem(tag, path=fanartFile) utils.tryEncode(fanartDir),
xbmcplugin.addDirectoryItem( utils.tryEncode("fanart%.3d.jpg" % count))
handle=int(sys.argv[1]), li = xbmcgui.ListItem("%.3d" % count, path=fanartFile)
url=fanartFile, xbmcplugin.addDirectoryItem(
listitem=li) handle=int(sys.argv[1]),
xbmcvfs.copy(backdrop, fanartFile) url=fanartFile,
count += 1 listitem=li)
else: xbmcvfs.copy(backdrop, fanartFile)
utils.logMsg("EMBY", "Found cached backdrop.", 2) else:
# Use existing cached images utils.logMsg(title, "Found cached backdrop.", 1)
dirs, files = xbmcvfs.listdir(fanartDir) # Use existing cached images
for file in files: dirs, files = xbmcvfs.listdir(fanartDir)
fanartFile = os.path.join(fanartDir, utils.tryDecode(file)) for file in files:
li = xbmcgui.ListItem(file, path=fanartFile) fanartFile = os.path.join(fanartDir, utils.tryDecode(file))
xbmcplugin.addDirectoryItem( li = xbmcgui.ListItem(file, path=fanartFile)
handle=int(sys.argv[1]), xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=fanartFile, url=fanartFile,
listitem=li) listitem=li)
except Exception as e: except Exception as e:
utils.logMsg("EMBY", "Error getting extrafanart: %s" % e, 0) utils.logMsg(title, "Error getting extrafanart: %s" % e, -1)
import traceback
# Always do endofdirectory to prevent errors in the logs utils.logMsg("Traceback:\n%s" % traceback.format_exc(), 0)
xbmcplugin.endOfDirectory(int(sys.argv[1])) xbmcplugin.endOfDirectory(int(sys.argv[1]))