diff --git a/app/deleterr.py b/app/deleterr.py index 7d6703a..54c2dac 100644 --- a/app/deleterr.py +++ b/app/deleterr.py @@ -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 @@ -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 @@ -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", []) @@ -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" ) @@ -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": @@ -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 @@ -700,4 +710,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main()