Merge pull request #977 from croneter/fix-sync

Fix PKC background sync synching items to Kodi even though entire section should not be synched
This commit is contained in:
croneter 2019-09-08 15:25:00 +02:00 committed by GitHub
commit 58e26be021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 30 deletions

View file

@ -75,8 +75,24 @@ class Sync(object):
# Could we access the paths? # Could we access the paths?
self.path_verified = False self.path_verified = False
# List of Section() items representing Plex library sections
self._sections = []
# List of section_ids we're synching to Kodi - will be automatically
# re-built if sections are set a-new
self.section_ids = set()
self.load() self.load()
@property
def sections(self):
return self._sections
@sections.setter
def sections(self, sections):
self._sections = sections
# Sets are faster when using "in" test than lists
self.section_ids = set([x.section_id for x in sections if x.sync_to_kodi])
def load(self): def load(self):
self.direct_paths = utils.settings('useDirectPaths') == '1' self.direct_paths = utils.settings('useDirectPaths') == '1'
self.enable_music = utils.settings('enableMusic') == 'true' self.enable_music = utils.settings('enableMusic') == 'true'

View file

@ -6,7 +6,7 @@ from ntpath import dirname
from ..plex_db import PlexDB, PLEXDB_LOCK from ..plex_db import PlexDB, PLEXDB_LOCK
from ..kodi_db import KodiVideoDB, KODIDB_LOCK from ..kodi_db import KodiVideoDB, KODIDB_LOCK
from .. import utils, timing from .. import utils, timing, app
LOG = getLogger('PLEX.itemtypes.common') LOG = getLogger('PLEX.itemtypes.common')
@ -136,3 +136,12 @@ class ItemBase(object):
duration, duration,
view_count, view_count,
timing.plex_date_to_kodi(lastViewedAt)) timing.plex_date_to_kodi(lastViewedAt))
@staticmethod
def sync_this_item(section_id):
"""
Returns False if we are NOT synching the corresponding Plex library
with section_id [int] to Kodi or if this sections has not yet been
encountered by PKC
"""
return section_id in app.SYNC.section_ids

View file

@ -20,11 +20,12 @@ class Movie(ItemBase):
Process single movie Process single movie
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id if not self.sync_this_item(api.library_section_id()):
# Cannot parse XML, abort LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
if not plex_id: 'Kodi', api.plex_type, api.plex_id, api.title(),
LOG.error('Cannot parse XML data for movie: %s', xml.attrib) api.library_section_id())
return return
plex_id = api.plex_id
movie = self.plexdb.movie(plex_id) movie = self.plexdb.movie(plex_id)
if movie: if movie:
update_item = True update_item = True

View file

@ -159,10 +159,12 @@ class Artist(MusicMixin, ItemBase):
Process a single artist Process a single artist
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id if not self.sync_this_item(api.library_section_id()):
if not plex_id: LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
LOG.error('Cannot process artist %s', xml.attrib) 'Kodi', api.plex_type, api.plex_id, api.title(),
api.library_section_id())
return return
plex_id = api.plex_id
artist = self.plexdb.artist(plex_id) artist = self.plexdb.artist(plex_id)
if not artist: if not artist:
update_item = False update_item = False
@ -224,9 +226,6 @@ class Album(MusicMixin, ItemBase):
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id plex_id = api.plex_id
if not plex_id:
LOG.error('Error processing album: %s', xml.attrib)
return
album = self.plexdb.album(plex_id) album = self.plexdb.album(plex_id)
if album: if album:
update_item = True update_item = True
@ -389,9 +388,6 @@ class Song(MusicMixin, ItemBase):
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id plex_id = api.plex_id
if not plex_id:
LOG.error('Error processing song: %s', xml.attrib)
return
song = self.plexdb.song(plex_id) song = self.plexdb.song(plex_id)
if song: if song:
update_item = True update_item = True

View file

@ -148,10 +148,12 @@ class Show(TvShowMixin, ItemBase):
Process a single show Process a single show
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id if not self.sync_this_item(api.library_section_id()):
if not plex_id: LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
LOG.error("Cannot parse XML data for TV show: %s", xml.attrib) 'Kodi', api.plex_type, api.plex_id, api.title(),
api.library_section_id())
return return
plex_id = api.plex_id
show = self.plexdb.show(plex_id) show = self.plexdb.show(plex_id)
if not show: if not show:
update_item = False update_item = False
@ -286,11 +288,12 @@ class Season(TvShowMixin, ItemBase):
Process a single season of a certain tv show Process a single season of a certain tv show
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id if not self.sync_this_item(api.library_section_id()):
if not plex_id: LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
LOG.error('Error getting plex_id for season, skipping: %s', 'Kodi', api.plex_type, api.plex_id, api.title(),
xml.attrib) api.library_section_id())
return return
plex_id = api.plex_id
season = self.plexdb.season(plex_id) season = self.plexdb.season(plex_id)
if not season: if not season:
update_item = False update_item = False
@ -354,11 +357,12 @@ class Episode(TvShowMixin, ItemBase):
Process single episode Process single episode
""" """
api = API(xml) api = API(xml)
plex_id = api.plex_id if not self.sync_this_item(api.library_section_id()):
if not plex_id: LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
LOG.error('Error getting plex_id for episode, skipping: %s', 'Kodi', api.plex_type, api.plex_id, api.title(),
xml.attrib) api.library_section_id())
return return
plex_id = api.plex_id
episode = self.plexdb.episode(plex_id) episode = self.plexdb.episode(plex_id)
if not episode: if not episode:
update_item = False update_item = False

View file

@ -255,7 +255,7 @@ class FullSync(common.fullsync_mixin):
""" """
try: try:
for kind in kinds: for kind in kinds:
for section in (x for x in sections.SECTIONS for section in (x for x in app.SYNC.sections
if x.section_type == kind[1]): if x.section_type == kind[1]):
if self.isCanceled(): if self.isCanceled():
LOG.debug('Need to exit now') LOG.debug('Need to exit now')

View file

@ -15,7 +15,6 @@ from ..utils import etree
LOG = getLogger('PLEX.sync.sections') LOG = getLogger('PLEX.sync.sections')
BATCH_SIZE = 500 BATCH_SIZE = 500
SECTIONS = []
# Need a way to interrupt our synching process # Need a way to interrupt our synching process
IS_CANCELED = None IS_CANCELED = None
@ -590,11 +589,10 @@ def sync_from_pms(parent_self, pick_libraries=False):
return _sync_from_pms(pick_libraries) return _sync_from_pms(pick_libraries)
finally: finally:
IS_CANCELED = None IS_CANCELED = None
LOG.info('Done synching sections from the PMS: %s', SECTIONS) LOG.info('Done synching sections from the PMS: %s', app.SYNC.sections)
def _sync_from_pms(pick_libraries): def _sync_from_pms(pick_libraries):
global SECTIONS
# Re-set value in order to make sure we got the lastest user input # Re-set value in order to make sure we got the lastest user input
app.SYNC.enable_music = utils.settings('enableMusic') == 'true' app.SYNC.enable_music = utils.settings('enableMusic') == 'true'
xml = PF.get_plex_sections() xml = PF.get_plex_sections()
@ -649,7 +647,7 @@ def _sync_from_pms(pick_libraries):
# Counter that tells us how many sections we have - e.g. for skins and # Counter that tells us how many sections we have - e.g. for skins and
# listings # listings
utils.window('Plex.nodes.total', str(len(sections))) utils.window('Plex.nodes.total', str(len(sections)))
SECTIONS = sections app.SYNC.sections = sections
return True return True