Fix: guard error in selecting YTM stream
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 16 Mar 2025 08:40:57 +0000 (09:40 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 16 Mar 2025 08:40:57 +0000 (09:40 +0100)
Prevent error "StopIteration interacts badly with generators"

music_assistant/providers/ytmusic/__init__.py

index adf286ee748ce2205d0b7dbd106e5d03389d2b2d..38d25399b8b0b13463398835e490a4d5b0cd141e 100644 (file)
@@ -862,7 +862,8 @@ class YoutubeMusicProvider(MusicProvider):
                 except yt_dlp.utils.DownloadError as err:
                     raise UnplayableMediaError(err) from err
                 format_selector = ydl.build_format_selector("m4a/bestaudio")
-                stream_format = next(format_selector({"formats": info["formats"]}))
+                if not (stream_format := next(format_selector({"formats": info["formats"]})), None):
+                    raise UnplayableMediaError("No stream formats found")
                 return stream_format
 
         return await asyncio.to_thread(_extract_best_stream_url_format)