This commit is contained in:
zxce3 2021-09-13 15:24:54 +07:00
parent cb727e36c3
commit ca8c651250

42
helpers/utils.py Normal file
View File

@ -0,0 +1,42 @@
from youtube_dl import YoutubeDL
from youtube_dl.utils import ExtractorError
###############
# 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_PROCESSES.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