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:
commit
58e26be021
7 changed files with 54 additions and 30 deletions
|
@ -75,8 +75,24 @@ class Sync(object):
|
|||
# Could we access the paths?
|
||||
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()
|
||||
|
||||
@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):
|
||||
self.direct_paths = utils.settings('useDirectPaths') == '1'
|
||||
self.enable_music = utils.settings('enableMusic') == 'true'
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
@ -136,3 +136,12 @@ class ItemBase(object):
|
|||
duration,
|
||||
view_count,
|
||||
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
|
||||
|
|
|
@ -20,11 +20,12 @@ class Movie(ItemBase):
|
|||
Process single movie
|
||||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
# Cannot parse XML, abort
|
||||
if not plex_id:
|
||||
LOG.error('Cannot parse XML data for movie: %s', xml.attrib)
|
||||
if not self.sync_this_item(api.library_section_id()):
|
||||
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
|
||||
'Kodi', api.plex_type, api.plex_id, api.title(),
|
||||
api.library_section_id())
|
||||
return
|
||||
plex_id = api.plex_id
|
||||
movie = self.plexdb.movie(plex_id)
|
||||
if movie:
|
||||
update_item = True
|
||||
|
|
|
@ -159,10 +159,12 @@ class Artist(MusicMixin, ItemBase):
|
|||
Process a single artist
|
||||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error('Cannot process artist %s', xml.attrib)
|
||||
if not self.sync_this_item(api.library_section_id()):
|
||||
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
|
||||
'Kodi', api.plex_type, api.plex_id, api.title(),
|
||||
api.library_section_id())
|
||||
return
|
||||
plex_id = api.plex_id
|
||||
artist = self.plexdb.artist(plex_id)
|
||||
if not artist:
|
||||
update_item = False
|
||||
|
@ -224,9 +226,6 @@ class Album(MusicMixin, ItemBase):
|
|||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error('Error processing album: %s', xml.attrib)
|
||||
return
|
||||
album = self.plexdb.album(plex_id)
|
||||
if album:
|
||||
update_item = True
|
||||
|
@ -389,9 +388,6 @@ class Song(MusicMixin, ItemBase):
|
|||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error('Error processing song: %s', xml.attrib)
|
||||
return
|
||||
song = self.plexdb.song(plex_id)
|
||||
if song:
|
||||
update_item = True
|
||||
|
|
|
@ -148,10 +148,12 @@ class Show(TvShowMixin, ItemBase):
|
|||
Process a single show
|
||||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error("Cannot parse XML data for TV show: %s", xml.attrib)
|
||||
if not self.sync_this_item(api.library_section_id()):
|
||||
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
|
||||
'Kodi', api.plex_type, api.plex_id, api.title(),
|
||||
api.library_section_id())
|
||||
return
|
||||
plex_id = api.plex_id
|
||||
show = self.plexdb.show(plex_id)
|
||||
if not show:
|
||||
update_item = False
|
||||
|
@ -286,11 +288,12 @@ class Season(TvShowMixin, ItemBase):
|
|||
Process a single season of a certain tv show
|
||||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error('Error getting plex_id for season, skipping: %s',
|
||||
xml.attrib)
|
||||
if not self.sync_this_item(api.library_section_id()):
|
||||
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
|
||||
'Kodi', api.plex_type, api.plex_id, api.title(),
|
||||
api.library_section_id())
|
||||
return
|
||||
plex_id = api.plex_id
|
||||
season = self.plexdb.season(plex_id)
|
||||
if not season:
|
||||
update_item = False
|
||||
|
@ -354,11 +357,12 @@ class Episode(TvShowMixin, ItemBase):
|
|||
Process single episode
|
||||
"""
|
||||
api = API(xml)
|
||||
plex_id = api.plex_id
|
||||
if not plex_id:
|
||||
LOG.error('Error getting plex_id for episode, skipping: %s',
|
||||
xml.attrib)
|
||||
if not self.sync_this_item(api.library_section_id()):
|
||||
LOG.debug('Skipping sync of %s %s: %s - section %s not synched to '
|
||||
'Kodi', api.plex_type, api.plex_id, api.title(),
|
||||
api.library_section_id())
|
||||
return
|
||||
plex_id = api.plex_id
|
||||
episode = self.plexdb.episode(plex_id)
|
||||
if not episode:
|
||||
update_item = False
|
||||
|
|
|
@ -255,7 +255,7 @@ class FullSync(common.fullsync_mixin):
|
|||
"""
|
||||
try:
|
||||
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 self.isCanceled():
|
||||
LOG.debug('Need to exit now')
|
||||
|
|
|
@ -15,7 +15,6 @@ from ..utils import etree
|
|||
LOG = getLogger('PLEX.sync.sections')
|
||||
|
||||
BATCH_SIZE = 500
|
||||
SECTIONS = []
|
||||
# Need a way to interrupt our synching process
|
||||
IS_CANCELED = None
|
||||
|
||||
|
@ -590,11 +589,10 @@ def sync_from_pms(parent_self, pick_libraries=False):
|
|||
return _sync_from_pms(pick_libraries)
|
||||
finally:
|
||||
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):
|
||||
global SECTIONS
|
||||
# Re-set value in order to make sure we got the lastest user input
|
||||
app.SYNC.enable_music = utils.settings('enableMusic') == 'true'
|
||||
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
|
||||
# listings
|
||||
utils.window('Plex.nodes.total', str(len(sections)))
|
||||
SECTIONS = sections
|
||||
app.SYNC.sections = sections
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue