2021-06-14 01:51:30 +00:00
|
|
|
import logging
|
2021-01-20 21:37:59 +00:00
|
|
|
from modules import util
|
|
|
|
from modules.util import Failed
|
2021-06-14 01:51:30 +00:00
|
|
|
from arrapi import RadarrAPI
|
|
|
|
from arrapi.exceptions import ArrException, Invalid
|
2021-01-20 21:37:59 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("Plex Meta Manager")
|
|
|
|
|
2021-07-23 19:44:21 +00:00
|
|
|
availability_translation = {"announced": "announced", "cinemas": "inCinemas", "released": "released", "db": "preDB"}
|
|
|
|
apply_tags_translation = {"": "add", "sync": "replace", "remove": "remove"}
|
|
|
|
availability_descriptions = {"announced": "For Announced", "cinemas": "For In Cinemas", "released": "For Released", "db": "For PreDB"}
|
2021-04-05 02:25:41 +00:00
|
|
|
|
2021-06-14 01:51:30 +00:00
|
|
|
class Radarr:
|
2021-07-14 14:47:20 +00:00
|
|
|
def __init__(self, config, params):
|
|
|
|
self.config = config
|
2021-04-05 02:25:41 +00:00
|
|
|
self.url = params["url"]
|
2021-04-02 20:15:59 +00:00
|
|
|
self.token = params["token"]
|
2021-01-20 21:37:59 +00:00
|
|
|
try:
|
2021-07-15 22:08:47 +00:00
|
|
|
self.api = RadarrAPI(self.url, self.token, session=self.config.session)
|
2021-11-12 07:23:03 +00:00
|
|
|
self.api.respect_list_exclusions_when_adding()
|
2021-06-14 01:51:30 +00:00
|
|
|
except ArrException as e:
|
|
|
|
raise Failed(e)
|
2021-04-05 02:25:41 +00:00
|
|
|
self.add = params["add"]
|
2021-08-16 05:41:04 +00:00
|
|
|
self.add_existing = params["add_existing"]
|
2021-04-05 02:25:41 +00:00
|
|
|
self.root_folder_path = params["root_folder_path"]
|
|
|
|
self.monitor = params["monitor"]
|
|
|
|
self.availability = params["availability"]
|
2021-06-14 01:51:30 +00:00
|
|
|
self.quality_profile = params["quality_profile"]
|
2021-04-05 02:25:41 +00:00
|
|
|
self.tag = params["tag"]
|
|
|
|
self.search = params["search"]
|
2021-11-24 13:22:17 +00:00
|
|
|
self.radarr_path = "" if params["radarr_path"] and params["plex_path"] else params["radarr_path"]
|
|
|
|
self.plex_path = "" if params["radarr_path"] and params["plex_path"] else params["plex_path"]
|
2021-04-05 02:25:41 +00:00
|
|
|
|
|
|
|
def add_tmdb(self, tmdb_ids, **options):
|
2021-05-24 03:38:46 +00:00
|
|
|
logger.info("")
|
2021-07-03 04:18:09 +00:00
|
|
|
util.separator("Adding to Radarr", space=False, border=False)
|
2021-06-14 01:51:30 +00:00
|
|
|
logger.debug("")
|
2021-11-24 13:22:17 +00:00
|
|
|
for tmdb_id in tmdb_ids:
|
|
|
|
logger.debug(tmdb_id)
|
2021-04-05 02:25:41 +00:00
|
|
|
folder = options["folder"] if "folder" in options else self.root_folder_path
|
|
|
|
monitor = options["monitor"] if "monitor" in options else self.monitor
|
2021-06-14 01:51:30 +00:00
|
|
|
availability = availability_translation[options["availability"] if "availability" in options else self.availability]
|
|
|
|
quality_profile = options["quality"] if "quality" in options else self.quality_profile
|
2021-04-05 02:25:41 +00:00
|
|
|
tags = options["tag"] if "tag" in options else self.tag
|
|
|
|
search = options["search"] if "search" in options else self.search
|
2021-06-14 01:51:30 +00:00
|
|
|
try:
|
2021-08-26 14:35:29 +00:00
|
|
|
added, exists, invalid = self.api.add_multiple_movies(tmdb_ids, folder, quality_profile, monitor, search, availability, tags, per_request=100)
|
2021-06-14 01:51:30 +00:00
|
|
|
except Invalid as e:
|
|
|
|
raise Failed(f"Radarr Error: {e}")
|
|
|
|
|
|
|
|
if len(added) > 0:
|
2021-07-03 01:47:09 +00:00
|
|
|
logger.info("")
|
2021-06-14 01:51:30 +00:00
|
|
|
for movie in added:
|
|
|
|
logger.info(f"Added to Radarr | {movie.tmdbId:<6} | {movie.title}")
|
|
|
|
logger.info(f"{len(added)} Movie{'s' if len(added) > 1 else ''} added to Radarr")
|
|
|
|
|
|
|
|
if len(exists) > 0:
|
2021-07-03 01:47:09 +00:00
|
|
|
logger.info("")
|
2021-06-14 01:51:30 +00:00
|
|
|
for movie in exists:
|
|
|
|
logger.info(f"Already in Radarr | {movie.tmdbId:<6} | {movie.title}")
|
|
|
|
logger.info(f"{len(exists)} Movie{'s' if len(exists) > 1 else ''} already existing in Radarr")
|
|
|
|
|
2021-07-03 04:18:09 +00:00
|
|
|
if len(invalid) > 0:
|
2021-07-03 01:47:09 +00:00
|
|
|
logger.info("")
|
2021-07-03 04:18:09 +00:00
|
|
|
for tmdb_id in invalid:
|
|
|
|
logger.info(f"Invalid TMDb ID | {tmdb_id}")
|
|
|
|
|
2021-11-03 14:36:11 +00:00
|
|
|
return len(added)
|
|
|
|
|
2021-07-03 04:18:09 +00:00
|
|
|
def edit_tags(self, tmdb_ids, tags, apply_tags):
|
|
|
|
logger.info("")
|
|
|
|
logger.info(f"{apply_tags_translation[apply_tags].capitalize()} Radarr Tags: {tags}")
|
|
|
|
|
2021-08-26 14:35:29 +00:00
|
|
|
edited, not_exists = self.api.edit_multiple_movies(tmdb_ids, tags=tags, apply_tags=apply_tags_translation[apply_tags], per_request=100)
|
2021-07-03 04:18:09 +00:00
|
|
|
|
|
|
|
if len(edited) > 0:
|
|
|
|
logger.info("")
|
|
|
|
for movie in edited:
|
|
|
|
logger.info(f"Radarr Tags | {movie.title:<25} | {movie.tags}")
|
|
|
|
logger.info(f"{len(edited)} Movie{'s' if len(edited) > 1 else ''} edited in Radarr")
|
|
|
|
|
|
|
|
if len(not_exists) > 0:
|
|
|
|
logger.info("")
|
|
|
|
for tmdb_id in not_exists:
|
|
|
|
logger.info(f"TMDb ID Not in Radarr | {tmdb_id}")
|