File size: 24,065 Bytes
80287e2 |
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 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
import random
import string
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InputMediaPhoto, Message
from pytgcalls.exceptions import NoActiveGroupCall
import config
from Devine import Apple, Resso, SoundCloud, Spotify, Telegram, YouTube, app
from Devine.core.call import Anony as devine
from Devine.utils import seconds_to_min, time_to_seconds
from Devine.utils.channelplay import get_channeplayCB
from Devine.utils.decorators.language import languageCB
from Devine.utils.decorators.play import PlayWrapper
from Devine.utils.formatters import formats
from Devine.utils.inline import (
botplaylist_markup,
livestream_markup,
playlist_markup,
slider_markup,
track_markup,
)
from Devine.utils.logger import play_logs
from Devine.utils.stream.stream import stream
from config import BANNED_USERS as filter, lyrical
@app.on_message(
filters.command(["play", "vplay", "cplay", "cvplay", "playforce", "vplayforce", "cplayforce", "cvplayforce"] ,prefixes=["/", "!", "%", ",", "", ".", "@", "#"])
& filters.group
& ~filter
)
@PlayWrapper
async def play_commnd(
client,
message: Message,
_,
chat_id,
video,
channel,
playmode,
url,
fplay,
):
mystic = await message.reply_text(
_["play_2"].format(channel) if channel else _["play_1"]
)
plist_id = None
slider = None
plist_type = None
spotify = None
user_id = message.from_user.id
user_name = message.from_user.first_name
audio_telegram = (
(message.reply_to_message.audio or message.reply_to_message.voice)
if message.reply_to_message
else None
)
video_telegram = (
(message.reply_to_message.video or message.reply_to_message.document)
if message.reply_to_message
else None
)
if audio_telegram:
if audio_telegram.file_size > 104857600:
return await mystic.edit_text(_["play_5"])
duration_min = seconds_to_min(audio_telegram.duration)
if (audio_telegram.duration) > config.DURATION_LIMIT:
return await mystic.edit_text(
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
)
file_path = await Telegram.get_filepath(audio=audio_telegram)
if await Telegram.download(_, message, mystic, file_path):
message_link = await Telegram.get_link(message)
file_name = await Telegram.get_filename(audio_telegram, audio=True)
dur = await Telegram.get_duration(audio_telegram, file_path)
details = {
"title": file_name,
"link": message_link,
"path": file_path,
"dur": dur,
}
try:
await stream(
_,
mystic,
user_id,
details,
chat_id,
user_name,
message.chat.id,
streamtype="telegram",
forceplay=fplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await mystic.delete()
return
elif video_telegram:
if message.reply_to_message.document:
try:
ext = video_telegram.file_name.split(".")[-1]
if ext.lower() not in formats:
return await mystic.edit_text(
_["play_7"].format(f"{' | '.join(formats)}")
)
except:
return await mystic.edit_text(
_["play_7"].format(f"{' | '.join(formats)}")
)
if video_telegram.file_size > config.TG_VIDEO_FILESIZE_LIMIT:
return await mystic.edit_text(_["play_8"])
file_path = await Telegram.get_filepath(video=video_telegram)
if await Telegram.download(_, message, mystic, file_path):
message_link = await Telegram.get_link(message)
file_name = await Telegram.get_filename(video_telegram)
dur = await Telegram.get_duration(video_telegram, file_path)
details = {
"title": file_name,
"link": message_link,
"path": file_path,
"dur": dur,
}
try:
await stream(
_,
mystic,
user_id,
details,
chat_id,
user_name,
message.chat.id,
video=True,
streamtype="telegram",
forceplay=fplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await mystic.delete()
return
elif url:
if await YouTube.exists(url):
if "playlist" in url:
try:
details = await YouTube.playlist(
url,
config.PLAYLIST_FETCH_LIMIT,
message.from_user.id,
)
except Exception as e:
print(e)
return await mystic.edit_text(_["play_3"])
streamtype = "playlist"
plist_type = "yt"
if "&" in url:
plist_id = (url.split("=")[1]).split("&")[0]
else:
plist_id = url.split("=")[1]
img = config.PLAYLIST_IMG_URL
cap = _["play_10"]
elif "https://youtu.be" in url:
videoid = url.split("/")[-1].split("?")[0]
details, track_id = await YouTube.track(f"https://www.youtube.com/watch?v={videoid}")
streamtype = "youtube"
img = details["thumb"]
cap = _["play_11"].format(
details["title"],
details["duration_min"],
)
else:
try:
details, track_id = await YouTube.track(url)
except Exception as e:
print(e)
return await mystic.edit_text(_["play_3"])
streamtype = "youtube"
img = details["thumb"]
cap = _["play_11"].format(
details["title"],
details["duration_min"],
)
elif await Spotify.valid(url):
spotify = True
if not config.SPOTIFY_CLIENT_ID and not config.SPOTIFY_CLIENT_SECRET:
return await mystic.edit_text(
"» sᴘᴏᴛɪғʏ ɪs ɴᴏᴛ sᴜᴘᴘᴏʀᴛᴇᴅ ʏᴇᴛ.\n\nᴘʟᴇᴀsᴇ ᴛʀʏ ᴀɢᴀɪɴ ʟᴀᴛᴇʀ."
)
if "track" in url:
try:
details, track_id = await Spotify.track(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "youtube"
img = details["thumb"]
cap = _["play_10"].format(details["title"], details["duration_min"])
elif "playlist" in url:
try:
details, plist_id = await Spotify.playlist(url)
except Exception:
return await mystic.edit_text(_["play_3"])
streamtype = "playlist"
plist_type = "spplay"
img = config.SPOTIFY_PLAYLIST_IMG_URL
cap = _["play_11"].format(app.mention, message.from_user.mention)
elif "album" in url:
try:
details, plist_id = await Spotify.album(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "playlist"
plist_type = "spalbum"
img = config.SPOTIFY_ALBUM_IMG_URL
cap = _["play_11"].format(app.mention, message.from_user.mention)
elif "artist" in url:
try:
details, plist_id = await Spotify.artist(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "playlist"
plist_type = "spartist"
img = config.SPOTIFY_ARTIST_IMG_URL
cap = _["play_11"].format(message.from_user.first_name)
else:
return await mystic.edit_text(_["play_15"])
elif await Apple.valid(url):
if "album" in url:
try:
details, track_id = await Apple.track(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "youtube"
img = details["thumb"]
cap = _["play_10"].format(details["title"], details["duration_min"])
elif "playlist" in url:
spotify = True
try:
details, plist_id = await Apple.playlist(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "playlist"
plist_type = "apple"
cap = _["play_12"].format(app.mention, message.from_user.mention)
img = url
else:
return await mystic.edit_text(_["play_3"])
elif await Resso.valid(url):
try:
details, track_id = await Resso.track(url)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "youtube"
img = details["thumb"]
cap = _["play_10"].format(details["title"], details["duration_min"])
elif await SoundCloud.valid(url):
try:
details, track_path = await SoundCloud.download(url)
except:
return await mystic.edit_text(_["play_3"])
duration_sec = details["duration_sec"]
if duration_sec > config.DURATION_LIMIT:
return await mystic.edit_text(
_["play_6"].format(
config.DURATION_LIMIT_MIN,
app.mention,
)
)
try:
await stream(
_,
mystic,
user_id,
details,
chat_id,
user_name,
message.chat.id,
streamtype="soundcloud",
forceplay=fplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await mystic.delete()
else:
try:
await devine.stream_call(url)
except NoActiveGroupCall:
await mystic.edit_text(_["black_9"])
return await app.send_message(
chat_id=config.LOGGER_ID,
text=_["play_17"],
)
except Exception as e:
return await mystic.edit_text(_["general_2"].format(type(e).__name__))
await mystic.edit_text(_["str_2"])
try:
await stream(
_,
mystic,
message.from_user.id,
url,
chat_id,
message.from_user.first_name,
message.chat.id,
video=video,
streamtype="index",
forceplay=fplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await play_logs(message, streamtype="M3u8 or Index Link")
else:
if len(message.command) < 2:
buttons = botplaylist_markup(_)
return await mystic.edit_text(
_["play_18"],
reply_markup=InlineKeyboardMarkup(buttons),
)
slider = True
query = message.text.split(None, 1)[1]
if "-v" in query:
query = query.replace("-v", "")
try:
details, track_id = await YouTube.track(query)
except:
return await mystic.edit_text(_["play_3"])
streamtype = "youtube"
if str(playmode) == "Direct":
if not plist_type:
if details["duration_min"]:
duration_sec = time_to_seconds(details["duration_min"])
if duration_sec > config.DURATION_LIMIT:
return await mystic.edit_text(
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
)
else:
buttons = livestream_markup(
_,
track_id,
user_id,
"v" if video else "a",
"c" if channel else "g",
"f" if fplay else "d",
)
return await mystic.edit_text(
_["play_13"],
reply_markup=InlineKeyboardMarkup(buttons),
)
try:
await stream(
_,
mystic,
user_id,
details,
chat_id,
user_name,
message.chat.id,
video=video,
streamtype=streamtype,
spotify=spotify,
forceplay=fplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
await mystic.delete()
return await play_logs(message, streamtype=streamtype)
else:
if plist_type:
ran_hash = "".join(
random.choices(string.ascii_uppercase + string.digits, k=10)
)
lyrical[ran_hash] = plist_id
buttons = playlist_markup(
_,
ran_hash,
message.from_user.id,
plist_type,
"c" if channel else "g",
"f" if fplay else "d",
)
await mystic.delete()
await message.reply_photo(
photo=img,
caption=cap,
reply_markup=InlineKeyboardMarkup(buttons),
)
return await play_logs(message, streamtype=f"Playlist : {plist_type}")
else:
if slider:
buttons = slider_markup(
_,
track_id,
message.from_user.id,
query,
0,
"c" if channel else "g",
"f" if fplay else "d",
)
await mystic.delete()
await message.reply_photo(
photo=details["thumb"],
caption=_["play_10"].format(
details["title"].title(),
details["duration_min"],
),
reply_markup=InlineKeyboardMarkup(buttons),
)
return await play_logs(message, streamtype=f"Searched on Youtube")
else:
buttons = track_markup(
_,
track_id,
message.from_user.id,
"c" if channel else "g",
"f" if fplay else "d",
)
await mystic.delete()
await message.reply_photo(
photo=img,
caption=cap,
reply_markup=InlineKeyboardMarkup(buttons),
)
return await play_logs(message, streamtype=f"URL Searched Inline")
@app.on_callback_query(filters.regex("MusicStream") & ~filter)
@languageCB
async def play_music(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
vidid, user_id, mode, cplay, fplay = callback_request.split("|")
if CallbackQuery.from_user.id != int(user_id):
try:
return await CallbackQuery.answer(_["playcb_1"], show_alert=True)
except:
return
try:
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
except:
return
user_name = CallbackQuery.from_user.first_name
try:
await CallbackQuery.message.delete()
await CallbackQuery.answer()
except:
pass
mystic = await CallbackQuery.message.reply_text(
_["play_2"].format(channel) if channel else _["play_1"]
)
try:
details, track_id = await YouTube.track(vidid, True)
except:
return await mystic.edit_text(_["play_3"])
if details["duration_min"]:
duration_sec = time_to_seconds(details["duration_min"])
if duration_sec > config.DURATION_LIMIT:
return await mystic.edit_text(
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
)
else:
buttons = livestream_markup(
_,
track_id,
CallbackQuery.from_user.id,
mode,
"c" if cplay == "c" else "g",
"f" if fplay else "d",
)
return await mystic.edit_text(
_["play_13"],
reply_markup=InlineKeyboardMarkup(buttons),
)
video = True if mode == "v" else None
ffplay = True if fplay == "f" else None
try:
await stream(
_,
mystic,
CallbackQuery.from_user.id,
details,
chat_id,
user_name,
CallbackQuery.message.chat.id,
video,
streamtype="youtube",
forceplay=ffplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await mystic.delete()
@app.on_callback_query(filters.regex("devinemousAdmin") & ~filter)
async def devinemous_check(client, CallbackQuery):
try:
await CallbackQuery.answer(
"» ʀᴇᴠᴇʀᴛ ʙᴀᴄᴋ ᴛᴏ ᴜsᴇʀ ᴀᴄᴄᴏᴜɴᴛ :\n\nᴏᴘᴇɴ ʏᴏᴜʀ ɢʀᴏᴜᴘ sᴇᴛᴛɪɴɢs.\n-> ᴀᴅᴍɪɴɪsᴛʀᴀᴛᴏʀs\n-> ᴄʟɪᴄᴋ ᴏɴ ʏᴏᴜʀ ɴᴀᴍᴇ\n-> ᴜɴᴄʜᴇᴄᴋ ᴀɴᴏɴʏᴍᴏᴜs ᴀᴅᴍɪɴ ᴘᴇʀᴍɪssɪᴏɴs.",
show_alert=True,
)
except:
pass
@app.on_callback_query(filters.regex("DAXXPlaylists") & ~filter)
@languageCB
async def play_playlists_command(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
(
videoid,
user_id,
ptype,
mode,
cplay,
fplay,
) = callback_request.split("|")
if CallbackQuery.from_user.id != int(user_id):
try:
return await CallbackQuery.answer(_["playcb_1"], show_alert=True)
except:
return
try:
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
except:
return
user_name = CallbackQuery.from_user.first_name
await CallbackQuery.message.delete()
try:
await CallbackQuery.answer()
except:
pass
mystic = await CallbackQuery.message.reply_text(
_["play_2"].format(channel) if channel else _["play_1"]
)
videoid = lyrical.get(videoid)
video = True if mode == "v" else None
ffplay = True if fplay == "f" else None
spotify = True
if ptype == "yt":
spotify = False
try:
result = await YouTube.playlist(
videoid,
config.PLAYLIST_FETCH_LIMIT,
CallbackQuery.from_user.id,
True,
)
except:
return await mystic.edit_text(_["play_3"])
if ptype == "spplay":
try:
result, spotify_id = await Spotify.playlist(videoid)
except:
return await mystic.edit_text(_["play_3"])
if ptype == "spalbum":
try:
result, spotify_id = await Spotify.album(videoid)
except:
return await mystic.edit_text(_["play_3"])
if ptype == "spartist":
try:
result, spotify_id = await Spotify.artist(videoid)
except:
return await mystic.edit_text(_["play_3"])
if ptype == "apple":
try:
result, apple_id = await Apple.playlist(videoid, True)
except:
return await mystic.edit_text(_["play_3"])
try:
await stream(
_,
mystic,
user_id,
result,
chat_id,
user_name,
CallbackQuery.message.chat.id,
video,
streamtype="playlist",
spotify=spotify,
forceplay=ffplay,
)
except Exception as e:
ex_type = type(e).__name__
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
return await mystic.edit_text(err)
return await mystic.delete()
@app.on_callback_query(filters.regex("slider") & ~filter)
@languageCB
async def slider_queries(client, CallbackQuery, _):
callback_data = CallbackQuery.data.strip()
callback_request = callback_data.split(None, 1)[1]
(
what,
rtype,
query,
user_id,
cplay,
fplay,
) = callback_request.split("|")
if CallbackQuery.from_user.id != int(user_id):
try:
return await CallbackQuery.answer(_["playcb_1"], show_alert=True)
except:
return
what = str(what)
rtype = int(rtype)
if what == "F":
if rtype == 9:
query_type = 0
else:
query_type = int(rtype + 1)
try:
await CallbackQuery.answer(_["playcb_2"])
except:
pass
title, duration_min, thumbnail, vidid = await YouTube.slider(query, query_type)
buttons = slider_markup(_, vidid, user_id, query, query_type, cplay, fplay)
med = InputMediaPhoto(
media=thumbnail,
caption=_["play_10"].format(
title.title(),
duration_min,
),
)
return await CallbackQuery.edit_message_media(
media=med, reply_markup=InlineKeyboardMarkup(buttons)
)
if what == "B":
if rtype == 0:
query_type = 9
else:
query_type = int(rtype - 1)
try:
await CallbackQuery.answer(_["playcb_2"])
except:
pass
title, duration_min, thumbnail, vidid = await YouTube.slider(query, query_type)
buttons = slider_markup(_, vidid, user_id, query, query_type, cplay, fplay)
med = InputMediaPhoto(
media=thumbnail,
caption=_["play_10"].format(
title.title(),
duration_min,
),
)
return await CallbackQuery.edit_message_media(
media=med, reply_markup=InlineKeyboardMarkup(buttons)
)
|