PlexKodiConnect/resources/lib/library_sync/sync_info.py

82 lines
2.5 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
2017-05-17 21:55:24 +10:00
from utils import thread_methods, language as lang
2017-04-03 01:02:41 +10:00
###############################################################################
log = getLogger("PLEX."+__name__)
GET_METADATA_COUNT = 0
PROCESS_METADATA_COUNT = 0
PROCESSING_VIEW_NAME = ''
LOCK = Lock()
###############################################################################
2017-05-17 21:55:24 +10:00
@thread_methods(add_stops=['SUSPEND_LIBRARY_THREAD'])
2017-04-03 01:02:41 +10:00
class Threaded_Show_Sync_Info(Thread):
"""
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):
"""
Catch all exceptions and log them
"""
try:
self.__run()
except Exception as e:
log.error('Exception %s' % e)
import traceback
log.error("Traceback:\n%s" % traceback.format_exc())
def __run(self):
"""
Do the work
"""
log.debug('Show sync info thread started')
# cache local variables because it's faster
2017-08-18 18:37:30 +10:00
total = self.totaltal
dialog = DialogProgressBG('dialoglogProgressBG')
thread_stopped = self.thread_stopped
dialog.create("%s %s: %s %s"
% (lang(39714), self.item_type, str(total), lang(39715)))
2017-04-03 01:02:41 +10:00
total = 2 * total
totalProgress = 0
while thread_stopped() is False:
2017-04-03 01:02:41 +10:00
with LOCK:
get_progress = GET_METADATA_COUNT
process_progress = PROCESS_METADATA_COUNT
viewName = PROCESSING_VIEW_NAME
totalProgress = get_progress + process_progress
try:
percentage = int(float(totalProgress) / float(total)*100.0)
except ZeroDivisionError:
percentage = 0
dialog.update(percentage,
message="%s %s. %s %s: %s"
2017-04-03 01:02:41 +10:00
% (get_progress,
lang(39712),
2017-04-03 01:02:41 +10:00
process_progress,
lang(39713),
2017-04-03 01:02:41 +10:00
viewName))
# Sleep for x milliseconds
sleep(200)
dialog.close()
log.debug('Show sync info thread terminated')