· 6 years ago · Nov 02, 2019, 07:42 PM
1#!/usr/bin/env python3
2
3import os
4import requests
5import json
6import logging
7
8# setup the logger
9LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
10logging.basicConfig(filename = "/var/log/radarr.log", level = logging.INFO, format = LOG_FORMAT)
11logger = logging.getLogger()
12
13# setup the radarr api key
14json_headers = {'X-Api-Key':'<put your key here>'}
15
16# setup the target path
17dl_path = "/downloads"
18files = os.listdir(dl_path)
19
20# build the url for sending commands to the api
21mv_url = "http://192.168.1.100:7878/radarr/api/command"
22
23# loop through the files in the target path
24for file in files:
25 data = dl_path + "/" + file
26 # build the json data payload
27 file_path_json = {"name": "DownloadedMoviesScan", "path": data, "importMode": "Move"}
28 print(json.dumps(file_path_json))
29 # send the json data payload to radarr and move the files to dest folder defined in radarr
30 mv_radarr = requests.post(mv_url, headers=json_headers, data=json.dumps(file_path_json))
31 print(mv_radarr.status_code)
32 # Write out some logging
33 logger.info(json.dumps(file_path_json))