(testing)
This commit is contained in:
angelblue05 2016-08-21 21:51:23 -05:00
parent 8cd4cb903e
commit 8b9b0821c0
3 changed files with 44 additions and 42 deletions

View file

@ -254,7 +254,7 @@ class Artwork():
while len(self.imageCacheThreads): while len(self.imageCacheThreads):
for thread in self.imageCacheThreads: for thread in self.imageCacheThreads:
if thread.isFinished: if thread.is_finished:
self.imageCacheThreads.remove(thread) self.imageCacheThreads.remove(thread)
pdialog.update(100, "%s %s" % (lang(33046), len(self.imageCacheThreads))) pdialog.update(100, "%s %s" % (lang(33046), len(self.imageCacheThreads)))
log.info("Waiting for all threads to exit: %s" % len(self.imageCacheThreads)) log.info("Waiting for all threads to exit: %s" % len(self.imageCacheThreads))
@ -267,15 +267,15 @@ class Artwork():
while True: while True:
# removed finished # removed finished
for thread in self.imageCacheThreads: for thread in self.imageCacheThreads:
if thread.isFinished: if thread.is_finished:
self.imageCacheThreads.remove(thread) self.imageCacheThreads.remove(thread)
# add a new thread or wait and retry if we hit our limit # add a new thread or wait and retry if we hit our limit
if len(self.imageCacheThreads) < self.imageCacheLimitThreads: if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
newThread = image_cache_thread.image_cache_thread() newThread = image_cache_thread.ImageCacheThread()
newThread.setUrl(self.double_urlencode(url)) newThread.set_url(self.double_urlencode(url))
newThread.setHost(self.xbmc_host, self.xbmc_port) newThread.set_host(self.xbmc_host, self.xbmc_port)
newThread.setAuth(self.xbmc_username, self.xbmc_password) newThread.set_auth(self.xbmc_username, self.xbmc_password)
newThread.start() newThread.start()
self.imageCacheThreads.append(newThread) self.imageCacheThreads.append(newThread)
return return

View file

@ -3,8 +3,8 @@
################################################################################################# #################################################################################################
import logging import logging
import requests
import threading import threading
import requests
################################################################################################# #################################################################################################
@ -12,49 +12,50 @@ log = logging.getLogger("EMBY."+__name__)
################################################################################################# #################################################################################################
class image_cache_thread(threading.Thread): class ImageCacheThread(threading.Thread):
url_to_process = None
is_finished = False
urlToProcess = None
isFinished = False
xbmc_host = "" xbmc_host = ""
xbmc_port = "" xbmc_port = ""
xbmc_username = "" xbmc_username = ""
xbmc_password = "" xbmc_password = ""
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)
def setUrl(self, url):
self.urlToProcess = url def set_url(self, url):
def setHost(self, host, port): self.url_to_process = url
def set_host(self, host, port):
self.xbmc_host = host self.xbmc_host = host
self.xbmc_port = port self.xbmc_port = port
def setAuth(self, user, pwd):
self.xbmc_username = user def set_auth(self, username, password):
self.xbmc_password = pwd
self.xbmc_username = username
self.xbmc_password = password
def run(self): def run(self):
log.debug("Image Caching Thread Processing: %s" % self.urlToProcess) log.debug("Image Caching Thread Processing: %s" % self.url_to_process)
try: try:
response = requests.head( requests.head(
url=( url=(
"http://%s:%s/image/image://%s" "http://%s:%s/image/image://%s"
% (self.xbmc_host, self.xbmc_port, self.urlToProcess)), % (self.xbmc_host, self.xbmc_port, self.url_to_process)),
auth=(self.xbmc_username, self.xbmc_password), auth=(self.xbmc_username, self.xbmc_password),
timeout=(35.1, 35.1)) timeout=(35.1, 35.1))
# We don't need the result # We don't need the result
except: pass except:
pass
log.debug("Image Caching Thread Exited") log.debug("Image Caching Thread Exited")
self.isFinished = True self.is_finished = True

View file

@ -11,7 +11,7 @@ from utils import window
def config(): def config():
logger = logging.getLogger('EMBY') logger = logging.getLogger('EMBY')
logger.addHandler(LogHandler()) logger.addHandler(LogHandler())
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@ -20,19 +20,20 @@ def config():
class LogHandler(logging.StreamHandler): class LogHandler(logging.StreamHandler):
def __init__(self): def __init__(self):
logging.StreamHandler.__init__(self) logging.StreamHandler.__init__(self)
self.setFormatter(MyFormatter()) self.setFormatter(MyFormatter())
def emit(self, record): def emit(self, record):
if self._getLogLevel(record.levelno): if self._get_log_level(record.levelno):
try: try:
xbmc.log(self.format(record), level=xbmc.LOGNOTICE) xbmc.log(self.format(record), level=xbmc.LOGNOTICE)
except UnicodeEncodeError: except UnicodeEncodeError:
xbmc.log(self.format(record).encode('utf-8'), level=xbmc.LOGNOTICE) xbmc.log(self.format(record).encode('utf-8'), level=xbmc.LOGNOTICE)
def _getLogLevel(self, level): @classmethod
def _get_log_level(cls, level):
levels = { levels = {
logging.ERROR: 0, logging.ERROR: 0,
@ -41,17 +42,17 @@ class LogHandler(logging.StreamHandler):
logging.DEBUG: 2 logging.DEBUG: 2
} }
try: try:
logLevel = int(window('emby_logLevel')) log_level = int(window('emby_logLevel'))
except ValueError: except ValueError:
logLevel = 0 log_level = 0
return logLevel >= levels[level] return log_level >= levels[level]
class MyFormatter(logging.Formatter): class MyFormatter(logging.Formatter):
def __init__(self, fmt="%(name)s -> %(message)s"): def __init__(self, fmt="%(name)s -> %(message)s"):
logging.Formatter.__init__(self, fmt) logging.Formatter.__init__(self, fmt)
def format(self, record): def format(self, record):
@ -70,4 +71,4 @@ class MyFormatter(logging.Formatter):
# Restore the original format configured by the user # Restore the original format configured by the user
self._fmt = format_orig self._fmt = format_orig
return result return result