-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtorrentcli
87 lines (70 loc) · 2.34 KB
/
torrentcli
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
#!/usr/bin/python3
import requests
import sys
import subprocess
import random
import json
class bg:
PINK = '\033[95m'
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
NORM = '\033[0m'
def get_instances():
instances = list()
instances_json = requests.get("https://raw.githubusercontent.com/hnhx/librex/main/instances.json").content
tmp = json.loads(instances_json)
for i in tmp["instances"]:
instances.append(i["clearnet"])
return instances
def main():
if len(sys.argv) == 1:
sys.exit("Please rerun the command in the format: \n ~ $ torrentcli movie name")
args = sys.argv[1:].copy()
for i in args:
if "-" in i:
args.remove(i)
search = ("+".join(args)).replace(" ", "+")
# sites = ["librex.extravi.dev", "librex.beparanoid.de", "search.davidovski.xyz", "search.funami.tech", "search.madreyk.xyz", "librex.catalyst.sx"]
sites = get_instances()
site = random.choice(sites)
URL = f"{site}api.php?q={search}&p=0&t=3"
data = requests.get(url=URL)
data = data.json()
numberOfOutputs = 8
torrentStream = "vlc"
def output(a):
for i in range(a):
torrent = data[i]
if torrent["seeders"] != 0:
name = str(torrent['name'])
seeders = str(torrent['seeders'])
leechers = str(torrent['leechers'])
size = str(torrent['size'])
source = str(torrent['source'])
print(f"[{i + 1}]{bg.RED} {name} \n ---{bg.GREEN} [se] {seeders} {bg.PINK} [le] {leechers} {bg.BLUE} [size] {size} {bg.YELLOW} [src] {source} {bg.NORM}")
if len(data) < numberOfOutputs:
a = len(data)
else:
a = numberOfOutputs
output(a)
try:
x = int(input("Which torrent would you like? ")) - 1
except ValueError:
print("Please enter a number between 1 and ")
if "1337x" in data[x]['source']:
re = str(f"{site}{data[x]['magnet'][1:]}")
magnet = requests.get(re, allow_redirects=False).headers['location']
else:
magnet = data[x]["magnet"]
print(magnet)
if "-s" in sys.argv:
subprocess.run(torrentStream, magnet)
else:
subprocess.run(["xdg-open", magnet])
try:
main()
except KeyboardInterrupt:
print("Exiting...")