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

View File

@ -3,8 +3,8 @@
#################################################################################################
import logging
import requests
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_port = ""
xbmc_username = ""
xbmc_password = ""
def __init__(self):
threading.Thread.__init__(self)
def setUrl(self, url):
self.urlToProcess = url
def setHost(self, host, port):
def set_url(self, url):
self.url_to_process = url
def set_host(self, host, port):
self.xbmc_host = host
self.xbmc_port = port
def setAuth(self, user, pwd):
self.xbmc_username = user
self.xbmc_password = pwd
def set_auth(self, username, password):
self.xbmc_username = username
self.xbmc_password = password
def run(self):
log.debug("Image Caching Thread Processing: %s" % self.urlToProcess)
log.debug("Image Caching Thread Processing: %s" % self.url_to_process)
try:
response = requests.head(
url=(
"http://%s:%s/image/image://%s"
% (self.xbmc_host, self.xbmc_port, self.urlToProcess)),
auth=(self.xbmc_username, self.xbmc_password),
timeout=(35.1, 35.1))
requests.head(
url=(
"http://%s:%s/image/image://%s"
% (self.xbmc_host, self.xbmc_port, self.url_to_process)),
auth=(self.xbmc_username, self.xbmc_password),
timeout=(35.1, 35.1))
# We don't need the result
except: pass
except:
pass
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():
logger = logging.getLogger('EMBY')
logger.addHandler(LogHandler())
logger.setLevel(logging.DEBUG)
@ -20,19 +20,20 @@ def config():
class LogHandler(logging.StreamHandler):
def __init__(self):
logging.StreamHandler.__init__(self)
self.setFormatter(MyFormatter())
def emit(self, record):
if self._getLogLevel(record.levelno):
if self._get_log_level(record.levelno):
try:
xbmc.log(self.format(record), level=xbmc.LOGNOTICE)
except UnicodeEncodeError:
xbmc.log(self.format(record).encode('utf-8'), level=xbmc.LOGNOTICE)
def _getLogLevel(self, level):
@classmethod
def _get_log_level(cls, level):
levels = {
logging.ERROR: 0,
@ -41,17 +42,17 @@ class LogHandler(logging.StreamHandler):
logging.DEBUG: 2
}
try:
logLevel = int(window('emby_logLevel'))
log_level = int(window('emby_logLevel'))
except ValueError:
logLevel = 0
log_level = 0
return logLevel >= levels[level]
return log_level >= levels[level]
class MyFormatter(logging.Formatter):
def __init__(self, fmt="%(name)s -> %(message)s"):
logging.Formatter.__init__(self, fmt)
def format(self, record):
@ -70,4 +71,4 @@ class MyFormatter(logging.Formatter):
# Restore the original format configured by the user
self._fmt = format_orig
return result
return result