parent
afb0960260
commit
c0d91507c0
2 changed files with 48 additions and 28 deletions
|
@ -14,7 +14,7 @@ import xbmc
|
|||
import xbmcgui
|
||||
import xbmcvfs
|
||||
|
||||
from image_cache_thread import ImageCacheThread
|
||||
import image_cache_thread
|
||||
from utils import window, settings, language as lang, kodiSQL, tryEncode, \
|
||||
tryDecode, IfExists
|
||||
|
||||
|
@ -254,22 +254,20 @@ class Artwork():
|
|||
# removed finished
|
||||
with self.lock:
|
||||
for thread in self.imageCacheThreads:
|
||||
if thread.isAlive() is False:
|
||||
if thread.is_finished:
|
||||
self.imageCacheThreads.remove(thread)
|
||||
# add a new thread or wait and retry if we hit our limit
|
||||
with self.lock:
|
||||
if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
|
||||
thread = ImageCacheThread(
|
||||
self.xbmc_username,
|
||||
self.xbmc_password,
|
||||
"http://%s:%s/image/image://%s"
|
||||
% (self.xbmc_host,
|
||||
self.xbmc_port,
|
||||
self.double_urlencode(url)))
|
||||
thread.start()
|
||||
self.imageCacheThreads.append(thread)
|
||||
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
|
||||
log.error('Waiting for queue spot here')
|
||||
log.debug("Waiting for empty queue spot: %s"
|
||||
% len(self.imageCacheThreads))
|
||||
xbmc.sleep(50)
|
||||
|
||||
def cacheTexture(self, url):
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
###############################################################################
|
||||
#################################################################################################
|
||||
|
||||
import logging
|
||||
import threading
|
||||
import requests
|
||||
|
@ -8,30 +9,51 @@ import requests
|
|||
# Disable annoying requests warnings
|
||||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
###############################################################################
|
||||
#################################################################################################
|
||||
|
||||
log = logging.getLogger("PLEX."+__name__)
|
||||
|
||||
###############################################################################
|
||||
#################################################################################################
|
||||
|
||||
|
||||
class ImageCacheThread(threading.Thread):
|
||||
def __init__(self, xbmc_username, xbmc_password, url):
|
||||
self.xbmc_username = xbmc_username
|
||||
self.xbmc_password = xbmc_password
|
||||
self.url = url
|
||||
|
||||
url_to_process = None
|
||||
is_finished = False
|
||||
|
||||
xbmc_host = ""
|
||||
xbmc_port = ""
|
||||
xbmc_username = ""
|
||||
xbmc_password = ""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
|
||||
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 set_auth(self, username, password):
|
||||
|
||||
self.xbmc_username = username
|
||||
self.xbmc_password = password
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
requests.head(
|
||||
url=self.url,
|
||||
response = 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=(0.01, 0.01))
|
||||
except requests.Timeout:
|
||||
# We don't need the result, only trigger Kodi to start download
|
||||
timeout=(5, 5))
|
||||
# We don't need the result
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
log.error('Encountered exception: %s' % e)
|
||||
import traceback
|
||||
log.error("Traceback:\n%s" % traceback.format_exc())
|
||||
self.is_finished = True
|
||||
|
|
Loading…
Reference in a new issue