From 43d5bc68ce0df043db38fb7c726a9a748d2cb943 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 6 Jan 2023 13:46:27 -0500 Subject: [PATCH] test --- tdarr_inform.py | 62 +++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/tdarr_inform.py b/tdarr_inform.py index f887ea2..1971871 100644 --- a/tdarr_inform.py +++ b/tdarr_inform.py @@ -2,34 +2,22 @@ import os import sys +import requests -""" -# title = show title -# season = season # -# fileNameBase is file name without path -# dbName is your tdarr database name -# adjust arrayOrPath to path name of fileNameBase -# tdarr_url = "http://192.168.1.122:8266/api/v2/scan-files" -# payload = {"data": {"scanConfig": { "dbID": dbName, "arrayOrPath": ["/media/TVShows/" + title + "/Season " + season + "/" + fileNameBase[:-3] + '.mkv'], "mode": "scanFolderWatcher"}}} -# headers = {"content-type": "application/json"} -# response = requests.post(tdarr_url, json=payload, headers=headers) -""" +tdarr_settings = { + "url": "http://tdarr-server1.ipa.dbb:8265/api/v2/scan-files", + "dbID": "fGxwT-ws7" + } -""" - { - "data": { - "scanConfig": { - "dbID": "KX7zfikAc", - "arrayOrPath": [ - "/data/shows/file1.mp4", - "/data/shows/file2.mp4", - "/data/shows/file3.mp4", - ], - "mode": "scanFolderWatcher" - } - } -} -""" + +def loggit(logtext): + SCRIPT_PATH = os.path.realpath(__file__) + SCRIPT_DIR = os.path.dirname(SCRIPT_PATH) + log_file = os.path.join(SCRIPT_DIR, "testlog.log") + with open(log_file, 'a') as logwrite: + logwrite.write(logtext) + sys.stdout.write(logtext) + sys.stderr.write(logtext) def main(): @@ -43,7 +31,7 @@ def main(): arr_event_type = os.environ["radarr_eventtype"] arr_file_path_key = "radarr_moviefile_path" - sys.stdout.write("tdarr_inform Recieved %s Event from %s\n" % (arr_event_type, arr_type)) + loggit("tdarr_inform Recieved %s Event from %s\n" % (arr_event_type, arr_type)) if arr_event_type == "Test": sys.exit(0) @@ -53,8 +41,26 @@ def main(): if arr_file_path_key not in os.environ: raise Exception("%s Environment variable was missing." % arr_file_path_key) + arr_file_path = os.environ[arr_file_path_key] - sys.stderr.write("%s\n" % sys.argv) + loggit("Preparing payload to POST to tdarr API\n" % sys.argv) + + headers = {"content-type": "application/json"} + + payload = { + "data": { + "scanConfig": { + "dbID": tdarr_settings["dbID"], + "arrayOrPath": [ + arr_file_path + ], + "mode": "scanFolderWatcher" + } + } + } + + response = requests.post(tdarr_settings["url"], json=payload, headers=headers) + loggit("Tdarr response: %s\n" % response) if __name__ == "__main__":