PlexKodiConnect/resources/lib/image_cache_thread.py

66 lines
1.7 KiB
Python
Raw Normal View History

2016-06-17 22:03:28 -05:00
# -*- coding: utf-8 -*-
#################################################################################################
import logging
import threading
import requests
# Disable annoying requests warnings
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
#################################################################################################
2016-08-30 15:55:13 +02:00
log = logging.getLogger("PLEX."+__name__)
2016-06-17 22:03:28 -05:00
#################################################################################################
2016-01-26 17:20:13 +01:00
2016-08-21 21:51:23 -05:00
class ImageCacheThread(threading.Thread):
url_to_process = None
is_finished = False
xbmc_host = ""
xbmc_port = ""
xbmc_username = ""
xbmc_password = ""
2016-08-21 21:51:23 -05:00
2016-06-17 22:03:28 -05:00
def __init__(self):
2016-06-17 22:03:28 -05:00
threading.Thread.__init__(self)
2016-01-26 17:20:13 +01:00
2016-06-17 22:03:28 -05:00
2016-08-21 21:51:23 -05:00
def set_url(self, url):
self.url_to_process = url
def set_host(self, host, port):
2016-06-17 22:03:28 -05:00
self.xbmc_host = host
self.xbmc_port = port
2016-06-17 22:03:28 -05:00
2016-08-21 21:51:23 -05:00
def set_auth(self, username, password):
self.xbmc_username = username
self.xbmc_password = password
def run(self):
2016-08-21 21:51:23 -05:00
2016-08-21 21:57:43 -05:00
log.debug("Image Caching Thread Processing: %s", self.url_to_process)
2016-08-21 22:00:35 -05:00
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),
2016-03-13 16:12:25 +01:00
timeout=(5, 5))
# We don't need the result
2016-08-21 21:57:43 -05:00
except Exception:
2016-08-21 21:51:23 -05:00
pass
log.debug("Image Caching Thread Exited")
2016-08-21 21:51:23 -05:00
self.is_finished = True