import os from video_dl import get_video_formats, download_video from balethon import Client, conditions from balethon.objects.message import Message import json import re url = "https://www.youtube.com/watch?v=GVPhBSmMuq8&pp=ugUEEgJlbg%3D%3D" data = get_video_formats(url=url) # print(json.dumps(data, indent=2)) # download_video(url=url, format_id="278", output="video.mp4", ffmpeg_location=r"C:\ffmpeg-master-latest-win64-gpl\bin\ffmpeg.exe") bot = Client(os.environ["BotToken"]) def is_youtube_link(event: str) -> bool: link = False if event.text: # Regular expression to match various YouTube URL formats youtube_regex = r'^(https?://)?(www\.|m\.)?(youtube\.com|youtu\.be)/' if re.match(youtube_regex, event.text): link = True return link @bot.on_message(condition=conditions.Condition(is_youtube_link)) async def greet(message: Message): user_message = message.text formats = get_video_formats(url=user_message) output_path = download_video(url=user_message, format_id=formats[-1]["format_id"]) # await message.reply("Hello") await message.reply_video(output_path) bot.run()