From 3723ae6eb5540489a6ee3b538244debade49d058 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 13 Sep 2021 05:47:27 +0700 Subject: [PATCH] improve added video name, duration when starting streaming youtube video --- bot/videoplayer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/videoplayer.py b/bot/videoplayer.py index 32eaa9d..e727b96 100644 --- a/bot/videoplayer.py +++ b/bot/videoplayer.py @@ -52,8 +52,8 @@ def youtube(url: str): params = {"format": "best[height=?480]/best", "noplaylist": True} yt = YoutubeDL(params) info = yt.extract_info(url, download=False) - return info['url'] - except ExtractorError: # do whatever + return info['url'], return info['title'], return info['duration'] + except ExtractorError: return except Exception: return @@ -70,7 +70,7 @@ async def startvideo(client, m: Message): livelink = m.text.split(None, 1)[1] chat_id = m.chat.id try: - livelink = await asyncio.wait_for( + livelink, title, duration = await asyncio.wait_for( app.loop.run_in_executor( None, lambda : youtube(livelink) @@ -111,7 +111,11 @@ async def startvideo(client, m: Message): ), stream_type=StreamType().local_stream, ) - await msg.edit("💡 **video streaming started!**\n\n» **join to video chat on the top to watch the video.**") + await msg.edit( + "💡 **video streaming started!**\n" + f"\n🏷 **Name:** {title}" + f"⏱ **Duration:** {duration}\n" + f"\n» **join to video chat on the top to watch the video.**") await idle() except Exception as e: await msg.edit(f"🚫 **error** | `{e}`")