Skip to content

Commit

Permalink
fix(refactor): Fix some broken references
Browse files Browse the repository at this point in the history
  • Loading branch information
rfsbraz committed Mar 8, 2024
1 parent 91ddeab commit 83242fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
38 changes: 4 additions & 34 deletions app/deleterr.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
# encoding: utf-8

import locale
import time
import os
import requests
import argparse

from datetime import datetime, timedelta
from pyarr.sonarr import SonarrAPI
from pyarr.radarr import RadarrAPI
from app.modules.tautulli import Tautulli
from app.modules.trakt import Trakt
from app import logger
from plexapi.server import PlexServer
from plexapi.exceptions import NotFound
from app.utils import print_readable_freed_space, parse_size_to_bytes
from app.utils import print_readable_freed_space
from app.media_cleaner import MediaCleaner
from app.config import load_config
from pyarr.exceptions import PyarrResourceNotFound, PyarrServerError


DEFAULT_SONARR_SERIES_TYPE = "standard"


class Deleterr:
def __init__(self, config):
self.config = config

self.media_cleaner = MediaCleaner(config)

# Setup connections
self.tautulli = Tautulli(
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 All @@ -54,10 +27,7 @@ def __init__(self, config):
connection["name"]: RadarrAPI(connection["url"], connection["api_key"])
for connection in config.settings.get("radarr", [])
}
self.trakt = Trakt(
config.settings.get("trakt", {}).get("client_id"),
config.settings.get("trakt", {}).get("client_secret"),
)

self.watched_collections = set()

self.process_sonarr()
Expand Down Expand Up @@ -106,7 +76,7 @@ def process_radarr(self):
saved_space = 0
for library in self.config.settings.get("libraries", []):
if library.get("radarr") == name:
saved_space += self.process_library_movies(
saved_space += self.media_cleaner.process_library_movies(
library, radarr, all_movie_data
)

Expand All @@ -123,7 +93,7 @@ def process_sonarr(self):
saved_space = 0
for library in self.config.settings.get("libraries", []):
if library.get("sonarr") == name:
saved_space += self.process_library(
saved_space += self.media_cleaner.process_library(
library, sonarr, unfiltered_all_show_data
)

Expand Down
32 changes: 32 additions & 0 deletions app/media_cleaner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
import requests
import time

from app import logger
from app.utils import print_readable_freed_space, parse_size_to_bytes
from datetime import datetime, timedelta
from plexapi.exceptions import NotFound
from plexapi.server import PlexServer
from app.modules.trakt import Trakt
from app.modules.tautulli import Tautulli

DEFAULT_MAX_ACTIONS_PER_RUN = 10
DEFAULT_SONARR_SERIES_TYPE = "standard"


class MediaCleaner:
def __init__(self, config):
self.config = config

# Setup connections
self.tautulli = Tautulli(
config.settings.get("tautulli").get("url"),
config.settings.get("tautulli").get("api_key"),
)

self.trakt = Trakt(
config.settings.get("trakt", {}).get("client_id"),
config.settings.get("trakt", {}).get("client_secret"),
)

# 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,
)

def get_trakt_items(self, media_type, library):
return self.trakt.get_all_items_for_url(
media_type, library.get("exclude", {}).get("trakt", {})
Expand Down

0 comments on commit 83242fa

Please sign in to comment.