More hacking
This commit is contained in:
parent
e935b7c97b
commit
35a25a7f15
2 changed files with 26 additions and 38 deletions
|
@ -31,6 +31,7 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
self.last_sync = None
|
self.last_sync = None
|
||||||
self.plex_db = None
|
self.plex_db = None
|
||||||
self.plex_type = None
|
self.plex_type = None
|
||||||
|
self.processing_thread = None
|
||||||
super(FullSync, self).__init__()
|
super(FullSync, self).__init__()
|
||||||
|
|
||||||
def process_item(self, xml_item):
|
def process_item(self, xml_item):
|
||||||
|
@ -105,10 +106,6 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
def full_library_sync(self):
|
def full_library_sync(self):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
self.queue = backgroundthread.Queue.Queue(maxsize=200)
|
|
||||||
t = process_metadata.ProcessMetadata(self.queue, self.last_sync)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
kinds = [
|
kinds = [
|
||||||
(v.PLEX_TYPE_MOVIE, itemtypes.Movie, False),
|
(v.PLEX_TYPE_MOVIE, itemtypes.Movie, False),
|
||||||
(v.PLEX_TYPE_SHOW, itemtypes.Show, False),
|
(v.PLEX_TYPE_SHOW, itemtypes.Show, False),
|
||||||
|
@ -126,33 +123,15 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
# Now do the heavy lifting
|
# Now do the heavy lifting
|
||||||
if self.isCanceled() or not self.process_kind():
|
if self.isCanceled() or not self.process_kind():
|
||||||
return False
|
return False
|
||||||
if not self.new_items_only:
|
if self.new_items_only:
|
||||||
# Delete movies that are not on Plex anymore - do this only once
|
# Delete movies that are not on Plex anymore - do this only once
|
||||||
self.process_delete()
|
self.process_delete()
|
||||||
|
|
||||||
|
|
||||||
# Let kodi update the views in any case, since we're doing a full sync
|
|
||||||
common.update_kodi_library(video=True, music=state.ENABLE_MUSIC)
|
|
||||||
|
|
||||||
if utils.window('plex_scancrashed') == 'true':
|
|
||||||
# Show warning if itemtypes.py crashed at some point
|
|
||||||
utils.messageDialog(utils.lang(29999), utils.lang(39408))
|
|
||||||
utils.window('plex_scancrashed', clear=True)
|
|
||||||
elif utils.window('plex_scancrashed') == '401':
|
|
||||||
utils.window('plex_scancrashed', clear=True)
|
|
||||||
if state.PMS_STATUS not in ('401', 'Auth'):
|
|
||||||
# Plex server had too much and returned ERROR
|
|
||||||
utils.messageDialog(utils.lang(29999), utils.lang(39409))
|
|
||||||
finally:
|
|
||||||
# Last element will kill the processing thread
|
|
||||||
self.queue.put(None)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@utils.log_time
|
@utils.log_time
|
||||||
def run(self):
|
def run(self):
|
||||||
successful = False
|
successful = False
|
||||||
self.last_sync = time.time()
|
self.last_sync = time.time()
|
||||||
try:
|
|
||||||
if self.isCanceled():
|
if self.isCanceled():
|
||||||
return
|
return
|
||||||
LOG.info('Running fullsync for NEW PMS items with repair=%s',
|
LOG.info('Running fullsync for NEW PMS items with repair=%s',
|
||||||
|
@ -161,6 +140,12 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
return
|
return
|
||||||
if self.isCanceled():
|
if self.isCanceled():
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
|
# Fire up our single processing thread
|
||||||
|
self.queue = backgroundthread.Queue.Queue(maxsize=200)
|
||||||
|
self.processing_thread = process_metadata.ProcessMetadata(
|
||||||
|
self.queue, self.last_sync)
|
||||||
|
self.processing_thread.start()
|
||||||
# This will also update playstates and userratings!
|
# This will also update playstates and userratings!
|
||||||
if self.full_library_sync(new_items_only=True) is False:
|
if self.full_library_sync(new_items_only=True) is False:
|
||||||
return
|
return
|
||||||
|
@ -179,7 +164,14 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
except:
|
except:
|
||||||
utils.ERROR(txt='full_sync.py crashed', notify=True)
|
utils.ERROR(txt='full_sync.py crashed', notify=True)
|
||||||
finally:
|
finally:
|
||||||
|
# Last element will kill the processing thread (if not already
|
||||||
|
# done so, e.g. quitting Kodi)
|
||||||
|
self.queue.put(None)
|
||||||
|
# This will block until the processing thread exits
|
||||||
|
LOG.debug('Waiting for processing thread to exit')
|
||||||
|
self.processing_thread.join()
|
||||||
self.callback(successful)
|
self.callback(successful)
|
||||||
|
LOG.info('Done full_sync')
|
||||||
|
|
||||||
|
|
||||||
def process_updatelist(item_class, show_sync_info=True):
|
def process_updatelist(item_class, show_sync_info=True):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
import xbmc
|
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
|
||||||
from . import common
|
from . import common
|
||||||
|
@ -74,16 +73,13 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
while self.isCanceled() is False:
|
while self.isCanceled() is False:
|
||||||
if section is None:
|
if section is None:
|
||||||
break
|
break
|
||||||
|
self.current = 0
|
||||||
self.total = section.total
|
self.total = section.total
|
||||||
self.section_name = section.name
|
self.section_name = section.name
|
||||||
with section.context(self.last_sync) as context:
|
with section.context(self.last_sync) as context:
|
||||||
while self.isCanceled() is False:
|
while self.isCanceled() is False:
|
||||||
# grabs item from queue
|
# grabs item from queue. This will block!
|
||||||
try:
|
xml = self.queue.get()
|
||||||
xml = self.queue.get(block=False)
|
|
||||||
except backgroundthread.Queue.Empty:
|
|
||||||
xbmc.sleep(20)
|
|
||||||
continue
|
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
if xml is InitNewSection or xml is None:
|
if xml is InitNewSection or xml is None:
|
||||||
section = xml
|
section = xml
|
||||||
|
@ -96,11 +92,11 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
||||||
except:
|
except:
|
||||||
utils.ERROR(txt='process_metadata crashed',
|
utils.ERROR(txt='process_metadata crashed',
|
||||||
notify=True)
|
notify=True)
|
||||||
self.current += 1
|
|
||||||
if self.current % 20 == 0:
|
if self.current % 20 == 0:
|
||||||
self.title = utils.cast(unicode,
|
self.title = utils.cast(unicode,
|
||||||
xml[0].get('title'))
|
xml[0].get('title'))
|
||||||
self.update_dialog()
|
self.update_dialog()
|
||||||
|
self.current += 1
|
||||||
finally:
|
finally:
|
||||||
self.dialog.close()
|
self.dialog.close()
|
||||||
LOG.debug('Processing thread terminated')
|
LOG.debug('Processing thread terminated')
|
||||||
|
|
Loading…
Reference in a new issue