-
Notifications
You must be signed in to change notification settings - Fork 1
/
torrent.py
214 lines (201 loc) · 6.66 KB
/
torrent.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
import datetime
import requests
from bs4 import BeautifulSoup as bs
import cfscrape
from . import *
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 += 1
return urls
@bot.on(d3vil_cmd(pattern=r"tsearch ?(.*)"))
@bot.on(sudo_cmd(pattern=r"tsearch ?(.*)", allow_sudo=True))
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)
d3vil = await eor(event, f"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"}):
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 += 1
if not urls:
await eod(d3vil, "Either the Keyword was restricted or not found..", 7)
return
for url in urls:
res = requests.get(url, headers)
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:
pass
shorted_links = dogbin(magnets)
msg = ""
try:
search_str = search_str.replace("+", " ")
except BaseException:
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 += 1
await d3vil.edit(msg, link_preview=False)
@bot.on(d3vil_cmd(pattern=r"movie (torrentz2\.eu|idop\.se) (.*)"))
@bot.on(sudo_cmd(pattern=r"movie (torrentz2\.eu|idop\.se) (.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
start = datetime.datetime.now()
d3vil = await eor(event, "Processing ...")
input_type = event.pattern_match.group(1)
input_str = event.pattern_match.group(2)
search_results = []
if input_type == "torrentz2.eu":
search_results = search_torrentz_eu(input_str)
elif input_type == "idop.se":
search_results = search_idop_se(input_str)
logger.info(search_results)
output_str = ""
i = 0
for result in search_results:
if i > 10:
break
message_text = (
"👉 <a href=https://t.me/TorrentSearchRoBot?start="
+ result["hash"]
+ ">"
+ result["title"]
+ ": "
+ "</a>"
+ " \r\n"
)
message_text += " FILE SIZE: " + result["size"] + "\r\n"
# message_text += " Uploaded " + result["date"] + "\r\n"
message_text += (
" SEEDS: " + result["seeds"] + " PEERS: " + result["peers"] + " \r\n"
)
message_text += "===\r\n"
output_str += message_text
i += 1
end = datetime.datetime.now()
ms = (end - start).seconds
await d3vil.edit(
f"Scrapped {input_type} for {input_str} in {ms} seconds. Obtained Results: \n {output_str}",
link_preview=False,
parse_mode="html",
)
def search_idop_se(search_query):
r = []
url = "https://idope.se/search/{}/".format(search_query)
raw_json = requests.get(url).json()
results = raw_json["result"]["items"]
for item in results:
# The content scrapped on 24.09.2018 22:56:45
title = item["name"]
t_hash = item["info_hash"]
age = item["create_time"]
size = item["length"]
seeds = str(item["seeds"])
r.append(
{
"title": title,
"hash": t_hash,
"age": age,
"size": humanbytes(size),
"seeds": seeds,
"peers": "NA",
}
)
return r
def search_torrentz_eu(search_query):
r = []
url = "https://torrentz2eu.org/searchA?safe=1&f=" + search_query + ""
scraper = cfscrape.create_scraper() # returns a CloudflareScraper instance
raw_html = scraper.get(url).content
# print(raw_html)
soup = bs(raw_html, "html.parser")
results = soup.find_all("div", {"class": "results"})
# print(results)
if len(results) > 0:
results = results[0]
for item in results.find_all("dl"):
# print(item)
# The content scrapped on 23.06.2018 15:40:35
dt = item.find_all("dt")[0]
dd = item.find_all("dd")[0]
#
try:
link_and_text = dt.find_all("a")[0]
link = link_and_text.get("href")[1:]
title = link_and_text.get_text()
span_elements = dd.find_all("span")
date = span_elements[1].get_text()
size = span_elements[2].get_text()
seeds = span_elements[3].get_text()
peers = span_elements[4].get_text()
#
r.append(
{
"title": title,
"hash": link,
"date": date,
"size": size,
"seeds": seeds,
"peers": peers,
}
)
except BaseException:
pass
return r
CmdHelp("torrent").add_command(
"tsearch", "<query>", "Fetches torrent links of given query"
).add_command(
"movie idop.se", "<query>", "Fetches torrent links of given query alternative way"
).add_command(
"movie torrentz2.eu", "<query>", "Fetches torrent links of given query alternative way"
).add()