68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
#!/usr/bin/python3
|
|
|
|
import os
|
|
import sys
|
|
import requests
|
|
|
|
tdarr_settings = {
|
|
"url": "http://tdarr-server1.ipa.dbb:8265/api/v2/scan-files",
|
|
"dbID": "fGxwT-ws7"
|
|
}
|
|
|
|
|
|
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():
|
|
|
|
if "sonarr_eventtype" in os.environ:
|
|
arr_type = "sonarr"
|
|
arr_event_type = os.environ["sonarr_eventtype"]
|
|
arr_file_path_key = "sonarr_episodefile_path"
|
|
elif "radarr_eventtype" in os.environ:
|
|
arr_type = "radarr"
|
|
arr_event_type = os.environ["radarr_eventtype"]
|
|
arr_file_path_key = "radarr_moviefile_path"
|
|
|
|
loggit("tdarr_inform Recieved %s Event from %s\n" % (arr_event_type, arr_type))
|
|
|
|
if arr_event_type == "Test":
|
|
sys.exit(0)
|
|
|
|
elif arr_event_type not in ["Download", "Rename"]:
|
|
raise Exception("%s is not a supported tdarr_inform Event." % arr_event_type)
|
|
|
|
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]
|
|
|
|
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__":
|
|
main()
|