Skip to content

Commit

Permalink
Merge pull request #73 from rfsbraz/fix/69-plex-ssl
Browse files Browse the repository at this point in the history
Disable certificate verication to support local secured connections
  • Loading branch information
rfsbraz authored Feb 19, 2024
2 parents 1377c4b + a9ded2c commit cb444b0
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions app/deleterr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import locale
import time
import os
import yaml
import sys
import requests

from datetime import datetime, timedelta
from pyarr.sonarr import SonarrAPI
Expand All @@ -19,11 +18,13 @@
from app.config import load_config
from pyarr.exceptions import PyarrResourceNotFound, PyarrServerError


logging.basicConfig()

DEFAULT_MAX_ACTIONS_PER_RUN = 10
DEFAULT_SONARR_SERIES_TYPE = "standard"


class Deleterr:
def __init__(self, config):
self.config = config
Expand All @@ -33,11 +34,18 @@ def __init__(self, config):
config.settings.get("tautulli").get("url"),
config.settings.get("tautulli").get("api_key"),
)

# Disable SSL verification to support required secure connections
# Certificates are not always valid for local connections
session = requests.Session()
session.verify = False
self.plex = PlexServer(
config.settings.get("plex").get("url"),
config.settings.get("plex").get("token"),
timeout=120,
session=session,
)

self.sonarr = {
connection["name"]: SonarrAPI(connection["url"], connection["api_key"])
for connection in config.settings.get("sonarr", [])
Expand Down Expand Up @@ -510,9 +518,7 @@ def is_movie_actionable(
return False

for label in exclude.get("plex_labels", []):
if label.lower() in (
g.tag.lower() for g in plex_media_item.labels
):
if label.lower() in (g.tag.lower() for g in plex_media_item.labels):
logger.debug(
f"{media_data['title']} has excluded label {label}, skipping"
)
Expand Down Expand Up @@ -655,9 +661,11 @@ def sort_key(media_item):
return media_item.get("added", "")
elif sort_field == "rating":
ratings = media_item.get("ratings", {})
return ratings.get("imdb", {}).get("value", 0) or ratings.get(
"tmdb", {}
).get("value", 0) or ratings.get("value", 0)
return (
ratings.get("imdb", {}).get("value", 0)
or ratings.get("tmdb", {}).get("value", 0)
or ratings.get("value", 0)
)
elif sort_field == "seasons":
return media_item.get("statistics", {}).get("seasonCount", 1)
elif sort_field == "episodes":
Expand All @@ -668,15 +676,17 @@ def sort_key(media_item):
sorted_media = sorted(media_list, key=sort_key, reverse=(sort_order == "desc"))
return sorted_media


def get_file_contents(file_path):
try:
with open(file_path, 'r') as file:
with open(file_path, "r") as file:
return file.read().strip()
except FileNotFoundError:
print(f"File not found: {file_path}")
except IOError as e:
print(f"Error reading file {file_path}: {e}")


def main():
"""
Deleterr application entry point. Parses arguments, configs and
Expand All @@ -700,4 +710,4 @@ def main():


if __name__ == "__main__":
main()
main()

0 comments on commit cb444b0

Please sign in to comment.