video-stream/driver/utils.py

83 lines
2.4 KiB
Python
Raw Normal View History

2021-10-26 12:56:29 +00:00
from driver.veez import call_py
2021-11-15 23:40:41 +00:00
from pytgcalls import PyTgCalls
2021-10-28 15:16:30 +00:00
from pytgcalls.types import Update
2021-11-01 04:02:37 +00:00
from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item
2021-10-26 08:59:28 +00:00
from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped
2021-10-30 23:06:11 +00:00
from pytgcalls.types.input_stream.quality import (
HighQualityAudio,
HighQualityVideo,
LowQualityVideo,
MediumQualityVideo,
)
2021-10-28 15:16:30 +00:00
from pytgcalls.types.stream import StreamAudioEnded, StreamVideoEnded
2021-10-26 08:59:28 +00:00
2021-10-28 15:16:30 +00:00
2021-10-26 08:59:28 +00:00
async def skip_current_song(chat_id):
2021-10-30 23:06:11 +00:00
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:
2021-11-10 13:30:00 +00:00
try:
2021-10-30 23:06:11 +00:00
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":
await call_py.change_stream(
chat_id,
AudioPiped(
url,
),
)
elif type == "Video":
if Q == 720:
hm = HighQualityVideo()
elif Q == 480:
hm = MediumQualityVideo()
elif Q == 360:
hm = LowQualityVideo()
await call_py.change_stream(
chat_id, AudioVideoPiped(url, HighQualityAudio(), hm)
)
pop_an_item(chat_id)
return [songname, link, type]
2021-11-10 13:37:39 +00:00
except:
2021-11-10 13:20:06 +00:00
await call_py.leave_group_call(chat_id)
clear_queue(chat_id)
return 2
2021-10-30 23:06:11 +00:00
else:
return 0
2021-10-26 08:59:28 +00:00
async def skip_item(chat_id, h):
2021-10-30 23:06:11 +00:00
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
2021-10-26 08:59:28 +00:00
@call_py.on_stream_end()
2021-10-30 23:06:11 +00:00
async def on_end_handler(_, u: Update):
2021-11-01 04:17:54 +00:00
if isinstance(u, StreamAudioEnded) or isinstance(u, StreamVideoEnded):
chat_id = u.chat_id
print(chat_id)
await skip_current_song(chat_id)
2021-11-15 23:40:41 +00:00
@call_py.on_closed_voice_chat()
async def close_handler(client: PyTgCalls, chat_id: int):
if chat_id in QUEUE:
clear_queue(chat_id)