-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDErrortest.py
97 lines (77 loc) · 3.77 KB
/
RDErrortest.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# RDErrortest.py
# originally posted by "Majestyck" on Discord
# https://discord.com/channels/1021692389368283158/1155806221408931881/1156150014096191528
import requests
import time
#import settings
from settings import api_token
import threading
exit_event = threading.Event()
# Replace <apiToken> with your actual API token
#api_token = "<apiToken>"
headers = {"Authorization": f"Bearer {api_token}"}
error_code_25_responses = []
call_interval = 150 # in ms
# Step 1: Get the list of all torrents
torrents_url = "https://api.real-debrid.com/rest/1.0/torrents?limit=2500"
response = requests.get(torrents_url, headers=headers)
torrents = response.json()
def process_torrent(torrent, call_interval=50):
try:
unrestrict_responses = []
links = torrent.get("links", [])
for i in range(len(links)):
# Step 2: Unrestrict each link and include id in the payload
time.sleep(call_interval / 1000)
unrestrict_url = "https://api.real-debrid.com/rest/1.0/unrestrict/link"
payload = {"link": links[i]}
response = requests.post(unrestrict_url, headers=headers, data=payload)
unrestrict_data = response.json()
if("error_code" in unrestrict_data and unrestrict_data["error_code"] in [34,36]):
call_interval += 50
print(f"Error code {unrestrict_data['error_code']}. Increasing call interval to {call_interval}ms and sleeping for 1 minute")
time.sleep(60)
i-=1
continue
unrestrict_responses.append(unrestrict_data)
# Step 3: Fetch media info using the id from the payload for each unrestrict response
media_info_responses = []
media_info_url = f"https://api.real-debrid.com/rest/1.0/streaming/mediaInfos/{unrestrict_data['id']}"
for i in range(len(unrestrict_responses)):
response = requests.get(media_info_url, headers=headers)
media_info = response.json()
if("error_code" in media_info and media_info["error_code"] in [34,36]):
call_interval += 50
print(f"Error code {media_info['error_code']}. Increasing call interval to {call_interval}ms and sleeping for 1 minute")
time.sleep(60)
i-=1
continue
media_info_responses.append(media_info)
return (media_info_responses, unrestrict_responses)
except Exception as err:
print(err)
return ([], [])
def main():
for torrent in torrents :
result = process_torrent(torrent, call_interval)
total_torrents_processed = 0
media_info_responses = result[0]
unrestricted_responses = result[1]
# Check for error_code 25 responses in media info
try:
for i in range(len(media_info_responses)):
media_info = media_info_responses[i]
if "error_code" in media_info:
print(f"{unrestricted_responses[i].get('filename')} can't be streamed")
error_code_25_responses.append(f"[{unrestricted_responses[i].get('id')}] {unrestricted_responses[i].get('filename')}")
# Write the error_code 25 responses to a file
with open("result.txt", "a") as result_file:
result_file.write(f"[{unrestricted_responses[i].get('id')}] {unrestricted_responses[i].get('filename')} \n")
else:
pass
#print(f"OK - {unrestricted_responses[i].get('filename')}")
except Exception as err:
print(err)
print(error_code_25_responses)
if __name__ == "__main__":
main()