Spaces:
Runtime error
Runtime error
File size: 20,383 Bytes
5126418 |
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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
from pytgcalls import StreamType
from pytgcalls.types import Update
from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped
from pytgcalls.types.input_stream.quality import (
HighQualityAudio,
HighQualityVideo,
LowQualityVideo,
MediumQualityVideo,
)
from telethon.tl.functions.channels import LeaveChannelRequest
from telethon.tl.functions.messages import ImportChatInviteRequest
from telethon.tl.functions.messages import ImportChatInviteRequest
from pytgcalls.exceptions import (
NoActiveGroupCall,
NotInGroupCallError
)
from Zaid.status import *
from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.functions.messages import ExportChatInviteRequest
import telethon.utils
from telethon.tl import functions
from telethon.tl import types
from telethon.utils import get_display_name
from telethon.tl.functions.users import GetFullUserRequest
from youtubesearchpython import VideosSearch
fotoplay = "https://telegra.ph/file/b6402152be44d90836339.jpg"
ngantri = "https://telegra.ph/file/b6402152be44d90836339.jpg"
from Zaid import call_py, Zaid, client as Client
owner = "1669178360"
from Zaid.helpers.yt_dlp import bash
from Zaid.helpers.chattitle import CHAT_TITLE
from Zaid.helpers.queues import (
QUEUE,
add_to_queue,
clear_queue,
get_queue,
pop_an_item,
active,
)
from telethon import Button, events
from Config import Config
from Zaid.helpers.thumbnail import gen_thumb
from Zaid.helpers.joiner import AssistantAdd
def vcmention(user):
full_name = get_display_name(user)
if not isinstance(user, types.User):
return full_name
return f"[{full_name}](tg://user?id={user.id})"
def ytsearch(query: str):
try:
search = VideosSearch(query, limit=1).result()
data = search["result"][0]
songname = data["title"]
url = data["link"]
duration = data["duration"]
thumbnail = f"https://i.ytimg.com/vi/{data['id']}/hqdefault.jpg"
videoid = data["id"]
return [songname, url, duration, thumbnail, videoid]
except Exception as e:
print(e)
return 0
async def ytdl(format: str, link: str):
stdout, stderr = await bash(f'yt-dlp -g -f "{format}" {link}')
if stdout:
return 1, stdout.split("\n")[0]
return 0, stderr
async def skip_item(chat_id: int, x: int):
if chat_id not in QUEUE:
return 0
chat_queue = get_queue(chat_id)
try:
songname = chat_queue[x][0]
chat_queue.pop(x)
return songname
except Exception as e:
print(e)
return 0
async def skip_current_song(chat_id: int):
if chat_id not in QUEUE:
return 0
chat_queue = get_queue(chat_id)
if len(chat_queue) == 1:
await call_py.leave_group_call(chat_id)
clear_queue(chat_id)
active.remove(chat_id)
return 1
songname = chat_queue[1][0]
url = chat_queue[1][1]
link = chat_queue[1][2]
type = chat_queue[1][3]
RESOLUSI = chat_queue[1][4]
if type == "Audio":
await call_py.change_stream(
chat_id,
AudioPiped(
url,
),
)
elif type == "Video":
if RESOLUSI == 720:
hm = HighQualityVideo()
elif RESOLUSI == 480:
hm = MediumQualityVideo()
elif RESOLUSI == 360:
hm = LowQualityVideo()
await call_py.change_stream(
chat_id, AudioVideoPiped(url, HighQualityAudio(), hm)
)
pop_an_item(chat_id)
return [songname, link, type]
@Zaid.on(events.callbackquery.CallbackQuery(data="cls"))
async def _(event):
await event.delete()
btnn =[[Button.inline("✯ cʟᴏꜱᴇ ✯", data="cls")]]
#play
@Zaid.on(events.NewMessage(pattern="^[?!/]play"))
@AssistantAdd
async def play(event):
title = ' '.join(event.text[5:])
replied = await event.get_reply_message()
sender = await event.get_sender()
chat = await event.get_chat()
chat_id = event.chat_id
from_user = vcmention(event.sender)
public = event.chat_id
if (
replied
and not replied.audio
and not replied.voice
and not title
or not replied
and not title
):
return await event.client.send_file(chat_id, Config.CMD_IMG, caption="**Give Me Your Query Which You want to Play**\n\n **Example**: `/play Nira Ishq Bass boosted`", buttons=btnn)
elif replied and not replied.audio and not replied.voice or not replied:
botman = await event.reply("🔎")
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
if search == 0:
await botman.edit(
"**Can't Find Song** Try searching with More Specific Title"
)
else:
songname = search[0]
title = search[0]
url = search[1]
duration = search[2]
thumbnail = search[3]
videoid = search[4]
userid = sender.id
titlegc = chat.title
ctitle = await CHAT_TITLE(titlegc)
thumb = await gen_thumb(videoid)
format = "best[height<=?720][width<=?1280]"
hm, ytlink = await ytdl(format, url)
if hm == 0:
await botman.edit(f"`{ytlink}`")
elif chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, ytlink, url, "Audio", 0)
caption = f"✨ **ᴀᴅᴅᴇᴅ ᴛᴏ ǫᴜᴇᴜᴇ ᴀᴛ** {pos}\n\n❄ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await botman.delete()
await event.client.send_file(chat_id, thumb, caption=caption, buttons=btnn)
else:
try:
await call_py.join_group_call(
chat_id,
AudioPiped(
ytlink,
),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, ytlink, url, "Audio", 0)
caption = f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n🌸 **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await botman.delete()
await event.client.send_file(chat_id, thumb, caption=caption, buttons=btnn)
except Exception as ep:
clear_queue(chat_id)
await botman.edit(f"`{ep}`")
else:
botman = await event.reply("➕ Downloading File...")
dl = await replied.download_media()
link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}"
if replied.audio:
songname = "Telegram Music Player"
elif replied.voice:
songname = "Voice Note"
if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, dl, link, "Audio", 0)
caption = f"✨ **ᴀᴅᴅᴇᴅ ᴛᴏ ǫᴜᴇᴜᴇ ᴀᴛ** {pos}\n\n❄ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await event.client.send_file(chat_id, ngantri, caption=caption, buttons=btnn)
await botman.delete()
else:
try:
await call_py.join_group_call(
chat_id,
AudioPiped(
dl,
),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, dl, link, "Audio", 0)
caption = f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n🌸 **ᴛɪᴛʟᴇ :** [{songname}]({link})\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await event.client.send_file(chat_id, fotoplay, caption=caption, buttons=btnn)
await botman.delete()
except Exception as ep:
clear_queue(chat_id)
await botman.edit(f"`{ep}`")
#end
@Zaid.on(events.NewMessage(pattern="^[/?!]end"))
@is_admin
async def vc_end(event, perm):
chat_id = event.chat_id
from_user = vcmention(event.sender)
try:
await call_py.leave_group_call(chat_id)
except Exception:
pass
if chat_id in QUEUE:
clear_queue(chat_id)
await event.reply(f"**Streaming Ended**")
else:
await event.reply("**Ntg is playing ~**")
@Zaid.on(events.NewMessage(pattern="^[?!/]vplay"))
@AssistantAdd
async def vplay(event):
if Config.HEROKU_MODE == "ENABLE":
await event.reply("__Currently Heroku Mode is ENABLED so You Can't Stream Video because Video Streaming Cause of Banning Your Heroku Account__.")
return
title = ' '.join(event.text[6:])
replied = await event.get_reply_message()
sender = await event.get_sender()
userid = sender.id
chat = await event.get_chat()
titlegc = chat.title
chat_id = event.chat_id
public = event.chat_id
from_user = vcmention(event.sender)
if (
replied
and not replied.video
and not replied.document
and not title
or not replied
and not title
):
return await event.client.send_file(chat_id, Config.CMD_IMG, caption="**Give Me Your Query Which You want to Stream**\n\n **Example**: `/vplay Nira Ishq Bass boosted`", buttons=btnn)
if replied and not replied.video and not replied.document:
xnxx = await event.reply("**🔄 Processing Query... Please Wait!**")
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
RESOLUSI = 720
hmmm = HighQualityVideo()
if search == 0:
await xnxx.edit(
"**Give Me Valid Inputs**"
)
else:
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
songname = search[0]
title = search[0]
url = search[1]
duration = search[2]
thumbnail = search[3]
videoid = search[4]
ctitle = await CHAT_TITLE(titlegc)
thumb = await gen_thumb(videoid)
format = "best[height<=?720][width<=?1280]"
hm, ytlink = await ytdl(format, url)
if hm == 0:
await xnxx.edit(f"`{ytlink}`")
elif chat_id in QUEUE:
pos = add_to_queue(
chat_id, songname, ytlink, url, "Video", RESOLUSI)
caption = f"**✨ ᴀᴅᴅᴇᴅ ᴛᴏ ǫᴜᴇᴜᴇ ᴀᴛ** {pos}\n\n❄ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await xnxx.delete()
await event.client.send_file(chat_id, thumb, caption=caption, buttons=btnn)
else:
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(ytlink, HighQualityAudio(), hmmm),
stream_type=StreamType().pulse_stream,
)
add_to_queue(
chat_id,
songname,
ytlink,
url,
"Video",
RESOLUSI)
await xnxx.delete()
await event.client.send_file(event.chat_id,
f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n🌸 **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}, buttons=btnn",
link_preview=False,
)
except Exception as ep:
clear_queue(chat_id)
await xnxx.edit(f"`{ep}`")
elif replied:
xnxx = await event.reply("➕ **Downloading Replied File**")
dl = await replied.download_media()
link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}"
if len(event.text.split()) < 2:
RESOLUSI = 720
else:
pq = event.text.split(maxsplit=1)[1]
RESOLUSI = int(pq)
if replied.video or replied.document:
songname = "Telegram Video Player"
if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, dl, link, "Video", RESOLUSI)
caption = f"**✨ ᴀᴅᴅᴇᴅ ᴛᴏ ǫᴜᴇᴜᴇ ᴀᴛ** {pos}\n\n❄ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await event.client.send_file(chat_id, ngantri, caption=caption, buttons=btnn)
await xnxx.delete()
else:
if RESOLUSI == 360:
hmmm = LowQualityVideo()
elif RESOLUSI == 480:
hmmm = MediumQualityVideo()
elif RESOLUSI == 720:
hmmm = HighQualityVideo()
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(dl, HighQualityAudio(), hmmm),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, dl, link, "Video", RESOLUSI)
caption = f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n✨ **ᴛɪᴛʟᴇ :** [{songname}]({link})\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await xnxx.delete()
await event.client.send_file(chat_id, fotoplay, caption=caption, buttons=btnn)
except Exception as ep:
clear_queue(chat_id)
await xnxx.edit(f"`{ep}`")
else:
xnxx = await event.reply("**🔄 Processing Query... Please Wait!**")
query = event.text.split(maxsplit=1)[1]
search = ytsearch(query)
RESOLUSI = 720
hmmm = HighQualityVideo()
if search == 0:
await xnxx.edit("**Unable To featch your Query**")
else:
songname = search[0]
title = search[0]
url = search[1]
duration = search[2]
thumbnail = search[3]
videoid = search[4]
ctitle = await CHAT_TITLE(titlegc)
thumb = await gen_thumb(videoid)
format = "best[height<=?720][width<=?1280]"
hm, ytlink = await ytdl(format, url)
if hm == 0:
await xnxx.edit(f"`{ytlink}`")
elif chat_id in QUEUE:
pos = add_to_queue(
chat_id, songname, ytlink, url, "Video", RESOLUSI)
caption = f"**✨ ᴀᴅᴅᴇᴅ ᴛᴏ ǫᴜᴇᴜᴇ ᴀᴛ** {pos}\n\n❄ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await xnxx.delete()
await event.client.send_file(chat_id, thumb, caption=caption, buttons=btnn)
else:
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(ytlink, HighQualityAudio(), hmmm),
stream_type=StreamType().pulse_stream,
)
add_to_queue(
chat_id,
songname,
ytlink,
url,
"Video",
RESOLUSI)
caption = f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n✨ **ᴛɪᴛʟᴇ :** [{songname}]({url})\n⏱ **ᴅᴜʀᴀᴛɪᴏɴ :** {duration} ᴍɪɴᴜᴛᴇs\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await xnxx.delete()
await event.client.send_file(chat_id, thumb, caption=caption, buttons=btnn)
except Exception as ep:
clear_queue(chat_id)
await xnxx.edit(f"`{ep}`")
#playlist
@Zaid.on(events.NewMessage(pattern="^[?!/]playlist"))
@is_admin
async def vc_playlist(event, perm):
chat_id = event.chat_id
if chat_id in QUEUE:
chat_queue = get_queue(chat_id)
if len(chat_queue) == 1:
await event.reply(
f"**�PlAYLIST:**\n• [{chat_queue[0][0]}]({chat_queue[0][2]}) | `{chat_queue[0][3]}`",
link_preview=False,
)
else:
PLAYLIST = f"**🎧 PLAYLIST:**\n**• [{chat_queue[0][0]}]({chat_queue[0][2]})** | `{chat_queue[0][3]}` \n\n**• Upcoming Streaming:**"
l = len(chat_queue)
for x in range(1, l):
hmm = chat_queue[x][0]
hmmm = chat_queue[x][2]
hmmmm = chat_queue[x][3]
PLAYLIST = PLAYLIST + "\n" + \
f"**#{x}** - [{hmm}]({hmmm}) | `{hmmmm}`"
await event.reply(PLAYLIST, link_preview=False)
else:
await event.reply("**Ntg is Streaming**")
#leavevc
@Zaid.on(events.NewMessage(pattern="^[?!/]leavevc"))
@is_admin
async def leavevc(event, perm):
xnxx = await event.reply("Processing")
chat_id = event.chat_id
from_user = vcmention(event.sender)
if from_user:
try:
await call_py.leave_group_call(chat_id)
except (NotInGroupCallError, NoActiveGroupCall):
pass
await xnxx.edit("**Left the voice chat** `{}`".format(str(event.chat_id)))
else:
await xnxx.edit(f"**Sorry {owner} not on Voice Chat**")
@Zaid.on(events.NewMessage(pattern="^[?!/]skip"))
@is_admin
async def vc_skip(event, perm):
chat_id = event.chat_id
if len(event.text.split()) < 2:
op = await skip_current_song(chat_id)
if op == 0:
await event.reply("**Nothing Is Streaming**")
elif op == 1:
await event.reply("empty queue, leaving voice chat")
else:
await event.reply(
f"**⏭ Skipped**\n**🎧 Now Playing** - [{op[0]}]({op[1]})",
link_preview=False,
)
else:
skip = event.text.split(maxsplit=1)[1]
DELQUE = "**Removing Following Songs From Queue:**"
if chat_id in QUEUE:
items = [int(x) for x in skip.split(" ") if x.isdigit()]
items.sort(reverse=True)
for x in items:
if x != 0:
hm = await skip_item(chat_id, x)
if hm != 0:
DELQUE = DELQUE + "\n" + f"**#{x}** - {hm}"
await event.reply(DELQUE)
@Zaid.on(events.NewMessage(pattern="^[?!/]pause"))
@is_admin
async def vc_pause(event, perm):
chat_id = event.chat_id
if chat_id in QUEUE:
try:
await call_py.pause_stream(chat_id)
await event.reply("**Streaming Paused**")
except Exception as e:
await event.reply(f"**ERROR:** `{e}`")
else:
await event.reply("**Nothing Is Playing**")
@Zaid.on(events.NewMessage(pattern="^[?!/]resume"))
@is_admin
async def vc_resume(event, perm):
chat_id = event.chat_id
if chat_id in QUEUE:
try:
await call_py.resume_stream(chat_id)
await event.reply("**Streaming Started Back 🔙**")
except Exception as e:
await event.reply(f"**ERROR:** `{e}`")
else:
await event.reply("**Nothing Is Streaming**")
@call_py.on_stream_end()
async def stream_end_handler(_, u: Update):
chat_id = u.chat_id
print(chat_id)
await skip_current_song(chat_id)
@call_py.on_closed_voice_chat()
async def closedvc(_, chat_id: int):
if chat_id in QUEUE:
clear_queue(chat_id)
if chat_id in active:
active.remove(chat_id)
@call_py.on_left()
async def leftvc(_, chat_id: int):
if chat_id in QUEUE:
clear_queue(chat_id)
if chat_id in active:
active.remove(chat_id)
@call_py.on_kicked()
async def kickedvc(_, chat_id: int):
if chat_id in QUEUE:
clear_queue(chat_id)
if chat_id in active:
active.remove(chat_id)
|