Compare commits

..

No commits in common. "9a2b3d0b39c9f4ab0702a2108d2e3f8996d56a4c" and "3ced053a1436a4b6c808cb4dea53ac09f637077e" have entirely different histories.

View File

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