diff --git a/tdarr_inform.py b/tdarr_inform.py index f71441e..b567a77 100644 --- a/tdarr_inform.py +++ b/tdarr_inform.py @@ -44,6 +44,24 @@ def do_tdarr_inform(dbID, arr_file_path): } } response = requests.post("%s/api/v2/scan-files" % script_settings["tdarr"]["url"], json=payload, headers=headers) + loggit("Tdarr response: %s\n" % response) + + +def do_file_search(arr_file_path): + payload = { + "data": { + "string": arr_file_path, + "lessThanGB": 9999, + "greaterThanGB": 0 + } + } + headers = {"content-type": "application/json"} + response = requests.post("%s/api/v2/search-db" % script_settings["tdarr"]["url"], json=payload, headers=headers) + loggit("Tdarr response: %s\n" % response) + try: + DBid = response.json()[0]["DB"] + except Exception: + return None def main(): @@ -86,24 +104,16 @@ def main(): # sys.exit(1) # arr_file_path = os.environ[arr_file_path_key] arr_file_path = "/Drivepool/Media/TV/Cartoons/Ben 10 (2016)/Season 2/Ben 10 (2016) - S02E31 - Chicken Nuggets of Wisdom.mkv" - loggit("Found %s\n" % arr_file_path) + loggit("Event Item: %s\n" % arr_file_path) # loggit("Preparing payload to POST to tdarr API\n") loggit("Searching tdarr API for item's library ID\n") - - payload = { - "data": { - "string": arr_file_path, - "lessThanGB": 9999, - "greaterThanGB": 0 - } - } - headers = {"content-type": "application/json"} - response = requests.post("%s/api/v2/search-db" % script_settings["tdarr"]["url"], json=payload, headers=headers) - - loggit("Tdarr response: %s\n" % response) - print(response.json()[0]["DB"]) + DBid = do_file_search(arr_file_path) + if not DBid: + loggit("No exact match found, searching for library ID from Reverse Recursive Directory matching\n") + else: + print(DBid) if __name__ == "__main__":