video-stream/helpers/utils.py
levina 180bcdbfcb
check #3
auto detection for missing object
2021-09-14 10:34:49 +07:00

51 lines
1.4 KiB
Python

# Copyright (C) 2021 By VeezMusicProject
import asyncio
from pyrogram import Client
from youtube_dl import YoutubeDL
from youtube_dl.utils import ExtractorError
from pytgcalls.pytgcalls import PyTgCalls
SIGINT: int = 2
FFMPEG_PROCESS = {}
call_py = PyTgCalls(app)
app = Client(Veez.SESSION_NAME, Veez.API_ID, Veez.API_HASH)
###############
# Basic Utils #
###############
def raw_converter(dl, song, video):
return subprocess.Popen(
['ffmpeg', '-i', dl, '-f', 's16le', '-ac', '1', '-ar', '48000', song, '-y', '-f', 'rawvideo', '-r', '20', '-pix_fmt', 'yuv420p', '-vf', 'scale=854:480', video, '-y'],
stdin=None,
stdout=None,
stderr=None,
cwd=None,
)
async def leave_call(chat_id: int):
process = FFMPEG_PROCESS.get(chat_id)
if process:
try:
process.send_signal(SIGINT)
await asyncio.sleep(3)
except Exception as e:
print(e)
pass
try:
await call_py.leave_group_call(chat_id)
except Exception as e:
print(f"🚫 error - {e}")
def youtube(url: str):
try:
params = {"format": "best[height=?480]/best", "noplaylist": True}
yt = YoutubeDL(params)
info = yt.extract_info(url, download=False)
return info['url'], info['title'], info['duration']
except ExtractorError:
return None, None
except Exception:
return None, None