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:
# for tvshows we get the plexid just from the path
if not plexid: if not plexid:
if "plugin.video.emby" in embyPath: if "plugin.video.plexkodiconnect" in plexPath:
plexid = embyPath.split("/")[-2] plexid = plexPath.split("/")[-2]
if not plexid:
if plexid: utils.logMsg(title, 'Could not get a plexid, aborting', -1)
#only proceed if we actually have a emby id return xbmcplugin.endOfDirectory(int(sys.argv[1]))
utils.logMsg("EMBY", "Requesting extrafanart for Id: %s" % plexid, 0)
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/emby/%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(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])
backdrops = API.getAllArtwork()['Backdrop']
for count, backdrop in enumerate(backdrops):
# Same ordering as in artwork # Same ordering as in artwork
tag = tags[count]
if os.path.supports_unicode_filenames: if os.path.supports_unicode_filenames:
fanartFile = os.path.join(fanartDir, "fanart%s.jpg" % tag) fanartFile = os.path.join(fanartDir,
"fanart%.3d.jpg" % count)
else: else:
fanartFile = os.path.join( fanartFile = os.path.join(
utils.tryEncode(fanartDir), utils.tryEncode(fanartDir),
"fanart%s.jpg" % utils.tryEncode(tag)) utils.tryEncode("fanart%.3d.jpg" % count))
li = xbmcgui.ListItem(tag, 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)
count += 1
else: else:
utils.logMsg("EMBY", "Found cached backdrop.", 2) 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( xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
handle=int(sys.argv[1]),
url=fanartFile, url=fanartFile,
listitem=li) listitem=li)
except Exception as e:
utils.logMsg("EMBY", "Error getting extrafanart: %s" % e, 0)
# Always do endofdirectory to prevent errors in the logs 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]))