-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue.py
334 lines (314 loc) · 10.8 KB
/
queue.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
333
334
import asyncio
import os
from random import randint
from strings.filters import command
from pyrogram import filters
from pyrogram.errors import FloodWait
from pyrogram.types import CallbackQuery, InputMediaPhoto, Message
import config
from config import BANNED_USERS
from strings import get_command
from AnonX import app
from AnonX.misc import db
from AnonX.utils import (Anonbin, get_channeplayCB,
seconds_to_min)
from AnonX.utils.database import (get_cmode, is_active_chat,
is_music_playing)
from AnonX.utils.decorators.language import language, languageCB
from AnonX.utils.inline import queue_back_markup, queue_markup
###Commands
QUEUE_COMMAND = get_command("QUEUE_COMMAND")
basic = {}
def get_image(videoid, user_id):
if os.path.isfile(f"cache/{videoid}_{user_id}.png"):
return f"cache/{videoid}_{user_id}.png"
else:
return config.YOUTUBE_IMG_URL
def get_duration(playing):
file_path = playing[0]["file"]
if "index_" in file_path or "live_" in file_path:
return "Unknown"
duration_seconds = int(playing[0]["seconds"])
if duration_seconds == 0:
return "Unknown"
else:
return "Inline"
@app.on_message(
command(QUEUE_COMMAND)
& filters.group
& ~BANNED_USERS
)
@language
async def ping_com(client, message: Message, _):
if message.command[0][0] == "c":
chat_id = await get_cmode(message.chat.id)
if chat_id is None:
return await message.reply_text(_["setting_12"])
try:
await app.get_chat(chat_id)
except:
return await message.reply_text(_["cplay_4"])
cplay = True
else:
chat_id = message.chat.id
cplay = False
if not await is_active_chat(chat_id):
return await message.reply_text(_["general_6"])
got = db.get(chat_id)
if not got:
return await message.reply_text(_["queue_2"])
file = got[0]["file"]
videoid = got[0]["vidid"]
user = got[0]["by"]
user_id = got[0]["user_id"]
title = (got[0]["title"]).title()
typo = (got[0]["streamtype"]).title()
DUR = get_duration(got)
if "live_" in file:
IMAGE = get_image(videoid, user_id)
elif "vid_" in file:
IMAGE = get_image(videoid, user_id)
elif "index_" in file:
IMAGE = config.STREAM_IMG_URL
else:
if videoid == "telegram":
IMAGE = (
config.TELEGRAM_AUDIO_URL
if typo == "Audio"
else config.TELEGRAM_VIDEO_URL
)
elif videoid == "soundcloud":
IMAGE = config.SOUNCLOUD_IMG_URL
else:
IMAGE = get_image(videoid, user_id)
send = (
"**⌛️ᴅᴜʀᴀᴛɪᴏɴ:** ᴜɴᴋɴᴏᴡɴ ᴅᴜʀᴀᴛɪᴏɴ sᴛʀᴇᴀᴍ\n\nᴄʟɪᴄᴋ ᴏɴ ʙᴇʟᴏᴡ ʙᴜᴛᴛᴏɴ ᴛᴏ ᴡʜᴏʟᴇ ǫᴜᴇᴜᴇᴅ ʟɪsᴛ."
if DUR == "Unknown"
else "\nᴄʟɪᴄᴋ ᴏɴ ʙᴇʟᴏᴡ ʙᴜᴛᴛᴏɴ ᴛᴏ ɢᴇᴛ ᴡʜᴏʟᴇ ǫᴜᴇᴜᴇᴅ ʟɪsᴛ."
)
cap = f"""**{config.MUSIC_BOT_NAME} ᴩʟᴀʏᴇʀ**
📌**ᴛɪᴛʟᴇ:** {title}
🍒**ᴛʏᴩᴇ:** {typo}
💖**ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ:** {user}
{send}"""
upl = (
queue_markup(_, DUR, "c" if cplay else "g", videoid)
if DUR == "Unknown"
else queue_markup(
_,
DUR,
"c" if cplay else "g",
videoid,
seconds_to_min(got[0]["played"]),
got[0]["dur"],
)
)
basic[videoid] = True
mystic = await message.reply_photo(
IMAGE, caption=cap, reply_markup=upl
)
if DUR != "Unknown":
try:
while db[chat_id][0]["vidid"] == videoid:
await asyncio.sleep(5)
if await is_active_chat(chat_id):
if basic[videoid]:
if await is_music_playing(chat_id):
try:
buttons = queue_markup(
_,
DUR,
"c" if cplay else "g",
videoid,
seconds_to_min(
db[chat_id][0]["played"]
),
db[chat_id][0]["dur"],
)
await mystic.edit_reply_markup(
reply_markup=buttons
)
except FloodWait:
pass
else:
pass
else:
break
else:
break
except:
return
@app.on_callback_query(filters.regex("GetTimer") & ~BANNED_USERS)
async def quite_timer(client, CallbackQuery: CallbackQuery):
try:
await CallbackQuery.answer()
except:
pass
@app.on_callback_query(filters.regex("GetQueued") & ~BANNED_USERS)
@languageCB
async def queued_tracks(client, CallbackQuery: CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
what, videoid = callback_request.split("|")
try:
chat_id, channel = await get_channeplayCB(
_, what, CallbackQuery
)
except:
return
if not await is_active_chat(chat_id):
return await CallbackQuery.answer(
_["general_6"], show_alert=True
)
got = db.get(chat_id)
if not got:
return await CallbackQuery.answer(
_["queue_2"], show_alert=True
)
if len(got) == 1:
return await CallbackQuery.answer(
_["queue_5"], show_alert=True
)
await CallbackQuery.answer()
basic[videoid] = False
buttons = queue_back_markup(_, what)
med = InputMediaPhoto(
media="https://telegra.ph//file/6f7d35131f69951c74ee5.jpg",
caption=_["queue_1"],
)
await CallbackQuery.edit_message_media(media=med)
j = 0
msg = ""
for x in got:
j += 1
if j == 1:
msg += f'Playing :\n\n📌 Title : {x["title"]}\nDuration : {x["dur"]}\nBy : {x["by"]}\n\n'
elif j == 2:
msg += f'Queued :\n\n📌 Title : {x["title"]}\nDuration : {x["dur"]}\nBy : {x["by"]}\n\n'
else:
msg += f'📌 Title : {x["title"]}\nDuration : {x["dur"]}\nBy : {x["by"]}\n\n'
if "Queued" in msg:
if len(msg) < 700:
await asyncio.sleep(1)
return await CallbackQuery.edit_message_text(
msg, reply_markup=buttons
)
if "📌" in msg:
msg = msg.replace("📌", "")
link = await Anonbin(msg)
med = InputMediaPhoto(
media=link, caption=_["queue_3"].format(link)
)
await CallbackQuery.edit_message_media(
media=med, reply_markup=buttons
)
else:
await asyncio.sleep(1)
return await CallbackQuery.edit_message_text(
msg, reply_markup=buttons
)
@app.on_callback_query(
filters.regex("queue_back_timer") & ~BANNED_USERS
)
@languageCB
async def queue_back(client, CallbackQuery: CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
cplay = callback_data.split(None, 1)[1]
try:
chat_id, channel = await get_channeplayCB(
_, cplay, CallbackQuery
)
except:
return
if not await is_active_chat(chat_id):
return await CallbackQuery.answer(
_["general_6"], show_alert=True
)
got = db.get(chat_id)
if not got:
return await CallbackQuery.answer(
_["queue_2"], show_alert=True
)
await CallbackQuery.answer(_["set_cb_8"], show_alert=True)
file = got[0]["file"]
videoid = got[0]["vidid"]
user = got[0]["by"]
user_id = got[0]["user_id"]
title = (got[0]["title"]).title()
typo = (got[0]["streamtype"]).title()
DUR = get_duration(got)
if "live_" in file:
IMAGE = get_image(videoid, user_id)
elif "vid_" in file:
IMAGE = get_image(videoid, user_id)
elif "index_" in file:
IMAGE = config.STREAM_IMG_URL
else:
if videoid == "telegram":
IMAGE = (
config.TELEGRAM_AUDIO_URL
if typo == "Audio"
else config.TELEGRAM_VIDEO_URL
)
elif videoid == "soundcloud":
IMAGE = config.SOUNCLOUD_IMG_URL
else:
IMAGE = get_image(videoid, user_id)
send = (
"**⌛️ᴅᴜʀᴀᴛɪᴏɴ:** ᴜɴᴋɴᴏᴡɴ ᴅᴜʀᴀᴛɪᴏɴ sᴛʀᴇᴀᴍ\n\nᴄʟɪᴄᴋ ᴏɴ ʙᴜᴛᴛᴏɴ ʙᴇʟᴏᴡ ᴛᴏ ɢᴇᴛ ᴡʜᴏʟᴇ ǫᴜᴇᴜᴇᴅ ʟɪsᴛ."
if DUR == "Unknown"
else "\nᴄʟɪᴄᴋ ᴏɴ ʙᴜᴛᴛᴏɴ ʙᴇʟᴏᴡ ᴛᴏ ɢᴇᴛ ᴡʜᴏʟᴇ ǫᴜᴇᴜᴇᴅ ʟɪsᴛ."
)
cap = f"""**{config.MUSIC_BOT_NAME} ᴩʟᴀʏᴇʀ**
📌 **ᴛɪᴛʟᴇ:** {title}
🍒 **ᴛʏᴩᴇ:** {typo}
💖 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ:** {user}
{send}"""
upl = (
queue_markup(_, DUR, cplay, videoid)
if DUR == "Unknown"
else queue_markup(
_,
DUR,
cplay,
videoid,
seconds_to_min(got[0]["played"]),
got[0]["dur"],
)
)
basic[videoid] = True
med = InputMediaPhoto(media=IMAGE, caption=cap)
mystic = await CallbackQuery.edit_message_media(
media=med, reply_markup=upl
)
if DUR != "Unknown":
try:
while db[chat_id][0]["vidid"] == videoid:
await asyncio.sleep(5)
if await is_active_chat(chat_id):
if basic[videoid]:
if await is_music_playing(chat_id):
try:
buttons = queue_markup(
_,
DUR,
cplay,
videoid,
seconds_to_min(
db[chat_id][0]["played"]
),
db[chat_id][0]["dur"],
)
await mystic.edit_reply_markup(
reply_markup=buttons
)
except FloodWait:
pass
else:
pass
else:
break
else:
break
except:
return