-
Notifications
You must be signed in to change notification settings - Fork 1
/
playlist.py
332 lines (306 loc) · 9.59 KB
/
playlist.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
import os
from random import randint
from strings.filters import command
from pykeyboard import InlineKeyboard
from pyrogram import filters
from pyrogram.types import (InlineKeyboardButton,
InlineKeyboardMarkup, Message)
from config import BANNED_USERS, SERVER_PLAYLIST_LIMIT
from strings import get_command
from AnonX import Carbon, YouTube, app
from AnonX.utils.database import (delete_playlist, get_playlist,
get_playlist_names,
save_playlist)
from AnonX.utils.decorators.language import language, languageCB
from AnonX.utils.inline.play import close_keyboard
from AnonX.utils.inline.playlist import (botplaylist_markup,
get_playlist_markup,
warning_markup)
from AnonX.utils.pastebin import Anonbin
from AnonX.utils.stream.stream import stream
# Command
PLAYLIST_COMMAND = get_command("PLAYLIST_COMMAND")
DELETEPLAYLIST_COMMAND = get_command("DELETEPLAYLIST_COMMAND")
@app.on_message(
command(PLAYLIST_COMMAND)
& ~BANNED_USERS
)
@language
async def check_playlist(client, message: Message, _):
_playlist = await get_playlist_names(message.from_user.id)
if _playlist:
get = await message.reply_text(_["playlist_2"])
else:
return await message.reply_text(_["playlist_3"])
msg = _["playlist_4"]
count = 0
for shikhar in _playlist:
_note = await get_playlist(message.from_user.id, shikhar)
title = _note["title"]
title = title.title()
duration = _note["duration"]
count += 1
msg += f"\n\n{count}- {title[:70]}\n"
msg += _["playlist_5"].format(duration)
link = await Anonbin(msg)
lines = msg.count("\n")
if lines >= 17:
car = os.linesep.join(msg.split(os.linesep)[:17])
else:
car = msg
carbon = await Carbon.generate(car, randint(100, 10000000000))
await get.delete()
await message.reply_photo(
carbon, caption=_["playlist_15"].format(link)
)
@app.on_message(
command(DELETEPLAYLIST_COMMAND)
& filters.group
& ~BANNED_USERS
)
@language
async def del_group_message(client, message: Message, _):
upl = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text=_["PL_B_6"],
url=f"https://t.me/{app.username}?start=delplaylists",
),
]
]
)
await message.reply_text(_["playlist_6"], reply_markup=upl)
async def get_keyboard(_, user_id):
keyboard = InlineKeyboard(row_width=5)
_playlist = await get_playlist_names(user_id)
count = len(_playlist)
for x in _playlist:
_note = await get_playlist(user_id, x)
title = _note["title"]
title = title.title()
keyboard.row(
InlineKeyboardButton(
text=title,
callback_data=f"del_playlist {x}",
)
)
keyboard.row(
InlineKeyboardButton(
text=_["PL_B_5"],
callback_data=f"delete_warning",
),
InlineKeyboardButton(
text=_["CLOSE_BUTTON"], callback_data=f"close"
),
)
return keyboard, count
@app.on_message(
filters.command(DELETEPLAYLIST_COMMAND)
& filters.private
& ~filters.edited
& ~BANNED_USERS
)
@language
async def del_plist_msg(client, message: Message, _):
_playlist = await get_playlist_names(message.from_user.id)
if _playlist:
get = await message.reply_text(_["playlist_2"])
else:
return await message.reply_text(_["playlist_3"])
keyboard, count = await get_keyboard(_, message.from_user.id)
await get.edit_text(
_["playlist_7"].format(count), reply_markup=keyboard
)
@app.on_callback_query(filters.regex("play_playlist") & ~BANNED_USERS)
@languageCB
async def play_playlist(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
mode = callback_data.split(None, 1)[1]
user_id = CallbackQuery.from_user.id
_playlist = await get_playlist_names(user_id)
if not _playlist:
try:
return await CallbackQuery.answer(
_["playlist_3"],
show_alert=True,
)
except:
return
chat_id = CallbackQuery.message.chat.id
user_name = CallbackQuery.from_user.first_name
await CallbackQuery.message.delete()
result = []
try:
await CallbackQuery.answer()
except:
pass
video = True if mode == "v" else None
mystic = await CallbackQuery.message.reply_text(_["play_1"])
for vidids in _playlist:
result.append(vidids)
try:
await stream(
_,
mystic,
user_id,
result,
chat_id,
user_name,
CallbackQuery.message.chat.id,
video,
streamtype="playlist",
)
except Exception as e:
ex_type = type(e).__name__
err = (
e
if ex_type == "AssistantErr"
else _["general_3"].format(ex_type)
)
return await mystic.edit_text(err)
return await mystic.delete()
@app.on_callback_query(filters.regex("add_playlist") & ~BANNED_USERS)
@languageCB
async def add_playlist(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
videoid = callback_data.split(None, 1)[1]
user_id = CallbackQuery.from_user.id
_check = await get_playlist(user_id, videoid)
if _check:
try:
return await CallbackQuery.answer(
_["playlist_8"], show_alert=True
)
except:
return
_count = await get_playlist_names(user_id)
count = len(_count)
if count == SERVER_PLAYLIST_LIMIT:
try:
return await CallbackQuery.answer(
_["playlist_9"].format(SERVER_PLAYLIST_LIMIT),
show_alert=True,
)
except:
return
(
title,
duration_min,
duration_sec,
thumbnail,
vidid,
) = await YouTube.details(videoid, True)
title = (title[:50]).title()
plist = {
"videoid": vidid,
"title": title,
"duration": duration_min,
}
await save_playlist(user_id, videoid, plist)
try:
title = (title[:30]).title()
return await CallbackQuery.message.reply_text(
text="❄ sᴜᴄᴄᴇssғᴜʟʟʏ ᴀᴅᴅᴇᴅ ᴛᴏ ᴩʟᴀʏʟɪsᴛ.\n │\n └ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ : {0}".format(CallbackQuery.from_user.mention),
reply_markup=close_keyboard,
)
except:
return
@app.on_callback_query(filters.regex("del_playlist") & ~BANNED_USERS)
@languageCB
async def del_plist(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
videoid = callback_data.split(None, 1)[1]
user_id = CallbackQuery.from_user.id
deleted = await delete_playlist(
CallbackQuery.from_user.id, videoid
)
if deleted:
try:
await CallbackQuery.answer(
_["playlist_11"], show_alert=True
)
except:
pass
else:
try:
return await CallbackQuery.answer(
_["playlist_12"], show_alert=True
)
except:
return
keyboard, count = await get_keyboard(_, user_id)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=keyboard
)
@app.on_callback_query(
filters.regex("delete_whole_playlist") & ~BANNED_USERS
)
@languageCB
async def del_whole_playlist(client, CallbackQuery, _):
_playlist = await get_playlist_names(CallbackQuery.from_user.id)
for x in _playlist:
await delete_playlist(CallbackQuery.from_user.id, x)
return await CallbackQuery.edit_message_text(_["playlist_13"])
@app.on_callback_query(
filters.regex("get_playlist_playmode") & ~BANNED_USERS
)
@languageCB
async def get_playlist_playmode_(client, CallbackQuery, _):
try:
await CallbackQuery.answer()
except:
pass
buttons = get_playlist_markup(_)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
@app.on_callback_query(
filters.regex("delete_warning") & ~BANNED_USERS
)
@languageCB
async def delete_warning_message(client, CallbackQuery, _):
try:
await CallbackQuery.answer()
except:
pass
upl = warning_markup(_)
return await CallbackQuery.edit_message_text(
_["playlist_14"], reply_markup=upl
)
@app.on_callback_query(filters.regex("home_play") & ~BANNED_USERS)
@languageCB
async def home_play_(client, CallbackQuery, _):
try:
await CallbackQuery.answer()
except:
pass
buttons = botplaylist_markup(_)
return await CallbackQuery.edit_message_reply_markup(
reply_markup=InlineKeyboardMarkup(buttons)
)
@app.on_callback_query(
filters.regex("del_back_playlist") & ~BANNED_USERS
)
@languageCB
async def del_back_playlist(client, CallbackQuery, _):
user_id = CallbackQuery.from_user.id
_playlist = await get_playlist_names(user_id)
if _playlist:
try:
await CallbackQuery.answer(
_["playlist_2"], show_alert=True
)
except:
pass
else:
try:
return await CallbackQuery.answer(
_["playlist_3"], show_alert=True
)
except:
return
keyboard, count = await get_keyboard(_, user_id)
return await CallbackQuery.edit_message_text(
_["playlist_7"].format(count), reply_markup=keyboard
)