This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
275 lines (266 loc) · 15.1 KB
/
main.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
# (c) @AbirHasan2005 & Jigar Varma & Hemanta Pokharel & Akib Hridoy
import asyncio
from pyrogram import Client, filters
from pyrogram.errors import QueryIdInvalid, FloodWait
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message, InlineQuery, InlineQueryResultArticle, \
InputTextMessageContent
from configs import Config
from tool import SearchYTS, SearchAnime, Search1337x, SearchPirateBay
TorrentBot = Client(session_name=Config.SESSION_NAME, api_id=Config.API_ID, api_hash=Config.API_HASH, bot_token=Config.BOT_TOKEN)
DEFAULT_SEARCH_MARKUP = [
[InlineKeyboardButton("🔎Search YTS", switch_inline_query_current_chat="!yts "),
InlineKeyboardButton("🔎Go Inline", switch_inline_query="!yts ")],
[InlineKeyboardButton("🔎Search ThePirateBay", switch_inline_query_current_chat="!pb "),
InlineKeyboardButton("🔎Go Inline", switch_inline_query="!pb ")],
[InlineKeyboardButton("🔎Search 1337x", switch_inline_query_current_chat=""),
InlineKeyboardButton("🔎Go Inline", switch_inline_query="")],
[InlineKeyboardButton("🔎Search Anime", switch_inline_query_current_chat="!a "),
InlineKeyboardButton("🔎GO Inline", switch_inline_query_current_chat="!a ")],
[InlineKeyboardButton("👨💻Updates channel ", url="https://t.me/SDBOTs_inifinity")]
]
@TorrentBot.on_message(filters.command("start"))
async def start_handler(_, message: Message):
try:
await message.reply_sticker("CAACAgUAAx0CQ2C8OgACGP1g9BHVCewNVakOnudwcNwCr7PrEgACoAMAAgaJYVd9142K-DF9GSAE")
await message.reply_text(
text="😋Hello, I am simple Torrent Search Bot!\n"
"✅I can search Torrent Magnetic Links from Inline.\n\n"
"✅Made by @Darkridersslk ",
disable_web_page_preview=True,
parse_mode="Markdown",
reply_markup=InlineKeyboardMarkup(DEFAULT_SEARCH_MARKUP)
)
except FloodWait as e:
print(f"[{Config.SESSION_NAME}] - Sleeping for {e.x}s")
await asyncio.sleep(e.x)
await start_handler(_, message)
@TorrentBot.on_inline_query()
async def inline_handlers(_, inline: InlineQuery):
search_ts = inline.query
answers = []
if search_ts == "":
answers.append(
InlineQueryResultArticle(
title="Search Something ...",
description="Search For Torrents ...",
input_message_content=InputTextMessageContent(
message_text="Search for Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(DEFAULT_SEARCH_MARKUP)
)
)
elif search_ts.startswith("!pb"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!pb [text]",
description="Search For Torrent in ThePirateBay ...",
input_message_content=InputTextMessageContent(
message_text="`!pb [text]`\n\nSearch ThePirateBay Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!pb ")]])
)
)
else:
torrentList = await SearchPirateBay(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found in ThePirateBay!",
description=f"Can't find torrents for {query} in ThePirateBay !!",
input_message_content=InputTextMessageContent(
message_text=f"No Torrents Found For `{query}` in ThePirateBay !!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!pb ")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeders']}, Leechers: {torrentList[i]['Leechers']}\nSize: {torrentList[i]['Size']}",
input_message_content=InputTextMessageContent(
message_text=f"**🗂Category:** `{torrentList[i]['Category']}`\n"
f"**📝Name:** `{torrentList[i]['Seeders']}`\n"
f"**📊Size:** `{torrentList[i]['Size']}`\n"
f"**📦Seeders:** `{torrentList[i]['Seeders']}`\n"
f"**🔗Leechers:** `{torrentList[i]['Leechers']}`\n"
f"**📤Uploader:** `{torrentList[i]['Uploader']}`\n"
f"**📭Uploaded :** {torrentList[i]['Date']}**\n\n"
f"**🗒Magnet:**\n`{torrentList[i]['Magnet']}`\n\n ✅ Powered By @SDBOTs_inifinity ",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!pb ")]])
)
)
elif search_ts.startswith("!yts"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!yts [text]",
description="Search For Torrent in YTS ...",
input_message_content=InputTextMessageContent(
message_text="`!yts [text]`\n\nSearch YTS Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!yts ")]])
)
)
else:
torrentList = await SearchYTS(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found!",
description=f"Can't find YTS torrents for {query} !!",
input_message_content=InputTextMessageContent(
message_text=f"No YTS Torrents Found For `{query}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!yts ")]])
)
)
else:
for i in range(len(torrentList)):
dl_links = "- " + "\n\n- ".join(torrentList[i]['Downloads'])
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Language: {torrentList[i]['Language']}\nLikes: {torrentList[i]['Likes']}, Rating: {torrentList[i]['Rating']}",
input_message_content=InputTextMessageContent(
message_text=f"**🔐Genre:** `{torrentList[i]['Genre']}`\n"
f"**🏷Name:** `{torrentList[i]['Name']}`\n"
f"**📝Language:** `{torrentList[i]['Language']}`\n"
f"**🖇Likes:** `{torrentList[i]['Likes']}`\n"
f"**🌟Rating:** `{torrentList[i]['Rating']}`\n"
f"**📊Duration:** `{torrentList[i]['Runtime']}`\n"
f"**🗓Released on {torrentList[i]['ReleaseDate']}**\n\n"
f"**🔗Torrent Download Links:**\n{dl_links}\n\n ✅ Powered By @SDBOTs_inifinity",
parse_mode="Markdown",
disable_web_page_preview=True
),
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!yts ")]]),
thumb_url=torrentList[i]["Poster"]
)
)
elif search_ts.startswith("!a"):
query = search_ts.split(" ", 1)[-1]
if (query == "") or (query == " "):
answers.append(
InlineQueryResultArticle(
title="!a [text]",
description="Search For Torrents for Anime ...",
input_message_content=InputTextMessageContent(
message_text="`!a [text]`\n\nSearch Anime Torrents from Inline!",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!a ")]])
)
)
else:
torrentList = await SearchAnime(query)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Anime Torrents Found!",
description=f"Can't find Anime torrents for {query} !!",
input_message_content=InputTextMessageContent(
message_text=f"No Anime Torrents Found For `{query}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="!a ")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeder']}, Leechers: {torrentList[i]['Leecher']}\nSize: {torrentList[i]['Size']}",
input_message_content=InputTextMessageContent(
message_text=f"**🗂Category:** `{torrentList[i]['Category']}`\n"
f"**📝Name:** `{torrentList[i]['Name']}`\n"
f"**📦Seeders:** `{torrentList[i]['Seeder']}`\n"
f"**🔗Leechers:** `{torrentList[i]['Leecher']}`\n"
f"**📊Size:** `{torrentList[i]['Size']}`\n"
f"**📭Uploaded on:** `{torrentList[i]['Date']}`\n\n"
f"**🗒Magnet:** \n`{torrentList[i]['Magnet']}`\n\n✅ Powered By @SDBOTs_inifinity",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="!a ")]]
)
)
)
else:
torrentList = await Search1337x(search_ts)
if not torrentList:
answers.append(
InlineQueryResultArticle(
title="No Torrents Found!",
description=f"Can't find torrents for {search_ts} !!",
input_message_content=InputTextMessageContent(
message_text=f"No Torrents Found For `{search_ts}`",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Try Again", switch_inline_query_current_chat="")]])
)
)
else:
for i in range(len(torrentList)):
answers.append(
InlineQueryResultArticle(
title=f"{torrentList[i]['Name']}",
description=f"Seeders: {torrentList[i]['Seeders']}, Leechers: {torrentList[i]['Leechers']}\nSize: {torrentList[i]['Size']}, Downloads: {torrentList[i]['Downloads']}",
input_message_content=InputTextMessageContent(
message_text=f"**Category:** `{torrentList[i]['Category']}`\n"
f"**Name:** `{torrentList[i]['Name']}`\n"
f"**Language:** `{torrentList[i]['Language']}`\n"
f"**Seeders:** `{torrentList[i]['Seeders']}`\n"
f"**Leechers:** `{torrentList[i]['Leechers']}`\n"
f"**Size:** `{torrentList[i]['Size']}`\n"
f"**Downloads:** `{torrentList[i]['Downloads']}`\n"
f"__Uploaded by {torrentList[i]['UploadedBy']}__\n"
f"__Uploaded {torrentList[i]['DateUploaded']}__\n"
f"__Last Checked {torrentList[i]['LastChecked']}__\n\n"
f"**Magnet:**\n`{torrentList[i]['Magnet']}`\n\n✅ Powered By @SDBOTs_inifinity",
parse_mode="Markdown"
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("🔍Search Again", switch_inline_query_current_chat="")]]
),
thumb_url=torrentList[i]['Poster']
)
)
try:
await inline.answer(
results=answers,
cache_time=0
)
print(f"[{Config.SESSION_NAME}] - Answered Successfully - {inline.from_user.first_name}")
except QueryIdInvalid:
print(f"[{Config.SESSION_NAME}] - Failed to Answer - {inline.from_user.first_name} - Sleeping for 5s")
await asyncio.sleep(5)
try:
await inline.answer(
results=answers,
cache_time=0,
switch_pm_text="Error: Search timed out!",
switch_pm_parameter="start",
)
except QueryIdInvalid:
print(f"[{Config.SESSION_NAME}] - Failed to Answer Error - {inline.from_user.first_name} - Sleeping for 5s")
await asyncio.sleep(5)
TorrentBot.run()