forked from ULTRA-OP/ULTRA-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
torrent_search.py
96 lines (87 loc) · 2.57 KB
/
torrent_search.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
"""
Torrent Search Plugin for Userbot. //torrentdownloads.me
cmd: .search search_string
Note: Number of results are currently limited to 15
By:-@Zero_cool7870
"""
from bs4 import BeautifulSoup as bs
import requests
from ULTRA.utils import admin_cmd
import asyncio
import json
from bs4 import BeautifulSoup
from telethon import events
def dogbin(magnets):
counter = 0
urls = []
while counter != len(magnets):
message = magnets[counter]
url = "https://del.dog/documents"
r = requests.post(url, data=message.encode("UTF-8")).json()
url = f"https://del.dog/{r['key']}"
urls.append(url)
counter = counter + 1
return urls
@borg.on(admin_cmd(pattern="tsearch ?(.*)"))
async def tor_search(event):
if event.fwd_from:
return
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'}
search_str = event.pattern_match.group(1)
print(search_str)
await event.edit("Searching for "+search_str+".....")
if " " in search_str:
search_str = search_str.replace(" ","+")
print(search_str)
res = requests.get("https://www.torrentdownloads.me/search/?new=1&s_cat=0&search="+search_str,headers)
else:
res = requests.get("https://www.torrentdownloads.me/search/?search="+search_str,headers)
source = bs(res.text,'lxml')
urls = []
magnets = []
titles = []
counter = 0
for div in source.find_all('div',{'class':'grey_bar3 back_none'}):
# print("https://www.torrentdownloads.me"+a['href'])
try:
title = div.p.a['title']
title = title[20:]
titles.append(title)
urls.append("https://www.torrentdownloads.me"+div.p.a['href'])
except KeyError:
pass
except TypeError:
pass
except AttributeError:
pass
if counter == 15:
break
counter = counter + 1
if not urls:
await event.edit("Either the Keyword was restricted or not found..")
return
print("Found URLS...")
for url in urls:
res = requests.get(url,headers)
# print("URl: "+url)
source = bs(res.text,'lxml')
for div in source.find_all('div',{'class':'grey_bar1 back_none'}):
try:
mg = div.p.a['href']
magnets.append(mg)
except Exception as e:
pass
print("Found Magnets...")
shorted_links = dogbin(magnets)
print("Dogged Magnets to del.dog...")
msg = ""
try:
search_str = search_str.replace("+"," ")
except:
pass
msg = "**Torrent Search Query**\n`{}`".format(search_str)+"\n**Results**\n"
counter = 0
while counter != len(titles):
msg = msg + "⁍ [{}]".format(titles[counter])+"({})".format(shorted_links[counter])+"\n\n"
counter = counter + 1
await event.edit(msg,link_preview=False)