PlexKodiConnect/resources/lib/library_sync/sync_info.py

74 lines
2.4 KiB
Python
Raw Normal View History

2017-04-03 01:02:41 +10:00
# -*- coding: utf-8 -*-
from logging import getLogger
from threading import Thread, Lock
from xbmc import sleep
2017-08-18 18:37:30 +10:00
from xbmcgui import DialogProgressBG
2017-04-03 01:02:41 +10:00
2018-06-22 03:24:37 +10:00
from .. import utils
2017-04-03 01:02:41 +10:00
###############################################################################
LOG = getLogger("PLEX." + __name__)
2017-04-03 01:02:41 +10:00
GET_METADATA_COUNT = 0
PROCESS_METADATA_COUNT = 0
PROCESSING_VIEW_NAME = ''
LOCK = Lock()
###############################################################################
2018-06-22 03:24:37 +10:00
@utils.thread_methods(add_stops=['SUSPEND_LIBRARY_THREAD',
'STOP_SYNC',
'SUSPEND_SYNC'])
class ThreadedShowSyncInfo(Thread):
2017-04-03 01:02:41 +10:00
"""
Threaded class to show the Kodi statusbar of the metadata download.
Input:
total: Total number of items to get
2017-08-18 18:37:30 +10:00
item_type:
2017-04-03 01:02:41 +10:00
"""
2017-08-18 18:37:30 +10:00
def __init__(self, total, item_type):
2017-04-03 01:02:41 +10:00
self.total = total
self.item_type = item_type
Thread.__init__(self)
def run(self):
"""
Do the work
"""
LOG.debug('Show sync info thread started')
2017-04-03 01:02:41 +10:00
# cache local variables because it's faster
2017-08-19 20:51:58 +10:00
total = self.total
2017-08-18 18:37:30 +10:00
dialog = DialogProgressBG('dialoglogProgressBG')
dialog.create("%s %s: %s %s"
2018-06-22 03:24:37 +10:00
% (utils.lang(39714),
self.item_type,
unicode(total),
utils.lang(39715)))
2017-04-03 01:02:41 +10:00
total = 2 * total
total_progress = 0
while not self.stopped():
2017-04-03 01:02:41 +10:00
with LOCK:
get_progress = GET_METADATA_COUNT
process_progress = PROCESS_METADATA_COUNT
view_name = PROCESSING_VIEW_NAME
total_progress = get_progress + process_progress
2017-04-03 01:02:41 +10:00
try:
2018-06-22 03:24:37 +10:00
percentage = int(float(total_progress) / float(total) * 100.0)
2017-04-03 01:02:41 +10:00
except ZeroDivisionError:
percentage = 0
dialog.update(percentage,
message="%s %s. %s %s: %s"
2017-04-03 01:02:41 +10:00
% (get_progress,
2018-06-22 03:24:37 +10:00
utils.lang(39712),
2017-04-03 01:02:41 +10:00
process_progress,
2018-06-22 03:24:37 +10:00
utils.lang(39713),
view_name))
2017-04-03 01:02:41 +10:00
# Sleep for x milliseconds
sleep(200)
dialog.close()
LOG.debug('Show sync info thread terminated')