[4] Fixed verify ssl for downloading images (#2103)

pull/2113/head
meisnate12 6 months ago committed by GitHub Action
parent a671d06dd9
commit dcf0435a96

@ -1 +1 @@
2.0.2-build3 2.0.2-build4

@ -11,6 +11,7 @@ logger = util.logger
class Library(ABC): class Library(ABC):
def __init__(self, config, params): def __init__(self, config, params):
self.session = None
self.Radarr = None self.Radarr = None
self.Sonarr = None self.Sonarr = None
self.Tautulli = None self.Tautulli = None
@ -298,7 +299,7 @@ class Library(ABC):
return images["asset_directory"] return images["asset_directory"]
else: else:
try: try:
return self.config.Requests.download_image(title, images[attr], item_dir, is_poster=is_poster, filename=image_name) return self.config.Requests.download_image(title, images[attr], item_dir, session=self.session, is_poster=is_poster, filename=image_name)
except Failed as e: except Failed as e:
logger.error(e) logger.error(e)
if attr in ["asset_directory", f"pmm_{image_type}"]: if attr in ["asset_directory", f"pmm_{image_type}"]:
@ -322,7 +323,7 @@ class Library(ABC):
pass pass
def check_image_for_overlay(self, image_url, image_path, remove=False): def check_image_for_overlay(self, image_url, image_path, remove=False):
image_path = self.config.Requests.download_image("", image_url, image_path).location image_path = self.config.Requests.download_image("", image_url, image_path, session=self.session).location
while util.is_locked(image_path): while util.is_locked(image_path):
time.sleep(1) time.sleep(1)
with Image.open(image_path) as image: with Image.open(image_path) as image:

@ -447,19 +447,19 @@ class Plex(Library):
super().__init__(config, params) super().__init__(config, params)
self.plex = params["plex"] self.plex = params["plex"]
self.url = self.plex["url"] self.url = self.plex["url"]
plex_session = self.config.Requests.session self.session = self.config.Requests.session
if self.plex["verify_ssl"] is False and self.config.Requests.global_ssl is True: if self.plex["verify_ssl"] is False and self.config.Requests.global_ssl is True:
logger.debug("Overriding verify_ssl to False for Plex connection") logger.debug("Overriding verify_ssl to False for Plex connection")
plex_session = self.config.Requests.create_session(verify_ssl=False) self.session = self.config.Requests.create_session(verify_ssl=False)
if self.plex["verify_ssl"] is True and self.config.Requests.global_ssl is False: if self.plex["verify_ssl"] is True and self.config.Requests.global_ssl is False:
logger.debug("Overriding verify_ssl to True for Plex connection") logger.debug("Overriding verify_ssl to True for Plex connection")
plex_session = self.config.Requests.create_session() self.session = self.config.Requests.create_session()
self.token = self.plex["token"] self.token = self.plex["token"]
self.timeout = self.plex["timeout"] self.timeout = self.plex["timeout"]
logger.secret(self.url) logger.secret(self.url)
logger.secret(self.token) logger.secret(self.token)
try: try:
self.PlexServer = PlexServer(baseurl=self.url, token=self.token, session=plex_session, timeout=self.timeout) self.PlexServer = PlexServer(baseurl=self.url, token=self.token, session=self.session, timeout=self.timeout)
plexapi.server.TIMEOUT = self.timeout plexapi.server.TIMEOUT = self.timeout
os.environ["PLEXAPI_PLEXAPI_TIMEOUT"] = str(self.timeout) os.environ["PLEXAPI_PLEXAPI_TIMEOUT"] = str(self.timeout)
logger.info(f"Connected to server {self.PlexServer.friendlyName} version {self.PlexServer.version}") logger.info(f"Connected to server {self.PlexServer.friendlyName} version {self.PlexServer.version}")

@ -92,8 +92,8 @@ class Requests:
import urllib3 import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def download_image(self, title, image_url, download_directory, is_poster=True, filename=None): def download_image(self, title, image_url, download_directory, session=None, is_poster=True, filename=None):
response = self.get_image(image_url) response = self.get_image(image_url, session=session)
new_image = os.path.join(download_directory, f"{filename}") if filename else download_directory new_image = os.path.join(download_directory, f"{filename}") if filename else download_directory
if response.headers["Content-Type"] == "image/jpeg": if response.headers["Content-Type"] == "image/jpeg":
new_image += ".jpg" new_image += ".jpg"
@ -114,8 +114,8 @@ class Requests:
raise Failed(f"URL Error: No file found at {url}") raise Failed(f"URL Error: No file found at {url}")
return YAML(input_data=response.content, check_empty=check_empty) return YAML(input_data=response.content, check_empty=check_empty)
def get_image(self, url): def get_image(self, url, session=None):
response = self.get(url, header=True) response = self.get(url, header=True) if session is None else session.get(url, headers=get_header(None, True, None))
if response.status_code == 404: if response.status_code == 404:
raise Failed(f"Image Error: Not Found on Image URL: {url}") raise Failed(f"Image Error: Not Found on Image URL: {url}")
if response.status_code >= 400: if response.status_code >= 400:

Loading…
Cancel
Save