Created
October 19, 2020 19:51
-
-
Save henryjfry/ba2c4244324fedea1d93f2054c864a36 to your computer and use it in GitHub Desktop.
realdebrid api magnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
import json | |
import time | |
import sys | |
# | |
#/home/osmc/scripts/magnet.py "magnet:?xt=urn:btih:3e0a8674e7e2dba675c5073455d79b9e89d47955&dn=The.West.Wing.S07.1080p.WEB-DL.AAC2.0.H.264-NTb%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2950&tr=udp%3A%2F%2F9.rarbg.to%3A2900" -s 13 | |
# | |
header = {'Authorization': 'Bearer ' + 'REALDEBRID_API_TOKEN'} | |
count_list = '' | |
start = 1 | |
flag_s = False | |
flag_l = False | |
for x in sys.argv: | |
if "magnet" in x: | |
magnet_link = x | |
if "-l" in x: | |
count_list = sys.argv[sys.argv.index(x) + 1] | |
count_list = count_list.split(',') | |
flag_l = True | |
if "-s" in x: | |
start = int(sys.argv[sys.argv.index(x) + 1]) + 1 | |
flag_s = True | |
if flag_l == False and flag_s == False: | |
flag_s = True | |
params = {'magnet': magnet_link} | |
response = requests.post('https://api.real-debrid.com/rest/1.0/torrents/addMagnet?', headers=header, data=params) | |
data = response.json() | |
torr_id = data.get('id') | |
print data | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/info/' + torr_id, headers=header) | |
data = response.json() | |
ids = [element['id'] for element in data['files']] | |
files = [element['path'] for element in data['files']] | |
files = [x.encode('utf-8') for x in files] | |
tot_files = ids[-1] | |
response = requests.delete('https://api.real-debrid.com/rest/1.0/torrents/delete/' + torr_id, headers=header) | |
print(response) | |
files, ids = zip(*sorted(zip(files,ids))) | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/activeCount', headers=header) | |
active_downloads = response.json().get('nb') | |
print('Total Active Downloads ' + str(active_downloads)) | |
if active_downloads >= 24 and count_list == '': | |
exit() | |
count = 1 | |
extensions = ['mkv', 'mp4', 'avi'] | |
for x in files: | |
if not any(s in str(x) for s in extensions): | |
#count = count + 1 | |
continue | |
if any(s in str(x) for s in extensions) and str(count) in count_list and flag_l == True: | |
params = {'magnet': magnet_link} | |
response = requests.post('https://api.real-debrid.com/rest/1.0/torrents/addMagnet?', headers=header, data=params) | |
data = response.json() | |
torr_id = data.get('id') | |
params = {'files': ids[files.index(x)]} | |
response = requests.post('https://api.real-debrid.com/rest/1.0/torrents/selectFiles/' + torr_id, headers=header, data=params) | |
print(response) | |
print(x) | |
print('file number: ' + str(count)) | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/info/' + torr_id + '?', headers=header) | |
data = response.json() | |
print(data.get('links')) | |
if data.get('status') == "downloaded": | |
link_url = data.get('links') | |
params = {'link': link_url } | |
response = requests.post('https://api.real-debrid.com/rest/1.0/unrestrict/link', headers=header, data=params) | |
print(response) | |
if data.get('progress') < 1: | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/activeCount', headers=header) | |
active_downloads = response.json().get('nb') | |
print('Total Active Downloads ' + str(active_downloads)) | |
if active_downloads >= 24: | |
exit() | |
time.sleep(5) | |
count = count + 1 | |
continue | |
if any(s in str(x) for s in extensions) and count >= int(start) - 1 and flag_s == True: | |
params = {'magnet': magnet_link} | |
response = requests.post('https://api.real-debrid.com/rest/1.0/torrents/addMagnet?', headers=header, data=params) | |
data = response.json() | |
torr_id = data.get('id') | |
params = {'files': ids[files.index(x)]} | |
response = requests.post('https://api.real-debrid.com/rest/1.0/torrents/selectFiles/' + torr_id, headers=header, data=params) | |
print(response) | |
print(x) | |
print('file number: ' + str(count)) | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/info/' + torr_id + '?', headers=header) | |
data = response.json() | |
print(data.get('links')) | |
if data.get('status') == "downloaded": | |
link_url = data.get('links') | |
params = {'link': link_url } | |
response = requests.post('https://api.real-debrid.com/rest/1.0/unrestrict/link', headers=header, data=params) | |
print(response) | |
if data.get('progress') < 1: | |
response = requests.get('https://api.real-debrid.com/rest/1.0/torrents/activeCount', headers=header) | |
active_downloads =response.json().get('nb') | |
print('Total Active Downloads ' + str(active_downloads)) | |
if active_downloads >= 24: | |
exit() | |
time.sleep(5) | |
count = count + 1 | |
continue | |
else: | |
count = count + 1 | |
#print(count) | |
#print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment