2022-01-31 12:03:49 +00:00
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item
|
2022-02-07 16:11:55 +00:00
|
|
|
|
from driver.core import bot, calls
|
2022-01-31 12:03:49 +00:00
|
|
|
|
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
|
|
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 pytgcalls.types.stream import StreamAudioEnded
|
|
|
|
|
|
2022-01-31 12:47:38 +00:00
|
|
|
|
|
2022-01-31 12:03:49 +00:00
|
|
|
|
keyboard = InlineKeyboardMarkup(
|
|
|
|
|
[
|
|
|
|
|
[
|
2022-02-07 16:11:55 +00:00
|
|
|
|
InlineKeyboardButton(text="• Mᴇɴᴜ", callback_data="stream_menu_panel"),
|
|
|
|
|
InlineKeyboardButton(text="• Cʟᴏsᴇ", callback_data="close_menu"),
|
2022-01-31 12:03:49 +00:00
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def skip_current_song(chat_id):
|
|
|
|
|
if chat_id in QUEUE:
|
|
|
|
|
chat_queue = get_queue(chat_id)
|
|
|
|
|
if len(chat_queue) == 1:
|
|
|
|
|
await call_py.leave_group_call(chat_id)
|
|
|
|
|
clear_queue(chat_id)
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
songname = chat_queue[1][0]
|
|
|
|
|
url = chat_queue[1][1]
|
|
|
|
|
link = chat_queue[1][2]
|
|
|
|
|
type = chat_queue[1][3]
|
|
|
|
|
Q = chat_queue[1][4]
|
|
|
|
|
if type == "Audio":
|
2022-02-07 16:11:55 +00:00
|
|
|
|
await calls.change_stream(
|
2022-01-31 12:03:49 +00:00
|
|
|
|
chat_id,
|
|
|
|
|
AudioPiped(
|
|
|
|
|
url,
|
2022-01-31 12:47:38 +00:00
|
|
|
|
HighQualityAudio(),
|
2022-01-31 12:03:49 +00:00
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
elif type == "Video":
|
|
|
|
|
if Q == 720:
|
|
|
|
|
hm = HighQualityVideo()
|
|
|
|
|
elif Q == 480:
|
|
|
|
|
hm = MediumQualityVideo()
|
|
|
|
|
elif Q == 360:
|
|
|
|
|
hm = LowQualityVideo()
|
2022-02-07 16:11:55 +00:00
|
|
|
|
await calls.change_stream(
|
2022-01-31 12:47:38 +00:00
|
|
|
|
chat_id,
|
|
|
|
|
AudioVideoPiped(
|
|
|
|
|
url,
|
|
|
|
|
HighQualityAudio(),
|
|
|
|
|
hm
|
|
|
|
|
)
|
2022-01-31 12:03:49 +00:00
|
|
|
|
)
|
|
|
|
|
pop_an_item(chat_id)
|
|
|
|
|
return [songname, link, type]
|
|
|
|
|
except:
|
2022-02-07 16:11:55 +00:00
|
|
|
|
await calls.leave_group_call(chat_id)
|
2022-01-31 12:03:49 +00:00
|
|
|
|
clear_queue(chat_id)
|
|
|
|
|
return 2
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def skip_item(chat_id, h):
|
|
|
|
|
if chat_id in QUEUE:
|
|
|
|
|
chat_queue = get_queue(chat_id)
|
|
|
|
|
try:
|
|
|
|
|
x = int(h)
|
|
|
|
|
songname = chat_queue[x][0]
|
|
|
|
|
chat_queue.pop(x)
|
|
|
|
|
return songname
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
2022-02-07 17:00:51 +00:00
|
|
|
|
@calls.on_kicked()
|
2022-01-31 12:03:49 +00:00
|
|
|
|
async def kicked_handler(_, chat_id: int):
|
|
|
|
|
if chat_id in QUEUE:
|
|
|
|
|
clear_queue(chat_id)
|
|
|
|
|
|
|
|
|
|
|
2022-02-07 17:00:51 +00:00
|
|
|
|
@calls.on_closed_voice_chat()
|
2022-01-31 12:03:49 +00:00
|
|
|
|
async def closed_voice_chat_handler(_, chat_id: int):
|
|
|
|
|
if chat_id in QUEUE:
|
|
|
|
|
clear_queue(chat_id)
|
|
|
|
|
|
|
|
|
|
|
2022-02-07 17:00:51 +00:00
|
|
|
|
@calls.on_left()
|
2022-01-31 12:03:49 +00:00
|
|
|
|
async def left_handler(_, chat_id: int):
|
|
|
|
|
if chat_id in QUEUE:
|
|
|
|
|
clear_queue(chat_id)
|
|
|
|
|
|
|
|
|
|
|
2022-02-07 17:00:51 +00:00
|
|
|
|
@calls.on_stream_end()
|
2022-01-31 12:03:49 +00:00
|
|
|
|
async def stream_end_handler(_, u: Update):
|
|
|
|
|
if isinstance(u, StreamAudioEnded):
|
|
|
|
|
chat_id = u.chat_id
|
|
|
|
|
print(chat_id)
|
|
|
|
|
op = await skip_current_song(chat_id)
|
|
|
|
|
if op == 1:
|
2022-02-01 04:02:51 +00:00
|
|
|
|
pass
|
2022-01-31 12:03:49 +00:00
|
|
|
|
elif op == 2:
|
|
|
|
|
await bot.send_message(
|
|
|
|
|
chat_id,
|
|
|
|
|
"❌ an error occurred\n\n» **Clearing** __Queues__ and leaving video chat.",
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
await bot.send_message(
|
|
|
|
|
chat_id,
|
|
|
|
|
f"💡 **Streaming next track**\n\n🗂 **Name:** [{op[0]}]({op[1]}) | `{op[2]}`\n💭 **Chat:** `{chat_id}`",
|
|
|
|
|
disable_web_page_preview=True,
|
|
|
|
|
reply_markup=keyboard,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def bash(cmd):
|
|
|
|
|
process = await asyncio.create_subprocess_shell(
|
|
|
|
|
cmd,
|
|
|
|
|
stdout=asyncio.subprocess.PIPE,
|
|
|
|
|
stderr=asyncio.subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
stdout, stderr = await process.communicate()
|
|
|
|
|
err = stderr.decode().strip()
|
|
|
|
|
out = stdout.decode().strip()
|
|
|
|
|
return out, err
|