Artwork overhaul part 1
This commit is contained in:
parent
22ddd28f0b
commit
b4716ba511
4 changed files with 104 additions and 65 deletions
|
@ -44,6 +44,7 @@ from utils import window, settings, language as lang, try_decode, try_encode, \
|
||||||
unix_date_to_kodi, exists_dir, slugify, dialog, escape_html
|
unix_date_to_kodi, exists_dir, slugify, dialog, escape_html
|
||||||
import PlexFunctions as PF
|
import PlexFunctions as PF
|
||||||
import plexdb_functions as plexdb
|
import plexdb_functions as plexdb
|
||||||
|
import kodidb_functions as kodidb
|
||||||
import variables as v
|
import variables as v
|
||||||
import state
|
import state
|
||||||
|
|
||||||
|
@ -732,51 +733,66 @@ class API(object):
|
||||||
'subtitle': subtitlelanguages
|
'subtitle': subtitlelanguages
|
||||||
}
|
}
|
||||||
|
|
||||||
def _one_artwork(self, entry):
|
def _one_artwork(self, art_kind):
|
||||||
if entry not in self.item.attrib:
|
artwork = self.item.get(art_kind)
|
||||||
return ''
|
if artwork and not artwork.startswith('http'):
|
||||||
artwork = self.item.attrib[entry]
|
|
||||||
if artwork.startswith('http'):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
artwork = self.attach_plex_token_to_url(
|
artwork = self.attach_plex_token_to_url(
|
||||||
'%s/photo/:/transcode?width=4000&height=4000&'
|
'%s/photo/:/transcode?width=4000&height=4000&'
|
||||||
'minSize=1&upscale=0&url=%s' % (self.server, artwork))
|
'minSize=1&upscale=0&url=%s' % (self.server, artwork))
|
||||||
return artwork
|
return artwork
|
||||||
|
|
||||||
def artwork(self, parent_info=False):
|
def artwork(self, kodi_id=None, kodi_type=None):
|
||||||
"""
|
"""
|
||||||
Gets the URLs to the Plex artwork, or empty string if not found.
|
Gets the URLs to the Plex artwork. Dict keys will be missing if there
|
||||||
parent_info=True will check for parent's artwork if None is found
|
is no corresponding artwork.
|
||||||
|
Pass kodi_id and kodi_type to grab the artwork saved in the Kodi DB
|
||||||
|
(thus potentially more artwork, e.g. clearart, discart)
|
||||||
|
|
||||||
Output:
|
Output ('max' version)
|
||||||
{
|
{
|
||||||
'Primary'
|
'thumb'
|
||||||
'Art'
|
'poster'
|
||||||
'Banner'
|
'banner'
|
||||||
'Logo'
|
'clearart'
|
||||||
'Thumb'
|
'clearlogo'
|
||||||
'Disc'
|
'landscape'
|
||||||
'Backdrop' : LIST with the first entry xml key "art"
|
'icon'
|
||||||
|
'fanart'
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
allartworks = {
|
if kodi_id:
|
||||||
'Primary': self._one_artwork('thumb'),
|
# in Kodi database, potentially with additional e.g. clearart
|
||||||
'Art': "",
|
if self.plex_type() in v.PLEX_VIDEOTYPES:
|
||||||
'Banner': self._one_artwork('banner'),
|
with kodidb.GetKodiDB('video') as kodi_db:
|
||||||
'Logo': "",
|
return kodi_db.get_art(kodi_id, kodi_type)
|
||||||
'Thumb': self._one_artwork('grandparentThumb'),
|
else:
|
||||||
'Disc': "",
|
with kodidb.GetKodiDB('music') as kodi_db:
|
||||||
'Backdrop': [self._one_artwork('art')]
|
return kodi_db.get_art(kodi_id, kodi_type)
|
||||||
}
|
|
||||||
# Process parent items if the main item is missing artwork
|
# Grab artwork from Plex
|
||||||
if parent_info:
|
artworks = {}
|
||||||
# Process parent backdrops
|
for kodi_artwork, plex_artwork in v.KODI_TO_PLEX_ARTWORK.iteritems():
|
||||||
if not allartworks['Backdrop']:
|
art = self._one_artwork(plex_artwork)
|
||||||
allartworks['Backdrop'].append(self._one_artwork('parentArt'))
|
if art:
|
||||||
if not allartworks['Primary']:
|
artworks[kodi_artwork] = art
|
||||||
allartworks['Primary'] = self._one_artwork('parentThumb')
|
if self.plex_type() in (v.PLEX_TYPE_EPISODE,
|
||||||
return allartworks
|
v.PLEX_TYPE_SONG,
|
||||||
|
v.PLEX_TYPE_ALBUM):
|
||||||
|
# Process parent item's poster
|
||||||
|
art = self._one_artwork('grandparentThumb')
|
||||||
|
if art:
|
||||||
|
artworks['tvshow.poster'] = art
|
||||||
|
# Get parent item artwork if the main item is missing artwork
|
||||||
|
if 'fanart1' not in artworks:
|
||||||
|
art = self._one_artwork('parentArt')
|
||||||
|
if art:
|
||||||
|
artworks['fanart1'] = art
|
||||||
|
if 'poster' not in artworks:
|
||||||
|
art = self._one_artwork('parentThumb')
|
||||||
|
if art:
|
||||||
|
artworks['poster'] = art
|
||||||
|
LOG.debug('artworks: %s', artworks)
|
||||||
|
return artworks
|
||||||
|
|
||||||
def fanart_artwork(self, allartworks):
|
def fanart_artwork(self, allartworks):
|
||||||
"""
|
"""
|
||||||
|
@ -1339,7 +1355,9 @@ class API(object):
|
||||||
append_show_title,
|
append_show_title,
|
||||||
append_sxxexx)
|
append_sxxexx)
|
||||||
self.add_video_streams(listitem)
|
self.add_video_streams(listitem)
|
||||||
self.set_listitem_artwork(listitem)
|
artwork = self.artwork()
|
||||||
|
LOG.debug('artwork: %s', artwork)
|
||||||
|
listitem.setArt(artwork)
|
||||||
return listitem
|
return listitem
|
||||||
|
|
||||||
def _create_photo_listitem(self, listitem=None):
|
def _create_photo_listitem(self, listitem=None):
|
||||||
|
@ -1545,19 +1563,8 @@ class API(object):
|
||||||
"""
|
"""
|
||||||
Set all artwork to the listitem
|
Set all artwork to the listitem
|
||||||
"""
|
"""
|
||||||
allartwork = self.artwork(parent_info=True)
|
allartwork = self.artwork()
|
||||||
arttypes = {
|
listitem.setArt(self.artwork())
|
||||||
'poster': "Primary",
|
|
||||||
'tvshow.poster': "Thumb",
|
|
||||||
'clearart': "Primary",
|
|
||||||
'tvshow.clearart': "Primary",
|
|
||||||
'clearlogo': "Logo",
|
|
||||||
'tvshow.clearlogo': "Logo",
|
|
||||||
'discart': "Disc",
|
|
||||||
'fanart_image': "Backdrop",
|
|
||||||
'landscape': "Backdrop",
|
|
||||||
"banner": "Banner"
|
|
||||||
}
|
|
||||||
for arttype in arttypes:
|
for arttype in arttypes:
|
||||||
art = arttypes[arttype]
|
art = arttypes[arttype]
|
||||||
if art == "Backdrop":
|
if art == "Backdrop":
|
||||||
|
|
|
@ -1306,16 +1306,15 @@ class Music(Items):
|
||||||
bio = api.plot()
|
bio = api.plot()
|
||||||
|
|
||||||
# Associate artwork
|
# Associate artwork
|
||||||
artworks = api.artwork(parent_info=True)
|
artworks = api.artwork()
|
||||||
thumb = artworks['Primary']
|
if 'poster' in artworks:
|
||||||
backdrops = artworks['Backdrop'] # List
|
thumb = "<thumb>%s</thumb>" % artworks['poster']
|
||||||
|
|
||||||
if thumb:
|
|
||||||
thumb = "<thumb>%s</thumb>" % thumb
|
|
||||||
if backdrops:
|
|
||||||
fanart = "<fanart>%s</fanart>" % backdrops[0]
|
|
||||||
else:
|
else:
|
||||||
fanart = ""
|
thumb = None
|
||||||
|
if 'fanart1' in artworks:
|
||||||
|
fanart = "<fanart>%s</fanart>" % artworks['fanart1']
|
||||||
|
else:
|
||||||
|
fanart = None
|
||||||
|
|
||||||
# UPDATE THE ARTIST #####
|
# UPDATE THE ARTIST #####
|
||||||
if update_item:
|
if update_item:
|
||||||
|
@ -1412,10 +1411,11 @@ class Music(Items):
|
||||||
self.compilation = 1
|
self.compilation = 1
|
||||||
break
|
break
|
||||||
# Associate artwork
|
# Associate artwork
|
||||||
artworks = api.artwork(parent_info=True)
|
artworks = api.artwork()
|
||||||
thumb = artworks['Primary']
|
if 'poster' in artworks:
|
||||||
if thumb:
|
thumb = "<thumb>%s</thumb>" % artworks['poster']
|
||||||
thumb = "<thumb>%s</thumb>" % thumb
|
else:
|
||||||
|
thumb = None
|
||||||
|
|
||||||
# UPDATE THE ALBUM #####
|
# UPDATE THE ALBUM #####
|
||||||
if update_item:
|
if update_item:
|
||||||
|
@ -1847,9 +1847,7 @@ class Music(Items):
|
||||||
# Add genres
|
# Add genres
|
||||||
if genres:
|
if genres:
|
||||||
self.kodi_db.addMusicGenres(songid, genres, v.KODI_TYPE_SONG)
|
self.kodi_db.addMusicGenres(songid, genres, v.KODI_TYPE_SONG)
|
||||||
# Update artwork
|
artwork.addArtwork(api.artwork(), songid, v.KODI_TYPE_SONG, kodicursor)
|
||||||
allart = api.artwork(parent_info=True)
|
|
||||||
artwork.addArtwork(allart, songid, v.KODI_TYPE_SONG, kodicursor)
|
|
||||||
if item.get('parentKey') is None:
|
if item.get('parentKey') is None:
|
||||||
# Update album artwork
|
# Update album artwork
|
||||||
artwork.addArtwork(allart, albumid, v.KODI_TYPE_ALBUM, kodicursor)
|
artwork.addArtwork(allart, albumid, v.KODI_TYPE_ALBUM, kodicursor)
|
||||||
|
|
|
@ -461,6 +461,25 @@ class KodiDBMethods(object):
|
||||||
self.cursor)
|
self.cursor)
|
||||||
return actor_id
|
return actor_id
|
||||||
|
|
||||||
|
def get_art(self, kodi_id, kodi_type):
|
||||||
|
"""
|
||||||
|
Returns a dict of all available artwork with unicode urls/paths:
|
||||||
|
{
|
||||||
|
'thumb'
|
||||||
|
'poster'
|
||||||
|
'banner'
|
||||||
|
'fanart'
|
||||||
|
'clearart'
|
||||||
|
'clearlogo'
|
||||||
|
'landscape'
|
||||||
|
'icon'
|
||||||
|
}
|
||||||
|
Missing fanart will not appear in the dict.
|
||||||
|
"""
|
||||||
|
query = 'SELECT type, url FROM art WHERE media_id=? AND media_type=?'
|
||||||
|
self.cursor.execute(query, (kodi_id, kodi_type))
|
||||||
|
return dict(self.cursor.fetchall())
|
||||||
|
|
||||||
def existingArt(self, kodiId, mediaType, refresh=False):
|
def existingArt(self, kodiId, mediaType, refresh=False):
|
||||||
"""
|
"""
|
||||||
For kodiId, returns an artwork dict with already existing art from
|
For kodiId, returns an artwork dict with already existing art from
|
||||||
|
|
|
@ -180,6 +180,14 @@ KODI_VIDEOTYPES = (
|
||||||
KODI_TYPE_SET
|
KODI_TYPE_SET
|
||||||
)
|
)
|
||||||
|
|
||||||
|
PLEX_VIDEOTYPES = (
|
||||||
|
PLEX_TYPE_MOVIE,
|
||||||
|
PLEX_TYPE_CLIP,
|
||||||
|
PLEX_TYPE_EPISODE,
|
||||||
|
PLEX_TYPE_SEASON,
|
||||||
|
PLEX_TYPE_SHOW
|
||||||
|
)
|
||||||
|
|
||||||
KODI_AUDIOTYPES = (
|
KODI_AUDIOTYPES = (
|
||||||
KODI_TYPE_SONG,
|
KODI_TYPE_SONG,
|
||||||
KODI_TYPE_ALBUM,
|
KODI_TYPE_ALBUM,
|
||||||
|
@ -310,6 +318,13 @@ PLEX_TYPE_FROM_WEBSOCKET = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KODI_TO_PLEX_ARTWORK = {
|
||||||
|
'poster': 'thumb',
|
||||||
|
'banner': 'banner',
|
||||||
|
'fanart1': 'art'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# extensions from:
|
# extensions from:
|
||||||
# http://kodi.wiki/view/Features_and_supported_codecs#Format_support (RAW image
|
# http://kodi.wiki/view/Features_and_supported_codecs#Format_support (RAW image
|
||||||
# formats, BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX and Targa/TGA)
|
# formats, BMP, JPEG, GIF, PNG, TIFF, MNG, ICO, PCX and Targa/TGA)
|
||||||
|
|
Loading…
Reference in a new issue