Moving getallartworks to PlexAPI

This commit is contained in:
tomkat83 2015-12-30 15:57:55 +01:00
parent 76c9b21dfb
commit 1e7acfc927
3 changed files with 125 additions and 21 deletions

View file

@ -603,12 +603,12 @@ class PlexAPI():
"""
# Get addon infos
xargs = dict()
xargs['User-agent'] = 'PlexKodiConnect'
xargs['User-agent'] = self.addonName
xargs['X-Plex-Device'] = self.deviceName
# xargs['X-Plex-Model'] = ''
xargs['X-Plex-Platform'] = self.platform
xargs['X-Plex-Client-Platform'] = self.platform
xargs['X-Plex-Product'] = 'PlexKodiConnect'
xargs['X-Plex-Product'] = self.addonName
xargs['X-Plex-Version'] = self.plexversion
xargs['X-Plex-Client-Identifier'] = self.clientId
if options:
@ -1720,3 +1720,99 @@ class API():
'audio': audiotracks,
'subtitle': subtitlelanguages
}
def getAllArtwork(self, item, parentInfo=False):
server = self.server
id = item['key']
maxHeight = 10000
maxWidth = 10000
customquery = ""
if utils.settings('compressArt') == "true":
customquery = "&Quality=90"
if utils.settings('enableCoverArt') == "false":
customquery += "&EnableImageEnhancers=false"
allartworks = {
'Primary': "",
'Art': "",
'Banner': "",
'Logo': "",
'Thumb': "",
'Disc': "",
'Backdrop': []
}
# Process backdrops
# Get background artwork URL
try:
background = item['art']
background = "%s%s" % (server, background)
except KeyError:
background = ""
allartworks['Backdrop'].append(background)
# Get primary "thumb" pictures:
try:
primary = item['thumb']
primary = "%s%s" % (server, primary)
except KeyError:
primary = ""
allartworks['Primary'] = primary
# Process parent items if the main item is missing artwork
if parentInfo:
# Process parent backdrops
if not allartworks['Backdrop']:
parentId = item.get('ParentBackdropItemId')
if parentId:
# If there is a parentId, go through the parent backdrop list
parentbackdrops = item['ParentBackdropImageTags']
backdropIndex = 0
for parentbackdroptag in parentbackdrops:
artwork = (
"%s/emby/Items/%s/Images/Backdrop/%s?"
"MaxWidth=%s&MaxHeight=%s&Format=original&Tag=%s%s"
% (server, parentId, backdropIndex,
maxWidth, maxHeight, parentbackdroptag, customquery))
allartworks['Backdrop'].append(artwork)
backdropIndex += 1
# Process the rest of the artwork
parentartwork = ['Logo', 'Art', 'Thumb']
for parentart in parentartwork:
if not allartworks[parentart]:
parentId = item.get('Parent%sItemId' % parentart)
if parentId:
parentTag = item['Parent%sImageTag' % parentart]
artwork = (
"%s/emby/Items/%s/Images/%s/0?"
"MaxWidth=%s&MaxHeight=%s&Format=original&Tag=%s%s"
% (server, parentId, parentart,
maxWidth, maxHeight, parentTag, customquery))
allartworks[parentart] = artwork
# Parent album works a bit differently
if not allartworks['Primary']:
parentId = item.get('AlbumId')
if parentId and item.get('AlbumPrimaryImageTag'):
parentTag = item['AlbumPrimaryImageTag']
artwork = (
"%s/emby/Items/%s/Images/Primary/0?"
"MaxWidth=%s&MaxHeight=%s&Format=original&Tag=%s%s"
% (server, parentId, maxWidth, maxHeight, parentTag, customquery))
allartworks['Primary'] = artwork
return allartworks

View file

@ -215,8 +215,7 @@ class Artwork():
timeout=(0.01, 0.01))
# We don't need the result
except: pass
def addArtwork(self, artwork, kodiId, mediaType, cursor):
# Kodi conversion table
kodiart = {
@ -424,11 +423,13 @@ class Artwork():
% (self.server, itemid, itemtype))
return image
def getAllArtwork(self, item, parentInfo=False):
def getAllArtwork(self, item, parentInfo=False):
server = self.server
id = item['key']
id = item['Id']
artworks = item['ImageTags']
backdrops = item['BackdropImageTags']
maxHeight = 10000
maxWidth = 10000
@ -452,20 +453,26 @@ class Artwork():
}
# Process backdrops
# Get background artwork URL
try:
background = item['art']
background = "%s%s" % (server, background)
except KeyError:
background = ""
allartworks['Backdrop'].append(background)
# Get primary "thumb" pictures:
try:
primary = item['thumb']
primary = "%s%s" % (server, primary)
except KeyError:
primary = ""
allartworks['Primary'] = primary
backdropIndex = 0
for backdroptag in backdrops:
artwork = (
"%s/emby/Items/%s/Images/Backdrop/%s?"
"MaxWidth=%s&MaxHeight=%s&Format=original&Tag=%s%s"
% (server, id, backdropIndex,
maxWidth, maxHeight, backdroptag, customquery))
allartworks['Backdrop'].append(artwork)
backdropIndex += 1
# Process the rest of the artwork
for art in artworks:
# Filter backcover
if art != "BoxRear":
tag = artworks[art]
artwork = (
"%s/emby/Items/%s/Images/%s/0?"
"MaxWidth=%s&MaxHeight=%s&Format=original&Tag=%s%s"
% (server, id, art, maxWidth, maxHeight, tag, customquery))
allartworks[art] = artwork
# Process parent items if the main item is missing artwork
if parentInfo:

View file

@ -444,7 +444,8 @@ class Movies(Items):
# Process genres
kodi_db.addGenres(movieid, genres, "movie")
# Process artwork
artwork.addArtwork(artwork.getAllArtwork(item), movieid, "movie", kodicursor)
allartworks = API.getAllArtwork()
artwork.addArtwork(allartworks, movieid, "movie", kodicursor)
# Process stream details
streams = API.getMediaStreams()
kodi_db.addStreams(fileid, streams, runtime)