This commit is contained in:
deathbybandaid 2023-01-07 12:11:53 -05:00
parent 3ced053a14
commit 20dad86fc3

View File

@ -26,7 +26,8 @@ expected_paths_env_variables = {
}, },
"radarr": { "radarr": {
"Download": ["radarr_moviefile_path", "radarr_deletedpaths"], "Download": ["radarr_moviefile_path", "radarr_deletedpaths"],
"Rename": ["radarr_moviefile_paths", "radarr_moviefile_previouspaths"] "Rename": ["radarr_moviefile_paths", "radarr_moviefile_previouspaths"],
"MovieDelete": ["radarr_moviefile_paths", "radarr_moviefile_previouspaths"]
}, },
} }
@ -34,11 +35,11 @@ expected_paths_env_variables = {
def loggit(logtext, force_err=False): def loggit(logtext, force_err=False):
if script_settings["logging"]["log_file"]: if script_settings["logging"]["log_file"]:
with open(script_settings["logging"]["log_file_path"], 'a') as logwrite: with open(script_settings["logging"]["log_file_path"], 'a') as logwrite:
logwrite.write(logtext) logwrite.write("%s\n" % logtext)
if script_settings["logging"]["output_level"] or force_err: if script_settings["logging"]["output_level"] or force_err:
sys.stderr.write(logtext) sys.stderr.write("%s\n" % logtext)
else: else:
sys.stdout.write(logtext) sys.stdout.write("%s\n" % logtext)
def do_tdarr_inform(dbID, file_paths): def do_tdarr_inform(dbID, file_paths):
@ -53,7 +54,7 @@ def do_tdarr_inform(dbID, file_paths):
} }
} }
response = requests.post("%s/api/v2/scan-files" % script_settings["tdarr"]["url"], json=payload, headers=headers) response = requests.post("%s/api/v2/scan-files" % script_settings["tdarr"]["url"], json=payload, headers=headers)
loggit("Tdarr response: %s\n" % response.text) loggit("Tdarr response: %s" % response.text)
def do_file_search(arr_file_path): def do_file_search(arr_file_path):
@ -98,7 +99,7 @@ def get_file_path_list(arr):
invalid_keys = [x for x in file_path_env_list if x not in os.environ] invalid_keys = [x for x in file_path_env_list if x not in os.environ]
if len(invalid_keys): if len(invalid_keys):
for x in invalid_keys: for x in invalid_keys:
loggit("%s Environment variable was missing.\n" % x) loggit("%s Environment variable was missing." % x)
sys.exit(1) sys.exit(1)
env_paths = [] env_paths = []
@ -137,7 +138,7 @@ def main():
# What event_type was recieved # What event_type was recieved
arr["event_type"] = os.environ["%s_eventtype" % arr["type"]] arr["event_type"] = os.environ["%s_eventtype" % arr["type"]]
loggit("tdarr_inform Recieved %s Event from %s\n" % (arr["event_type"], arr["type"])) loggit("tdarr_inform Recieved %s Event from %s" % (arr["event_type"], arr["type"]))
# Gracefuilly exit a Test Event # Gracefuilly exit a Test Event
if arr["event_type"] == "Test": if arr["event_type"] == "Test":
@ -157,14 +158,14 @@ def main():
# Dedupe dbID/file_path combinations # Dedupe dbID/file_path combinations
inform_dict = {} inform_dict = {}
for file_path in arr["file_paths"]: for file_path in arr["file_paths"]:
loggit("Event Item: %s\n" % file_path) loggit("Event Item: %s" % file_path)
loggit("Searching tdarr API for item's library ID\n") loggit("Searching tdarr API for item's library ID")
dbID = do_file_search(file_path) dbID = do_file_search(file_path)
if not dbID: if not dbID:
loggit("No exact match found, searching for library ID from Reverse Recursive Directory matching\n") loggit("No exact match found, searching for library ID from Reverse Recursive Directory matching")
dbID = do_reverse_recursive_directory_search(file_path) dbID = do_reverse_recursive_directory_search(file_path)
if not dbID: if not dbID:
loggit("No match found\n") loggit("No match found")
else: else:
if dbID not in list(inform_dict.keys()): if dbID not in list(inform_dict.keys()):
inform_dict[dbID] = [] inform_dict[dbID] = []
@ -172,10 +173,10 @@ def main():
inform_dict[dbID].append(file_path) inform_dict[dbID].append(file_path)
if not len(inform_dict.keys()): if not len(inform_dict.keys()):
loggit("No matches found, Exiting\n") loggit("No matches found, Exiting")
sys.exit(1) sys.exit(1)
loggit("Preparing payload to POST to tdarr API\n") loggit("Preparing payload to POST to tdarr API")
for dbID in list(inform_dict.keys()): for dbID in list(inform_dict.keys()):
do_tdarr_inform(dbID, inform_dict[dbID]) do_tdarr_inform(dbID, inform_dict[dbID])