parent
4ee828dfe9
commit
50686ae191
2 changed files with 43 additions and 26 deletions
|
@ -15,6 +15,7 @@ LOG = getLogger('PLEX.sync.fanart')
|
||||||
SUPPORTED_TYPES = (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW)
|
SUPPORTED_TYPES = (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW)
|
||||||
SYNC_FANART = utils.settings('FanartTV') == 'true'
|
SYNC_FANART = utils.settings('FanartTV') == 'true'
|
||||||
PREFER_KODI_COLLECTION_ART = utils.settings('PreferKodiCollectionArt') == 'false'
|
PREFER_KODI_COLLECTION_ART = utils.settings('PreferKodiCollectionArt') == 'false'
|
||||||
|
BATCH_SIZE = 500
|
||||||
|
|
||||||
|
|
||||||
def suspends():
|
def suspends():
|
||||||
|
@ -45,29 +46,37 @@ class FanartThread(backgroundthread.KillableThread):
|
||||||
def _run_internal(self):
|
def _run_internal(self):
|
||||||
LOG.info('Starting FanartThread')
|
LOG.info('Starting FanartThread')
|
||||||
finished = False
|
finished = False
|
||||||
while True:
|
try:
|
||||||
with PlexDB() as plexdb:
|
for typus in SUPPORTED_TYPES:
|
||||||
func = plexdb.every_plex_id if self.refresh else plexdb.missing_fanart
|
offset = 0
|
||||||
for typus in SUPPORTED_TYPES:
|
while True:
|
||||||
for plex_id in func(typus):
|
with PlexDB() as plexdb:
|
||||||
if self.isCanceled() or self.isSuspended():
|
# Keep DB connection open only for a short period of time!
|
||||||
break
|
if self.refresh:
|
||||||
|
batch = list(plexdb.every_plex_id(typus,
|
||||||
|
offset,
|
||||||
|
BATCH_SIZE))
|
||||||
|
else:
|
||||||
|
batch = list(plexdb.missing_fanart(typus,
|
||||||
|
offset,
|
||||||
|
BATCH_SIZE))
|
||||||
|
for plex_id in batch:
|
||||||
|
# Do the actual, time-consuming processing
|
||||||
|
if self.isCanceled():
|
||||||
|
return
|
||||||
|
if self.isSuspended():
|
||||||
|
if self.isCanceled():
|
||||||
|
return
|
||||||
|
app.APP.monitor.waitForAbort(1)
|
||||||
process_fanart(plex_id, typus, self.refresh)
|
process_fanart(plex_id, typus, self.refresh)
|
||||||
if self.isCanceled() or self.isSuspended():
|
if len(batch) < BATCH_SIZE:
|
||||||
break
|
break
|
||||||
else:
|
offset += BATCH_SIZE
|
||||||
# Done processing!
|
else:
|
||||||
finished = True
|
finished = True
|
||||||
break
|
finally:
|
||||||
# Need to have these outside our DB context to close the connection
|
LOG.info('FanartThread finished: %s', finished)
|
||||||
if self.isCanceled():
|
self.callback(finished)
|
||||||
return
|
|
||||||
if self.isSuspended():
|
|
||||||
if self.isCanceled():
|
|
||||||
return
|
|
||||||
app.APP.monitor.waitForAbort(1)
|
|
||||||
LOG.info('FanartThread finished')
|
|
||||||
self.callback(finished)
|
|
||||||
|
|
||||||
|
|
||||||
class FanartTask(common.libsync_mixin, backgroundthread.Task):
|
class FanartTask(common.libsync_mixin, backgroundthread.Task):
|
||||||
|
|
|
@ -121,20 +121,28 @@ class PlexDBBase(object):
|
||||||
"""
|
"""
|
||||||
self.cursor.execute('DELETE FROM %s WHERE plex_id = ?' % plex_type, (plex_id, ))
|
self.cursor.execute('DELETE FROM %s WHERE plex_id = ?' % plex_type, (plex_id, ))
|
||||||
|
|
||||||
def every_plex_id(self, plex_type):
|
def every_plex_id(self, plex_type, offset, limit):
|
||||||
"""
|
"""
|
||||||
Returns an iterator for plex_type for every single plex_id
|
Returns an iterator for plex_type for every single plex_id
|
||||||
|
Will start with records at DB position offset [int] and return limit
|
||||||
|
[int] number of items
|
||||||
"""
|
"""
|
||||||
return (x[0] for x in
|
return (x[0] for x in
|
||||||
self.cursor.execute('SELECT plex_id from %s' % plex_type))
|
self.cursor.execute('SELECT plex_id FROM %s LIMIT %s OFFSET %s'
|
||||||
|
% (plex_type, limit, offset)))
|
||||||
|
|
||||||
def missing_fanart(self, plex_type):
|
def missing_fanart(self, plex_type, offset, limit):
|
||||||
"""
|
"""
|
||||||
Returns an iterator for plex_type for all plex_id, where fanart_synced
|
Returns an iterator for plex_type for all plex_id, where fanart_synced
|
||||||
has not yet been set to 1
|
has not yet been set to 1
|
||||||
|
Will start with records at DB position offset [int] and return limit
|
||||||
|
[int] number of items
|
||||||
"""
|
"""
|
||||||
return (x[0] for x in
|
query = '''
|
||||||
self.cursor.execute('SELECT plex_id from %s WHERE fanart_synced = 0' % plex_type))
|
SELECT plex_id FROM %s WHERE fanart_synced = 0
|
||||||
|
LIMIT %s OFFSET %s
|
||||||
|
''' % (plex_type, limit, offset)
|
||||||
|
return (x[0] for x in self.cursor.execute(query))
|
||||||
|
|
||||||
def set_fanart_synced(self, plex_id, plex_type):
|
def set_fanart_synced(self, plex_id, plex_type):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue