This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Phub.py
297 lines (278 loc) · 10.2 KB
/
Phub.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
# Disclaimer:
# This Repo is just an working case of ARQ API with Pyrogram.
# Telegram May ban your bot or your account since Porns aren't allowed in Telegram.
# We aren't reponsible for Your causes....Use with caution...
# We recommend you to use Alt account.
# For support https://t.me/PatheticProgrammers
import os
from aiohttp import ClientSession
from pyrogram import filters, Client
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, InputMediaPhoto, InputMediaVideo
from Python_ARQ import ARQ
from asyncio import get_running_loop
from wget import download
# Config Check-----------------------------------------------------------------
if os.path.exists("config.py"):
from config import *
elif os.path.exists("sample_config.py"):
from sample_config import *
else:
raise Exception("Your Config File Is Invalid or Maybe Doesn't Exist! Please Check Your Config File or Try Again.")
# ARQ API and Bot Initialize---------------------------------------------------
session = ClientSession()
arq = ARQ("https://thearq.tech", ARQ_API_KEY, session)
pornhub = arq.pornhub
phdl = arq.phdl
app = Client("Tg_PHub_Bot", bot_token=Bot_token, api_id=6,
api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e")
print("\nBot Started!...\n")
db = {}
async def download_url(url: str):
loop = get_running_loop()
file = await loop.run_in_executor(None, download, url)
return file
async def time_to_seconds(time):
stringt = str(time)
return sum(
int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":")))
)
# Start -----------------------------------------------------------------------
@app.on_message(
filters.command("start") & ~filters.edited
)
async def start(_, message):
m= await message.reply_text(
text = "Hi Iam Tg_PHub_Bot.You can Download Videos from PHub upto 1080p !"
)
# Help-------------------------------------------------------------------------
@app.on_message(
filters.command("help") & ~filters.edited
)
async def help(_, message):
await message.reply_text(
"""**Below are My Commands...**
/help To Show This Message.
/repo To Get the Repo.
To Search in PHub just simply Type something"""
)
# Repo -----------------------------------------------------------------------
@app.on_message(
filters.command("repo") & ~filters.edited
)
async def repo(_, message):
m= await message.reply_text(
text="""[Tg_PHub_Bot Repo](https://github.com/Devanagaraj/Tg_PHub_Bot) | [Support Group](https://t.me/PatheticProgrammers)""",
disable_web_page_preview=True
)
# Let's Go----------------------------------------------------------------------
@app.on_message(
filters.private & ~filters.edited & ~filters.command("help") & ~filters.command("start") & ~filters.command("repo")
)
async def sarch(_,message):
try:
if "/" in message.text.split(None,1)[0]:
await message.reply_text(
"**Usage:**\nJust type Something to search in PHub Directly"
)
return
except:
pass
m = await message.reply_text("Getting Results.....")
search = message.text
try:
resp = await pornhub(search,thumbsize="large")
res = resp.result
except:
await m.edit("Found Nothing... Try again")
return
if not resp.ok:
await m.edit("Found Nothing... Try again")
return
resolt = f"""
**Title:** {res[0].title}
**views:** {res[0].views}
**rating:** {res[0].rating}"""
await m.delete()
m = await message.reply_photo(
photo=res[0].thumbnails[0].src,
caption=resolt,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton("Next",
callback_data="next"),
InlineKeyboardButton("Delete",
callback_data="delete"),
],
[
InlineKeyboardButton("Download",
callback_data="dload")
]
]
),
parse_mode="markdown",
)
new_db={"result":res,"curr_page":0}
db[message.chat.id] = new_db
# Next Button--------------------------------------------------------------------------
@app.on_callback_query(filters.regex("next"))
async def callback_query_next(_, query):
m = query.message
try:
data = db[query.message.chat.id]
except:
await m.edit("Something Wrong ..... **Search Again**")
return
res = data['result']
curr_page = int(data['curr_page'])
cur_page = curr_page+1
db[query.message.chat.id]['curr_page'] = cur_page
if len(res) <= (cur_page+1):
cbb = [
[
InlineKeyboardButton("Previous",
callback_data="previous"),
InlineKeyboardButton("Download",
callback_data="dload"),
],
[
InlineKeyboardButton("Delete",
callback_data="delete"),
]
]
else:
cbb = [
[
InlineKeyboardButton("Previous",
callback_data="previous"),
InlineKeyboardButton("Next",
callback_data="next"),
],
[
InlineKeyboardButton("Delete",
callback_data="delete"),
InlineKeyboardButton("Download",
callback_data="dload")
]
]
resolt = f"""
**Title:** {res[cur_page].title}
**views:** {res[cur_page].views}
**rating:** {res[cur_page].rating}"""
await m.edit_media(media=InputMediaPhoto(res[cur_page].thumbnails[0].src))
await m.edit(
resolt,
reply_markup=InlineKeyboardMarkup(cbb),
parse_mode="markdown",
)
# Previous Button--------------------------------------------------------------------------
@app.on_callback_query(filters.regex("previous"))
async def callback_query_next(_, query):
m = query.message
try:
data = db[query.message.chat.id]
except:
await m.edit("Something Wrong ..... **Search Again**")
return
res = data['result']
curr_page = int(data['curr_page'])
cur_page = curr_page-1
db[query.message.chat.id]['curr_page'] = cur_page
if cur_page != 0:
cbb=[
[
InlineKeyboardButton("Previous",
callback_data="previous"),
InlineKeyboardButton("Next",
callback_data="next"),
],
[
InlineKeyboardButton("Delete",
callback_data="delete"),
InlineKeyboardButton("Download",
callback_data="dload")
]
]
else:
cbb=[
[
InlineKeyboardButton("Next",
callback_data="next"),
InlineKeyboardButton("Delete",
callback_data="Delete"),
],
[
InlineKeyboardButton("Download",
callback_data="dload")
]
]
resolt = f"""
**Title:** {res[cur_page].title}
**views:** {res[cur_page].views}
**rating:** {res[cur_page].rating}"""
await m.edit_media(media=InputMediaPhoto(res[cur_page].thumbnails[0].src))
await m.edit(
resolt,
reply_markup=InlineKeyboardMarkup(cbb),
parse_mode="markdown",
)
# Download Button--------------------------------------------------------------------------
@app.on_callback_query(filters.regex("dload"))
async def callback_query_next(_, query):
m = query.message
data = db[m.chat.id]
res = data['result']
curr_page = int(data['curr_page'])
dl_links = await phdl(res[curr_page].url)
db[m.chat.id]['result'] = dl_links.result.video
db[m.chat.id]['thumb'] = res[curr_page].thumbnails[0].src
db[m.chat.id]['dur'] = res[curr_page].duration
resolt = f"""
**Title:** {res[curr_page].title}
**views:** {res[curr_page].views}
**rating:** {res[curr_page].rating}"""
pos = 1
cbb = []
for resolts in dl_links.result.video:
b= [InlineKeyboardButton(f"{resolts.quality} - {resolts.size}", callback_data=f"phubdl {pos}")]
pos += 1
cbb.append(b)
cbb.append([InlineKeyboardButton("Delete", callback_data="delete")])
await m.edit(
resolt,
reply_markup=InlineKeyboardMarkup(cbb),
parse_mode="markdown",
)
# Download Button 2--------------------------------------------------------------------------
@app.on_callback_query(filters.regex(r"^phubdl"))
async def callback_query_dl(_, query):
m = query.message
capsion = m.caption
entoty = m.caption_entities
await m.edit(f"**Downloading Now :\n\n{capsion}")
data = db[m.chat.id]
res = data['result']
curr_page = int(data['curr_page'])
thomb = await download_url(data['thumb'])
durr = await time_to_seconds(data['dur'])
pos = int(query.data.split()[1])
pos = pos-1
try:
vid = await download_url(res[pos].url)
except Exception as e:
print(e)
await m.edit("Oops Download Error... Try again")
return
await m.edit(f"**Uploading Now :\n\n'''{capsion}'''")
await app.send_chat_action(m.chat.id, "upload_video")
await m.edit_media(media=InputMediaVideo(vid,thumb=thomb, duration=durr, supports_streaming=True))
await m.edit_caption(caption=capsion, caption_entities=entoty)
if os.path.isfile(vid):
os.remove(vid)
if os.path.isfile(thomb):
os.remove(thomb)
# Delete Button--------------------------------------------------------------------------
@app.on_callback_query(filters.regex("delete"))
async def callback_query_delete(_, query):
await query.message.delete()
app.run()