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