From dcf0435a968d636250babf482c11cf14473f3930 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 6 Jun 2024 12:50:11 -0400 Subject: [PATCH] [4] Fixed verify ssl for downloading images (#2103) --- VERSION | 2 +- modules/library.py | 5 +++-- modules/plex.py | 8 ++++---- modules/request.py | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 170de0b5..2b6a6f61 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.2-build3 +2.0.2-build4 diff --git a/modules/library.py b/modules/library.py index 3f909138..40410e43 100644 --- a/modules/library.py +++ b/modules/library.py @@ -11,6 +11,7 @@ logger = util.logger class Library(ABC): def __init__(self, config, params): + self.session = None self.Radarr = None self.Sonarr = None self.Tautulli = None @@ -298,7 +299,7 @@ class Library(ABC): return images["asset_directory"] else: 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: logger.error(e) if attr in ["asset_directory", f"pmm_{image_type}"]: @@ -322,7 +323,7 @@ class Library(ABC): pass 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): time.sleep(1) with Image.open(image_path) as image: diff --git a/modules/plex.py b/modules/plex.py index a307d6a8..53c354d7 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -447,19 +447,19 @@ class Plex(Library): super().__init__(config, params) self.plex = params["plex"] 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: 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: 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.timeout = self.plex["timeout"] logger.secret(self.url) logger.secret(self.token) 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 os.environ["PLEXAPI_PLEXAPI_TIMEOUT"] = str(self.timeout) logger.info(f"Connected to server {self.PlexServer.friendlyName} version {self.PlexServer.version}") diff --git a/modules/request.py b/modules/request.py index 4234cce9..97537272 100644 --- a/modules/request.py +++ b/modules/request.py @@ -92,8 +92,8 @@ class Requests: import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - def download_image(self, title, image_url, download_directory, is_poster=True, filename=None): - response = self.get_image(image_url) + def download_image(self, title, image_url, download_directory, session=None, is_poster=True, filename=None): + response = self.get_image(image_url, session=session) new_image = os.path.join(download_directory, f"{filename}") if filename else download_directory if response.headers["Content-Type"] == "image/jpeg": new_image += ".jpg" @@ -114,8 +114,8 @@ class Requests: raise Failed(f"URL Error: No file found at {url}") return YAML(input_data=response.content, check_empty=check_empty) - def get_image(self, url): - response = self.get(url, header=True) + def get_image(self, url, session=None): + 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: raise Failed(f"Image Error: Not Found on Image URL: {url}") if response.status_code >= 400: