test
This commit is contained in:
parent
ce83a6b1fd
commit
1279baaa8b
80
radarr_to_tdarr.py
Normal file
80
radarr_to_tdarr.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
SCRIPT_PATH = os.path.realpath(__file__)
|
||||||
|
SCRIPT_DIR = os.path.dirname(SCRIPT_PATH)
|
||||||
|
|
||||||
|
script_settings = {
|
||||||
|
"tdarr": {
|
||||||
|
"url": "http://tdarr-server1.ipa.dbb:8265/api/v2/scan-files",
|
||||||
|
"dbID": "c9eH2A9AP"
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"log_file": True,
|
||||||
|
"log_file_path": os.path.join(SCRIPT_DIR, "debug.log"),
|
||||||
|
"output_level": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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(logtext)
|
||||||
|
if script_settings["logging"]["output_level"] or force_err:
|
||||||
|
sys.stderr.write(logtext)
|
||||||
|
else:
|
||||||
|
sys.stdout.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"
|
||||||
|
else:
|
||||||
|
loggit("Could not Detect Radarr or Sonarr", True)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
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"]:
|
||||||
|
loggit("%s is not a supported tdarr_inform Event." % arr_event_type, True)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if arr_file_path_key not in os.environ:
|
||||||
|
loggit("%s Environment variable was missing." % arr_file_path_key, True)
|
||||||
|
sys.exit(1)
|
||||||
|
arr_file_path = os.environ[arr_file_path_key]
|
||||||
|
|
||||||
|
loggit("Preparing payload to POST to tdarr API\n" % sys.argv)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"data": {
|
||||||
|
"scanConfig": {
|
||||||
|
"dbID": script_settings["tdarr"]["dbID"],
|
||||||
|
"arrayOrPath": [
|
||||||
|
arr_file_path
|
||||||
|
],
|
||||||
|
"mode": "scanFolderWatcher"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
headers = {"content-type": "application/json"}
|
||||||
|
response = requests.post(script_settings["tdarr"]["url"], json=payload, headers=headers)
|
||||||
|
loggit("Tdarr response: %s\n" % response)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
80
sonarr_to_tdarr.py
Normal file
80
sonarr_to_tdarr.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
SCRIPT_PATH = os.path.realpath(__file__)
|
||||||
|
SCRIPT_DIR = os.path.dirname(SCRIPT_PATH)
|
||||||
|
|
||||||
|
script_settings = {
|
||||||
|
"tdarr": {
|
||||||
|
"url": "http://tdarr-server1.ipa.dbb:8265/api/v2/scan-files",
|
||||||
|
"dbID": "fGxwT-ws7"
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"log_file": True,
|
||||||
|
"log_file_path": os.path.join(SCRIPT_DIR, "debug.log"),
|
||||||
|
"output_level": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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(logtext)
|
||||||
|
if script_settings["logging"]["output_level"] or force_err:
|
||||||
|
sys.stderr.write(logtext)
|
||||||
|
else:
|
||||||
|
sys.stdout.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"
|
||||||
|
else:
|
||||||
|
loggit("Could not Detect Radarr or Sonarr", True)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
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"]:
|
||||||
|
loggit("%s is not a supported tdarr_inform Event." % arr_event_type, True)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if arr_file_path_key not in os.environ:
|
||||||
|
loggit("%s Environment variable was missing." % arr_file_path_key, True)
|
||||||
|
sys.exit(1)
|
||||||
|
arr_file_path = os.environ[arr_file_path_key]
|
||||||
|
|
||||||
|
loggit("Preparing payload to POST to tdarr API\n" % sys.argv)
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"data": {
|
||||||
|
"scanConfig": {
|
||||||
|
"dbID": script_settings["tdarr"]["dbID"],
|
||||||
|
"arrayOrPath": [
|
||||||
|
arr_file_path
|
||||||
|
],
|
||||||
|
"mode": "scanFolderWatcher"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
headers = {"content-type": "application/json"}
|
||||||
|
response = requests.post(script_settings["tdarr"]["url"], json=payload, headers=headers)
|
||||||
|
loggit("Tdarr response: %s\n" % response)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user