From: Marcel van der Veldt Date: Thu, 7 Apr 2022 12:39:23 +0000 (+0200) Subject: parse contenttype from url X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=c786593353bddac0db1a6fe2cb56146217525147;p=music-assistant-server.git parse contenttype from url --- diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 3da9c274..a1d4988d 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -191,7 +191,7 @@ async def get_stream_details( provider="url", item_id=queue_item.item_id, path=queue_item.uri, - content_type=ContentType(queue_item.uri.split(".")[-1]), + content_type=ContentType.try_parse(queue_item.uri), ) else: # always request the full db track as there might be other qualities available diff --git a/music_assistant/models/media_items.py b/music_assistant/models/media_items.py index 8bd307de..a1e93656 100755 --- a/music_assistant/models/media_items.py +++ b/music_assistant/models/media_items.py @@ -259,6 +259,21 @@ class ContentType(Enum): PCM_F32LE = "f32le" # PCM 32-bit floating-point little-endian PCM_F64LE = "f64le" # PCM 64-bit floating-point little-endian + @classmethod + def try_parse( + cls: "ContentType", string: str, fallback: str = "mp3" + ) -> "ContentType": + """Try to parse ContentType from (url)string.""" + tempstr = string.lower() + if "." in tempstr: + tempstr = tempstr.split(".")[-1] + tempstr = tempstr.split("?")[0] + tempstr = tempstr.split("&")[0] + try: + return cls(tempstr) + except ValueError: + return cls(fallback) + def is_pcm(self): """Return if contentype is PCM.""" return self.name.startswith("PCM")