test
This commit is contained in:
parent
00c4b3bc7a
commit
27593082d1
@ -1,81 +0,0 @@
|
||||
#!/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("Found %s\n" % arr_file_path)
|
||||
|
||||
loggit("Preparing payload to POST to tdarr API\n")
|
||||
|
||||
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()
|
||||
@ -1,81 +0,0 @@
|
||||
#!/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("Found %s\n" % arr_file_path)
|
||||
|
||||
loggit("Preparing payload to POST to tdarr API\n")
|
||||
|
||||
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()
|
||||
@ -4,9 +4,6 @@ import os
|
||||
import sys
|
||||
import requests
|
||||
|
||||
SCRIPT_PATH = os.path.realpath(__file__)
|
||||
SCRIPT_DIR = os.path.dirname(SCRIPT_PATH)
|
||||
|
||||
"""Edit here"""
|
||||
script_settings = {
|
||||
"tdarr": {
|
||||
@ -14,7 +11,7 @@ script_settings = {
|
||||
},
|
||||
"logging": {
|
||||
"log_file": True,
|
||||
"log_file_path": os.path.join(SCRIPT_DIR, "debug.log"),
|
||||
"log_file_path": os.path.join(os.path.dirname(os.path.realpath(__file__)), "debug.log"),
|
||||
"output_level": 1
|
||||
}
|
||||
}
|
||||
@ -22,10 +19,14 @@ script_settings = {
|
||||
|
||||
expected_paths_env_variables = {
|
||||
"sonarr": {
|
||||
"Download": ["sonarr_episodefile_path", "sonarr_deletedpaths"]
|
||||
"Download": ["sonarr_episodefile_path", "sonarr_deletedpaths"],
|
||||
"Rename": ["sonarr_series_path"],
|
||||
"EpisodeFileDelete": ["sonarr_episodefile_path"],
|
||||
"SeriesDelete": ["sonarr_series_path"]
|
||||
},
|
||||
"radarr": {
|
||||
"Download": ["radarr_moviefile_path", "radarr_deletedpaths"]
|
||||
"Download": ["radarr_moviefile_path", "radarr_deletedpaths"],
|
||||
"Rename": ["radarr_moviefile_paths", "radarr_moviefile_previouspaths"]
|
||||
},
|
||||
}
|
||||
|
||||
@ -41,7 +42,7 @@ def loggit(logtext, force_err=False):
|
||||
|
||||
|
||||
def do_tdarr_inform(dbID, file_paths):
|
||||
# headers = {"content-type": "application/json"}
|
||||
headers = {"content-type": "application/json"}
|
||||
payload = {
|
||||
"data": {
|
||||
"scanConfig": {
|
||||
@ -51,9 +52,8 @@ 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\n" % response.text)
|
||||
print(payload)
|
||||
response = requests.post("%s/api/v2/scan-files" % script_settings["tdarr"]["url"], json=payload, headers=headers)
|
||||
loggit("Tdarr response: %s\n" % response.text)
|
||||
|
||||
|
||||
def do_file_search(arr_file_path):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user