New option to not use Plex artwork

This commit is contained in:
croneter 2019-01-04 20:38:45 +01:00
parent 3d4ba1e165
commit 262a2dda21
10 changed files with 285 additions and 155 deletions

View file

@ -429,6 +429,11 @@ msgctxt "#30501"
msgid "Client SSL certificate"
msgstr ""
# PKC Settings - Artwork
msgctxt "#30502"
msgid "Sync Plex artwork from the PMS (recommended)"
msgstr ""
# PKC Settings - Connection
msgctxt "#30505"
msgid "[COLOR yellow]Reset login attempts[/COLOR]"

View file

@ -38,6 +38,8 @@ class Sync(object):
self.direct_paths = utils.settings('useDirectPaths') == '1'
# Is synching of Plex music enabled?
self.enable_music = utils.settings('enableMusic') == 'true'
# Do we sync artwork from the PMS to Kodi?
self.artwork = utils.settings('usePlexArtwork') == 'true'
# Path remapping mechanism (e.g. smb paths)
# Do we replace \\myserver\path to smb://myserver/path?
self.replace_smb_path = utils.settings('replaceSMB') == 'true'

View file

@ -6,7 +6,7 @@ from ntpath import dirname
from ..plex_db import PlexDB, PLEXDB_LOCK
from ..kodi_db import KodiVideoDB, KODIDB_LOCK
from .. import utils, timing
from .. import utils, timing, app
LOG = getLogger('PLEX.itemtypes.common')
@ -61,8 +61,12 @@ class ItemBase(object):
self.plexcursor = self.plexconn.cursor()
self.kodiconn = utils.kodi_sql('video')
self.kodicursor = self.kodiconn.cursor()
if app.SYNC.artwork:
self.artconn = utils.kodi_sql('texture')
self.artcursor = self.artconn.cursor()
else:
self.artconn = None
self.artcursor = None
self.plexdb = PlexDB(cursor=self.plexcursor)
self.kodidb = KodiVideoDB(texture_db=True,
cursor=self.kodicursor,
@ -78,12 +82,14 @@ class ItemBase(object):
# re-raise any exception
return False
self.plexconn.commit()
self.artconn.commit()
self.kodiconn.commit()
if self.artconn:
self.artconn.commit()
return self
finally:
self.plexconn.close()
self.kodiconn.close()
if self.artconn:
self.artconn.close()
if self.lock:
PLEXDB_LOCK.release()
@ -92,10 +98,11 @@ class ItemBase(object):
def commit(self):
self.plexconn.commit()
self.plexconn.execute('BEGIN')
self.artconn.commit()
self.artconn.execute('BEGIN')
self.kodiconn.commit()
self.kodiconn.execute('BEGIN')
if self.artconn:
self.artconn.commit()
self.artconn.execute('BEGIN')
def set_fanart(self, artworks, kodi_id, kodi_type):
"""

View file

@ -110,6 +110,7 @@ class Movie(ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
@ -137,6 +138,7 @@ class Movie(ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
@ -179,6 +181,9 @@ class Movie(ItemBase):
# Add any sets from Plex collection tags
kodi_set_id = self.kodidb.create_collection(set_name)
self.kodidb.assign_collection(kodi_set_id, kodi_id)
if not app.SYNC.artwork:
# Rest below is to get collection artwork
continue
if children is None:
# e.g. when added via websocket
LOG.debug('Costly looking up Plex collection %s: %s',

View file

@ -24,6 +24,7 @@ class MusicMixin(object):
self.plexcursor = self.plexconn.cursor()
self.kodiconn = utils.kodi_sql('music')
self.kodicursor = self.kodiconn.cursor()
if app.SYNC.artwork:
self.artconn = utils.kodi_sql('texture')
self.artcursor = self.artconn.cursor()
self.plexdb = PlexDB(self.plexcursor)
@ -170,7 +171,7 @@ class Artist(MusicMixin, ItemBase):
# Not yet implemented by Plex
musicBrainzId = None
# Associate artwork
if app.SYNC.artwork:
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
@ -180,6 +181,8 @@ class Artist(MusicMixin, ItemBase):
fanart = "<fanart>%s</fanart>" % artworks['fanart']
else:
fanart = None
else:
thumb, fanart = None, None
# UPDATE THE ARTIST #####
if update_item:
@ -198,7 +201,7 @@ class Artist(MusicMixin, ItemBase):
fanart,
timing.unix_date_to_kodi(self.last_sync),
kodi_id)
# Update artwork
if app.SYNC.artwork:
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ARTIST)
@ -265,12 +268,14 @@ class Album(MusicMixin, ItemBase):
musicBrainzId = None
genres = api.genre_list()
genre = api.list_to_string(genres)
# Associate artwork
if app.SYNC.artwork:
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
else:
thumb = None
else:
thumb = None
# UPDATE THE ALBUM #####
if update_item:
@ -341,6 +346,7 @@ class Album(MusicMixin, ItemBase):
self.kodidb.add_music_genres(kodi_id,
genres,
v.KODI_TYPE_ALBUM)
if app.SYNC.artwork:
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ALBUM)
@ -630,6 +636,7 @@ class Song(MusicMixin, ItemBase):
# Add genres
if genres:
self.kodidb.add_music_genres(kodi_id, genres, v.KODI_TYPE_SONG)
if app.SYNC.artwork:
artworks = api.artwork()
self.kodidb.modify_artwork(artworks,
kodi_id,

View file

@ -204,6 +204,7 @@ class Show(TvShowMixin, ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
@ -243,6 +244,7 @@ class Show(TvShowMixin, ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
@ -310,6 +312,7 @@ class Season(TvShowMixin, ItemBase):
LOG.error('Still could not find parent tv show %s', show_id)
return
parent_id = show['kodi_id']
if app.SYNC.artwork:
parent_artwork = api.artwork(kodi_id=parent_id,
kodi_type=v.KODI_TYPE_SHOW)
artwork = api.artwork()
@ -320,12 +323,14 @@ class Season(TvShowMixin, ItemBase):
if update_item:
LOG.info('UPDATE season plex_id %s - %s', plex_id, api.title())
kodi_id = season['kodi_id']
if app.SYNC.artwork:
self.kodidb.modify_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
else:
LOG.info('ADD season plex_id %s - %s', plex_id, api.title())
kodi_id = self.kodidb.add_season(parent_id, api.season_number())
if app.SYNC.artwork:
self.kodidb.add_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
@ -475,6 +480,7 @@ class Episode(TvShowMixin, ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)
@ -537,6 +543,7 @@ class Episode(TvShowMixin, ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)

View file

@ -4,7 +4,7 @@ from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
from . import common
from .. import variables as v
from .. import variables as v, app
LOG = getLogger('PLEX.kodi_db.music')
@ -145,6 +145,7 @@ class KodiMusicDB(common.KodiDBBase):
"""
strReleaseType: 'album' or 'single'
"""
if app.SYNC.artwork:
self.cursor.execute('''
INSERT INTO album(
idAlbum,
@ -162,8 +163,28 @@ class KodiMusicDB(common.KodiDBBase):
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
else:
args = list(args)
del args[8]
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtists,
strGenres,
iYear,
bCompilation,
strReview,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
def update_album_17(self, *args):
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
@ -180,11 +201,30 @@ class KodiMusicDB(common.KodiDBBase):
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
else:
args = list(args)
del args[7]
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtists = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
def add_album(self, *args):
"""
strReleaseType: 'album' or 'single'
"""
if app.SYNC.artwork:
self.cursor.execute('''
INSERT INTO album(
idAlbum,
@ -202,8 +242,28 @@ class KodiMusicDB(common.KodiDBBase):
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
else:
args = list(args)
del args[8]
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtistDisp,
strGenres,
iYear,
bCompilation,
strReview,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
def update_album(self, *args):
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
@ -220,6 +280,24 @@ class KodiMusicDB(common.KodiDBBase):
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
else:
args = list(args)
del args[7]
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtistDisp = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
def add_albumartist(self, artist_id, kodi_id, artistname):
self.cursor.execute('''
@ -424,6 +502,7 @@ class KodiMusicDB(common.KodiDBBase):
return artistid
def update_artist(self, *args):
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE artist
SET strGenres = ?,
@ -433,6 +512,16 @@ class KodiMusicDB(common.KodiDBBase):
lastScraped = ?
WHERE idArtist = ?
''', (args))
else:
args = list(args)
del args[3], args[2]
self.cursor.execute('''
UPDATE artist
SET strGenres = ?,
strBiography = ?,
lastScraped = ?
WHERE idArtist = ?
''', (args))
def remove_song(self, kodi_id):
self.cursor.execute('DELETE FROM song WHERE idSong = ?', (kodi_id, ))

View file

@ -13,7 +13,8 @@ from .. import itemtypes, plex_functions as PF, variables as v, app
LOG = getLogger('PLEX.sync.fanart')
SUPPORTED_TYPES = (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW)
SYNC_FANART = utils.settings('FanartTV') == 'true'
SYNC_FANART = (utils.settings('FanartTV') == 'true' and
utils.settings('usePlexArtwork') == 'true')
PREFER_KODI_COLLECTION_ART = utils.settings('PreferKodiCollectionArt') == 'false'
BATCH_SIZE = 500

View file

@ -136,6 +136,9 @@ class Sync(backgroundthread.KillableThread):
if not utils.settings('FanartTV') == 'true':
LOG.info('Additional fanart download is deactivated')
return False
if not app.SYNC.artwork:
LOG.info('Not synching Plex PMS artwork, not getting artwork')
return False
elif self.fanart is None or not self.fanart.is_alive():
LOG.info('Start downloading additional fanart with refresh %s',
refresh)
@ -156,6 +159,9 @@ class Sync(backgroundthread.KillableThread):
if not utils.settings('enableTextureCache') == "true":
LOG.info('Image caching has been deactivated')
return
if not app.SYNC.artwork:
LOG.info('Not synching Plex artwork - not caching')
return
if self.image_cache_thread and self.image_cache_thread.is_alive():
self.image_cache_thread.cancel()
self.image_cache_thread.join()

View file

@ -132,16 +132,17 @@
</category>
<category label="30544"><!-- artwork -->
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Cache all artwork for a smooth Kodi experience -->
<setting id="FanartTV" label="30539" type="bool" default="false" /><!-- Download additional art from FanArtTV -->
<setting id="PreferKodiCollectionArt" label="30543" type="bool" default="true" visible="eq(-1,true)" subsetting="true" /><!-- Prefer Kodi artwork for collections -->
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-2,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
<setting id="imageSyncNotifications" label="30008" type="bool" default="true" /><!-- Enable notifications for image caching -->
<setting id="imageSyncDuringPlayback" label="30009" type="bool" default="true" /><!-- Enable image caching during Kodi playback (restart Kodi!) -->
<setting label="39020" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=texturecache)" option="close" /> <!-- Cache all images to Kodi texture cache now -->
<setting type="lsep" label="$LOCALIZE[126]" /><!-- Status -->
<setting id="plex_status_fanarttv_lookup" label="30019" type="text" default="" enable="false" /><!-- FanartTV lookup completed -->
<setting id="plex_status_image_caching" label="30028" type="text" default="" enable="false" /><!-- Image caching completed -->
<setting id="usePlexArtwork" label="30502" type="bool" default="true" /> <!-- Sync Plex artwork from the PMS -->
<setting id="enableTextureCache" label="30512" type="bool" default="true" visible="eq(-1,true)"/> <!-- Cache all artwork for a smooth Kodi experience -->
<setting id="FanartTV" label="30539" type="bool" default="false" visible="eq(-2,true)"/><!-- Download additional art from FanArtTV -->
<setting id="PreferKodiCollectionArt" label="30543" type="bool" default="true" visible="eq(-1,true) + eq(-3,true)" subsetting="true" /><!-- Prefer Kodi artwork for collections -->
<setting label="39222" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=fanart)" option="close" visible="eq(-2,true) + eq(-4,true)" subsetting="true" /> <!-- Look for missing fanart on FanartTV now -->
<setting id="imageSyncNotifications" label="30008" type="bool" default="true" visible="eq(-5,true)"/><!-- Enable notifications for image caching -->
<setting id="imageSyncDuringPlayback" label="30009" type="bool" default="true" visible="eq(-6,true)"/><!-- Enable image caching during Kodi playback (restart Kodi!) -->
<setting label="39020" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect/?mode=texturecache)" option="close" visible="eq(-7,true)"/> <!-- Cache all images to Kodi texture cache now -->
<setting type="lsep" label="$LOCALIZE[126]" visible="eq(-8,true)"/><!-- Status -->
<setting id="plex_status_fanarttv_lookup" label="30019" type="text" default="" enable="false" visible="eq(-9,true)"/><!-- FanartTV lookup completed -->
<setting id="plex_status_image_caching" label="30028" type="text" default="" enable="false" visible="eq(-10,true)"/><!-- Image caching completed -->
</category>
<!--
<category label="30235" visible="false">