-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorget.py
366 lines (296 loc) · 12.1 KB
/
torget.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# TorGet torrent getter
# made by Apoorv Bandyopdhyay
# A simple cli based application to get the best torrent for your favorate application without all the hassal and irritating pop ups
# Version 1.0 made by python 3.10.8
# Gets the result from 1337x.to(more will be added in the future) make sure the url works on your network
# tested with qbittorrent
#importing libraries
import random
from sqlite3 import DataError
from matplotlib.streamplot import OutOfBounds
import requests
from bs4 import BeautifulSoup
import os
import time
import webbrowser
wipe = ""
url = 'https://1337x.to/home/'
#function to load torrent hompage
def HomePage(url):
os.system(wipe)
try:
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
namelist = soup.find_all(class_="coll-1 name")
datelist = soup.find_all(class_="coll-date")
printlist = SplitList(namelist , datelist)
PrintResult(printlist)
print("\n")
print("-------------------------------------------------------------------------------------")
print(" Press 1 to Select a Torrent for Downloading , Press 2 to go back to main menu")
print("-------------------------------------------------------------------------------------")
print("\n")
print('# 1. Select Torrent')
print('# 2. Back to Menu')
print("\n")
print("\n")
userinput = int(input('# Enter Choice ==> '))
if(userinput == 1 or userinput ==2):
if(userinput == 1):
userinput = int(input('# Select Torrent ==> '))
GetTorrent(userinput ,printlist)
else:
menu()
else:
print('# Invalid Input Press enter to continue')
char = input()
menu()
except Exception:
print('# Unable to load homepage please check connection or run the program again')
char = input('# Press Enter to Continue')
menu()
#function to split text
def SplitList(namelist , datelist):
listsize = len(namelist)
templist = []
for x in range(0,listsize-1):
if (str(namelist[x].text.strip()) == 'name'):
x = x - 1
continue
else:
href = namelist[x].find_all('a', href=True)
infodict = {
'num' : x,
'name' : str(namelist[x].text.strip()),
'date' : str(datelist[x].text.strip()),
'href' : str(href[1]['href'])
};
templist.append(infodict)
return templist
def SearchList(namelist , datelist ):
listsize = len(namelist)
rlist = []
for x in range(0,listsize-1):
if (str(namelist[x].text.strip()) == 'name'):
x = x - 1
continue
else:
href = namelist[x].find_all('a', href=True)
infodict = {
'num' : x,
'name' : str(namelist[x].text.strip()),
'date' : str(datelist[x].text.strip()),
'href' : str(href[1]['href'])
};
rlist.append(infodict)
return rlist
#function to print the result
def PrintResult(printlist):
os.system(wipe)
print('Sno. Name Date')
for x in range(0,len(printlist)-1):
print( " # ",printlist[x]['num'] ," ==> ",printlist[x]['name'][0:-10],"\t",printlist[x]['date'])
#fuction to load torrent page
def GetTorrent(userinput , printlist):
os.system(wipe)
for x in printlist:
if(int(x['num']) == userinput):
TorPage(x['href'] , x['name'])
menu()
#function to set search url
def AdvanceSearch(keyword):
searchlist = []
os.system(wipe)
url = 'https://www.1337x.to/'
searchlist = []
cleanedkeyword = keyword.strip()
cleanedkeyword = cleanedkeyword.replace(" ",'+')
search = 'sort-search/'
sort = 'seeders'
sort_keyword = '/'+ sort + '/desc/'
page = 1
category =''
search = 'sort-category-search/'
print('# Select Search Category')
print('# 1.Movies')
print('# 2.TV')
print('# 3.Games')
print('# 4.Application')
print('# 5.Music')
print('# 6.XXX')
print('# 7.Anime')
print('# 8.Other')
categoryinput = int(input('# Enter Choice ==> '))
print('# Enter sort category')
print('# 1.Seeders')
print('# 2.Time')
print('# 3.Leechers')
print('# 4.Size')
sortinput = int(input('# Enter choice ==> '))
if(categoryinput == 1):
category = 'Movies/'
elif(categoryinput == 2):
category = 'TV/'
elif(categoryinput == 3):
category = 'Games/'
elif(categoryinput == 4):
category = 'Apps/'
elif(categoryinput == 5):
category = 'Music/'
elif(categoryinput == 6):
category = 'XXX/'
elif(categoryinput == 7):
category = 'Anime/'
elif(categoryinput == 8):
category ='Other/'
else:
print("invalid category")
print('# Press Enter to Continue')
char = input()
menu()
if(sortinput == 1):
sort = 'seeders'
elif(sortinput == 2):
sort = 'time'
elif(sortinput == 3):
sort = 'leechers'
elif(sortinput == 4):
sort = 'size'
else:
print("invalid choice sorting by seeders")
sort = 'seeders'
sort_keyword = '/'+ category + sort + '/desc/'
new_url = url + search + cleanedkeyword + sort_keyword + str(page) + '/'
return new_url
#function to get torrent page
def TorPage(torurl , name):
url = 'https://www.1337x.to'
pageurl = url + torurl
response = requests.get(pageurl)
soup = BeautifulSoup(response.text, 'html.parser')
torlist = soup.findAll('ul', {'class' : 'list'})
os.system(wipe)
print('#' + name[0:-10])
print(' ' + torlist[2].text.strip() + '\n')
print(' ' + torlist[1].text.strip() + '\n')
print('\n')
print('-------------------------------------------------------------------------------------------------------')
print('Press 1 to download using a torrent client, Press 2 to Open in Browser, Press 3 to go back to main menu')
print('-------------------------------------------------------------------------------------------------------')
print('\n')
print('# 1. Download')
print('# 2. Open in Browser')
print('# 3. Back to Menu')
userinput = int(input(" # Enter your choice ==> "))
if(userinput == 1):
MagnetDownload(soup)
menu()
elif(userinput == 2):
webbrowser.open(pageurl, new=1, autoraise=True)
menu()
else:
menu()
#funtion for magnet download
def MagnetDownload(soup):
alist = soup.findAll('ul')
atags = alist[4].find_all('a' ,href = True)
href = atags[5]['href']
webbrowser.open(href, new=1, autoraise=True)
#fuction for search page
def SearchPage(keyword):
newurl = AdvanceSearch(keyword)
response = requests.get(newurl)
soup = BeautifulSoup(response.text, 'html.parser')
namelist = soup.find_all(class_="coll-1 name")
datelist = soup.find_all(class_="coll-date")
if(len(namelist) == 0):
print('# Search error please try again later press any key to return to menu')
char = input()
menu()
else:
searchlist = SearchList(namelist , datelist )
PrintResult(searchlist)
print("\n")
print("-------------------------------------------------------------------------------------")
print("Press 1 to Search Again Press 2 ,To select a torrent, 3 To go back to main menu")
print("-------------------------------------------------------------------------------------")
print("\n")
print("# 1. Search again")
print("# 2. Continue")
print('# 3. Go back to Menu')
userinput = int(input("# Enter Choice ==> "))
if(userinput == 1):
keyword = str(input("# Enter Choice ==> "))
SearchPage(keyword)
elif(userinput == 2):
userinput = int(input('# Select Torrent ==> '))
os.system(wipe)
GetTorrent(userinput,searchlist)
else:
menu()
def menu():
#getting os name for screen clear function
name = os.name
wipe = ""
if name == 'nt':
wipe = 'cls'
else:
wipe = 'clear'
while(True):
userinput = 0
os.system(wipe)
asciiGen()
print('# TorGet ==> Hassel free torent getter <==')
print('# Enter Choice ')
print('# 1.Browse')
print('# 2.Search')
print('# 3.Exit')
userinput = int(input('# Input ==> '))
if(userinput == 1):
url = 'https://www.1337x.to/'
url = url + 'home/'
HomePage(url)
elif(userinput == 2):
os.system(wipe)
print('# Please use accurate keywords and select appropriate categories in search for correct results')
userinput = str(input("# Enter Keyword ==> "))
SearchPage(userinput)
elif(userinput == 3):
os.system(wipe)
print('# Thank you for using ')
break;
def checkconnection(url):
try:
requests.get(url)
return print('# Connection Established press enter to continue')
except requests.exceptions.ConnectionError:
print(f"URL {url} not reachable")
def asciiGen():
print(" .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. ")
print(" | .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |")
print(" | | _________ | || | ____ | || | _______ | || | ______ | || | _________ | || | _________ | |")
print(" | | | _ _ | | || | .' `. | || | |_ __ \ | || | .' ___ | | || | |_ ___ | | || | | _ _ | | |")
print(" | | |_/ | | \_| | || | / .--. \ | || | | |__) | | || | / .' \_| | || | | |_ \_| | || | |_/ | | \_| | |")
print(" | | | | | || | | | | | | || | | __ / | || | | | ____ | || | | _| _ | || | | | | |")
print(" | | _| |_ | || | \ `--' / | || | _| | \ \_ | || | \ `.___] _| | || | _| |___/ | | || | _| |_ | |")
print(" | | |_____| | || | `.____.' | || | |____| |___| | || | `._____.' | || | |_________| | || | |_____| | |")
print(" | | | || | | || | | || | | || | | || | | |")
print(" | '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |")
print(" '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' ")
print("By Apoorv Bandyopadhyay")
def main():
os.system(wipe)
asciiGen()
try:
url = 'https://1337x.to/home/'
checkconnection(url)
char = input()
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
menu()
except Exception:
print('# Unable to connect to 1337x check your network or try again')
char = input("Press any key to return to menu")
menu()
if __name__ == '__main__':
main()