From f08a95e32f7461385617b85fdb0ca046a92fa6a6 Mon Sep 17 00:00:00 2001 From: Nikita Zavadin Date: Wed, 11 Sep 2024 00:05:54 +0200 Subject: [PATCH] Fix yt search --- lib/players/stream.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/players/stream.py b/lib/players/stream.py index 7cd422a..8d8227e 100644 --- a/lib/players/stream.py +++ b/lib/players/stream.py @@ -32,7 +32,7 @@ async def get_audio(self, meta: AudioMeta) -> FFmpegOpusAudio: async def get_info(self, url: str) -> AudioMeta: with YoutubeDL(self.ydl_opts) as ydl: info = ydl.extract_info(str(url), download=False) - video_info = info['formats'][0] + video_info = _find_video_info(info) return AudioMeta( author=info.get('uploader', 'Unknown'), @@ -40,3 +40,11 @@ async def get_info(self, url: str) -> AudioMeta: name=info['title'], original_url=url, ) + + +def _find_video_info(info: dict) -> dict: + for video_format in info['formats']: + if video_format.get('audio_ext', 'none') != 'none': + return video_format + + raise ValueError('No audio format found')