arr_to_tdarr/tdarr_inform.py
deathbybandaid e2cbeee40b test
2023-01-06 12:57:18 -05:00

76 lines
2.1 KiB
Python

#!/usr/bin/python3
import os
# from sys import argv
"""
# 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)
"""
"""
{
"data": {
"scanConfig": {
"dbID": "KX7zfikAc",
"arrayOrPath": [
"/data/shows/file1.mp4",
"/data/shows/file2.mp4",
"/data/shows/file3.mp4",
],
"mode": "scanFolderWatcher"
}
}
}
"""
# fp = open('/opt/testlog.log', 'a', 0)
# fp.write("Testing")
# fp.write("%s" % argv)
def main():
SCRIPT_PATH = os.path.realpath(__file__)
SCRIPT_DIR = os.path.dirname(SCRIPT_PATH)
log_file = os.path.join(SCRIPT_DIR, "testlog.log")
logwrite = open(log_file, 'a')
if "sonarr_eventtype" in os.environ:
arr_type = "sonarr"
elif "radarr_eventtype" in os.environ:
arr_type = "radarr"
logwrite.write("Recieved %s Event from %s\n" % ("%s_eventtype" % arr_type, arr_type.upper()))
ENV_FILE = os.path.join(SCRIPT_DIR, "env_%s" % arr_type)
logwrite.write("%s\n" % ENV_FILE)
envs = {}
# Checking all potentiall environment variables
with open(ENV_FILE, 'r') as f:
for line in f:
env = line.rstrip()
if env in os.environ:
envs[env] = os.environ[env]
logwrite.write("%s %s" % (env, envs[env]))
# No environment variables were found
# Either the script was run manually as a test (ie Not ran by *arr)
# or, something went wrong : )
# if len(envs) == 0:
# raise Exception('No *arr Environment variables were found.')
logwrite.close()
if __name__ == "__main__":
main()