-
Notifications
You must be signed in to change notification settings - Fork 3
/
sonarr_search.py
executable file
·52 lines (44 loc) · 1.22 KB
/
sonarr_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import sys
import json
import requests
import argparse
import time
import syslog
syslog.syslog('Radarr missing movie search started')
parser = argparse.ArgumentParser(description='Radarr: Initiate missing movie search')
parser.add_argument(
'-v',
'--verbose',
action='store_true',
help='Monitor status until task ends'
)
args = parser.parse_args()
# Radarr server details, in URL format:
baseurl = 'http://localhost/sonarr/'
apikey = '5b00a64dc14a477b84dc8fae1f994776'
h = dict()
h.update({ 'X-Api-Key': apikey })
h.update({ 'accept': 'application/json' })
d = dict()
d.update({ 'name': 'missingEpisodeSearch' })
#d.update({ 'filterKey': 'status' })
#d.update({ 'filterValue': 'released' })
url = baseurl+'api/command'
response = requests.post(url, json=d, headers=h)
if args.verbose == True:
print('Web response: '+str(response.status_code))
count=1
while args.verbose:
response = requests.get(url, headers=h)
data = response.json()
if len(data) == 0:
break
for task in data:
if count >= 4:
print("%s : %s" % (task['name'], task['state']))
count=0
time.sleep(0.6666)
count+=1
if args.verbose == True:
print('Search task complete')