-
Notifications
You must be signed in to change notification settings - Fork 1
/
RealDebridController.py
66 lines (57 loc) · 2.5 KB
/
RealDebridController.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pyinotify
import os
import requests
import time
#Folder this script will watch for torrents/magnets
pathtowatch = "/mnt/local/downloads/torrents"
#Your RealDebrid Api key
rdapikey = ""
wm = pyinotify.WatchManager() # Watch Manager
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE # watched events
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
head, tail = os.path.split(event.pathname)
filename = (tail)
extension = os.path.splitext(filename)[1][1:]
if extension == "torrent":
print("Torrent file detected ",tail)
torrent=(event.pathname)
addtorrenturl = ("https://api.real-debrid.com/rest/1.0/torrents/addTorrent?auth_token="+rdapikey)
with open(torrent, 'rb') as finput:
response = requests.put(addtorrenturl, data=finput.read())
responsefromrd = (response.json())
myid = responsefromrd['id']
head, tail = os.path.split(torrent)
filename=tail
print ("Submitted to RD")
attemptstogetlink=0
rderror=" "
completedtask="No"
time.sleep(2)
selectfiles = ("https://api.real-debrid.com/rest/1.0/torrents/selectFiles/" + myid + "?auth_token=" + rdapikey)
allfiles = {"files": "all"}
response = requests.post(selectfiles, data=allfiles)
elif extension == "magnet":
print("Magnet file detected ",tail)
magnetlink = (event.pathname)
addmagneturl = ("https://api.real-debrid.com/rest/1.0/torrents/addMagnet?auth_token="+ rdapikey)
magnetaddjson = {"magnet": magnet}
response = requests.post(addmagneturl, data=magnetaddjson)
responsefromrd = (response.json())
myid = responsefromrd['id']
head, tail = os.path.split(magnet)
filename = tail
print("Submitted to RD")
attemptstogetlink=0
rderror=" "
completedtask="No"
time.sleep(2)
selectfiles = ("https://api.real-debrid.com/rest/1.0/torrents/selectFiles/" + myid + "?auth_token=" + rdapikey)
allfiles = {"files": "all"}
response = requests.post(selectfiles, data=allfiles)
else:
print("IGNORE Not suitable - " , tail)
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch(pathtowatch, mask, rec=True)
notifier.loop()