From 7c0228288219081eb629b4cd3b02c90e169a03a7 Mon Sep 17 00:00:00 2001 From: yasir Date: Sat, 10 Dec 2022 12:03:44 +0700 Subject: [PATCH] Tes rewrite ytdl --- misskaty/plugins/ytdl_download_new.py | 36 +++++++-------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/misskaty/plugins/ytdl_download_new.py b/misskaty/plugins/ytdl_download_new.py index 55d2d69b..13c4e509 100644 --- a/misskaty/plugins/ytdl_download_new.py +++ b/misskaty/plugins/ytdl_download_new.py @@ -5,11 +5,10 @@ from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL from misskaty.core.decorator.errors import capture_err from misskaty.helper.http import http from pyrogram import filters -from iytdl import main +from iytdl import iYTDL from uuid import uuid4 LOGGER = getLogger(__name__) -ytdl = main.iYTDL(LOG_CHANNEL, download_path="iytdl/", silent=True) regex = recompile( r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P[A-Za-z0-9\-=_]{11})" ) @@ -22,28 +21,11 @@ async def ytdownv2(_, message): if len(message.command) == 1: return await message.reply("Please input a valid YT-DLP Supported URL") query = message.text.split(" ", maxsplit=1)[1] - x = await ytdl.parse("https://fb.watch/heTbglEJ8O/", extract=True) - y = await ytdl.parse("https://www.youtube.com/watch?v=VGt-BZ-SxGI") - LOGGER.info(x) - LOGGER.info(y) - # img = await get_ytthumb(key) - # caption = x.caption - # markup = x.buttons - # await message.reply_photo(img, caption=caption, reply_markup=markup) - - -async def get_ytthumb(videoid: str): - thumb_quality = [ - "maxresdefault.jpg", # Best quality - "hqdefault.jpg", - "sddefault.jpg", - "mqdefault.jpg", - "default.jpg", # Worst quality - ] - thumb_link = "https://i.imgur.com/4LwPLai.png" - for qualiy in thumb_quality: - link = f"https://i.ytimg.com/vi/{videoid}/{qualiy}" - if await http.get(link).status_code == 200: - thumb_link = link - break - return thumb_link + async with iYTDL( + log_group_id=0, cache_path="cache", ffmpeg_location="/usr/bin/mediaextract" + ) as ytdl: + x = await ytdl.parse("https://www.youtube.com/watch?v=VGt-BZ-SxGI") + img = x.image_url + caption = x.caption + markup = x.buttons + await message.reply_photo(img, caption=caption, reply_markup=markup)