Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed verify ssl for downloading images #2103

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions modules/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class Library(ABC):
def __init__(self, config, params):
self.session = None
self.Radarr = None
self.Sonarr = None
self.Tautulli = None
Expand Down Expand Up @@ -298,7 +299,7 @@ def pick_image(self, title, images, prioritize_assets, download_url_assets, item
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}"]:
Expand All @@ -322,7 +323,7 @@ def find_poster_url(self, item):
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:
Expand Down
8 changes: 4 additions & 4 deletions modules/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,19 @@ def __init__(self, config, params):
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}")
Expand Down
8 changes: 4 additions & 4 deletions modules/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def no_verify_ssl(self, session=None):
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"
Expand All @@ -108,8 +108,8 @@ def get_yaml(self, url, headers=None, params=None, check_empty=False):
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:
Expand Down