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()
self.artconn = utils.kodi_sql('texture')
self.artcursor = self.artconn.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,13 +82,15 @@ 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()
self.artconn.close()
if self.artconn:
self.artconn.close()
if self.lock:
PLEXDB_LOCK.release()
KODIDB_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,9 +110,10 @@ class Movie(ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
else:
LOG.info("ADD movie plex_id: %s - %s", plex_id, title)
file_id = self.kodidb.add_file(filename,
@ -137,9 +138,10 @@ class Movie(ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_MOVIE)
# Update Kodi's main entry
self.kodidb.add_movie(kodi_id,
@ -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,8 +24,9 @@ class MusicMixin(object):
self.plexcursor = self.plexconn.cursor()
self.kodiconn = utils.kodi_sql('music')
self.kodicursor = self.kodiconn.cursor()
self.artconn = utils.kodi_sql('texture')
self.artcursor = self.artconn.cursor()
if app.SYNC.artwork:
self.artconn = utils.kodi_sql('texture')
self.artcursor = self.artconn.cursor()
self.plexdb = PlexDB(self.plexcursor)
self.kodidb = KodiMusicDB(texture_db=True,
cursor=self.kodicursor,
@ -170,16 +171,18 @@ class Artist(MusicMixin, ItemBase):
# Not yet implemented by Plex
musicBrainzId = None
# Associate artwork
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
if app.SYNC.artwork:
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
else:
thumb = None
if 'fanart' in artworks:
fanart = "<fanart>%s</fanart>" % artworks['fanart']
else:
fanart = None
else:
thumb = None
if 'fanart' in artworks:
fanart = "<fanart>%s</fanart>" % artworks['fanart']
else:
fanart = None
thumb, fanart = None, None
# UPDATE THE ARTIST #####
if update_item:
@ -198,10 +201,10 @@ class Artist(MusicMixin, ItemBase):
fanart,
timing.unix_date_to_kodi(self.last_sync),
kodi_id)
# Update artwork
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ARTIST)
if app.SYNC.artwork:
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ARTIST)
self.plexdb.add_artist(plex_id,
api.checksum(),
section_id,
@ -265,10 +268,12 @@ class Album(MusicMixin, ItemBase):
musicBrainzId = None
genres = api.genre_list()
genre = api.list_to_string(genres)
# Associate artwork
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
if app.SYNC.artwork:
artworks = api.artwork()
if 'poster' in artworks:
thumb = "<thumb>%s</thumb>" % artworks['poster']
else:
thumb = None
else:
thumb = None
@ -341,9 +346,10 @@ class Album(MusicMixin, ItemBase):
self.kodidb.add_music_genres(kodi_id,
genres,
v.KODI_TYPE_ALBUM)
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ALBUM)
if app.SYNC.artwork:
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_ALBUM)
self.plexdb.add_album(plex_id,
api.checksum(),
section_id,
@ -630,15 +636,16 @@ class Song(MusicMixin, ItemBase):
# Add genres
if genres:
self.kodidb.add_music_genres(kodi_id, genres, v.KODI_TYPE_SONG)
artworks = api.artwork()
self.kodidb.modify_artwork(artworks,
kodi_id,
v.KODI_TYPE_SONG)
if xml.get('parentKey') is None:
# Update album artwork
if app.SYNC.artwork:
artworks = api.artwork()
self.kodidb.modify_artwork(artworks,
parent_id,
v.KODI_TYPE_ALBUM)
kodi_id,
v.KODI_TYPE_SONG)
if xml.get('parentKey') is None:
# Update album artwork
self.kodidb.modify_artwork(artworks,
parent_id,
v.KODI_TYPE_ALBUM)
self.plexdb.add_song(plex_id,
api.checksum(),
section_id,

View file

@ -204,9 +204,10 @@ class Show(TvShowMixin, ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
# Update the tvshow entry
self.kodidb.update_show(api.title(),
api.plot(),
@ -243,9 +244,10 @@ class Show(TvShowMixin, ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_SHOW)
# Create the tvshow entry
self.kodidb.add_show(kodi_id,
api.title(),
@ -310,25 +312,28 @@ class Season(TvShowMixin, ItemBase):
LOG.error('Still could not find parent tv show %s', show_id)
return
parent_id = show['kodi_id']
parent_artwork = api.artwork(kodi_id=parent_id,
kodi_type=v.KODI_TYPE_SHOW)
artwork = api.artwork()
# Remove all artwork that is identical for the season's show
for key in parent_artwork:
if key in artwork and artwork[key] == parent_artwork[key]:
del artwork[key]
if app.SYNC.artwork:
parent_artwork = api.artwork(kodi_id=parent_id,
kodi_type=v.KODI_TYPE_SHOW)
artwork = api.artwork()
# Remove all artwork that is identical for the season's show
for key in parent_artwork:
if key in artwork and artwork[key] == parent_artwork[key]:
del artwork[key]
if update_item:
LOG.info('UPDATE season plex_id %s - %s', plex_id, api.title())
kodi_id = season['kodi_id']
self.kodidb.modify_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
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())
self.kodidb.add_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
if app.SYNC.artwork:
self.kodidb.add_artwork(artwork,
kodi_id,
v.KODI_TYPE_SEASON)
self.plexdb.add_season(plex_id=plex_id,
checksum=api.checksum(),
section_id=section_id,
@ -475,9 +480,10 @@ class Episode(TvShowMixin, ItemBase):
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)
if app.SYNC.artwork:
self.kodidb.modify_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)
self.kodidb.update_episode(api.title(),
api.plot(),
ratingid,
@ -537,9 +543,10 @@ class Episode(TvShowMixin, ItemBase):
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)
if app.SYNC.artwork:
self.kodidb.add_artwork(api.artwork(),
kodi_id,
v.KODI_TYPE_EPISODE)
self.kodidb.add_episode(kodi_id,
kodi_fileid,
api.title(),

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,81 +145,159 @@ class KodiMusicDB(common.KodiDBBase):
"""
strReleaseType: 'album' or 'single'
"""
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtists,
strGenres,
iYear,
bCompilation,
strReview,
strImage,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
if app.SYNC.artwork:
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtists,
strGenres,
iYear,
bCompilation,
strReview,
strImage,
strLabel,
iUserrating,
lastScraped,
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):
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtists = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strImage = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtists = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strImage = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
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'
"""
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtistDisp,
strGenres,
iYear,
bCompilation,
strReview,
strImage,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
if app.SYNC.artwork:
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtistDisp,
strGenres,
iYear,
bCompilation,
strReview,
strImage,
strLabel,
iUserrating,
lastScraped,
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):
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtistDisp = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strImage = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtistDisp = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strImage = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
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,15 +502,26 @@ class KodiMusicDB(common.KodiDBBase):
return artistid
def update_artist(self, *args):
self.cursor.execute('''
UPDATE artist
SET strGenres = ?,
strBiography = ?,
strImage = ?,
strFanart = ?,
lastScraped = ?
WHERE idArtist = ?
''', (args))
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE artist
SET strGenres = ?,
strBiography = ?,
strImage = ?,
strFanart = ?,
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">