From f1bcd06c7333eb6a7900a6f68443022c0d6e6d3f Mon Sep 17 00:00:00 2001 From: Fabian Munkes <105975993+fmunkes@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:27:31 +0200 Subject: [PATCH] Ignore a guid containing spaces in podcasts parsing (#2238) --- music_assistant/helpers/podcast_parsers.py | 10 +++++++++- music_assistant/providers/gpodder/__init__.py | 7 ++++++- music_assistant/providers/itunes_podcasts/__init__.py | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/music_assistant/helpers/podcast_parsers.py b/music_assistant/helpers/podcast_parsers.py index 1f141498..d471cd20 100644 --- a/music_assistant/helpers/podcast_parsers.py +++ b/music_assistant/helpers/podcast_parsers.py @@ -83,6 +83,13 @@ def get_stream_url_and_guid_from_episode(*, episode: dict[str, Any]) -> tuple[st raise ValueError("Episode enclosure is missing") if stream_url := episode_enclosures[0].get("url"): guid = episode.get("guid") + if guid is not None: + # The media's item_id is {prov_podcast_id} {guid_or_stream_url} + # see parse_podcast_episode. + # However, the guid must not contain a space, otherwise it is invalid. + # We cannot check, if it is a proper guid (uuid.UUID4(...)), as some podcast feeds + # do not follow the standard. + guid = None if len(guid.split(" ")) > 1 else guid return stream_url, guid raise ValueError("Stream URL is missing.") @@ -120,7 +127,8 @@ def parse_podcast_episode( except ValueError: # we are missing the episode enclosure or stream information return None - guid_or_stream_url = guid if guid is not None else stream_url + # We treat a guid as invalid if contains a space. + guid_or_stream_url = guid if guid is not None and len(guid.split(" ")) == 1 else stream_url # Default episode id. A guid is preferred as identification. episode_id = f"{prov_podcast_id} {guid_or_stream_url}" if mass_item_id is None else mass_item_id diff --git a/music_assistant/providers/gpodder/__init__.py b/music_assistant/providers/gpodder/__init__.py index 7c964f67..8d1112ef 100644 --- a/music_assistant/providers/gpodder/__init__.py +++ b/music_assistant/providers/gpodder/__init__.py @@ -612,7 +612,12 @@ class GPodder(MusicProvider): if len(episode_enclosures) < 1: raise MediaNotFoundError stream_url: str | None = episode_enclosures[0].get("url", None) - if guid_or_stream_url == episode.get("guid", stream_url): + guid = episode.get("guid") + if guid is not None and len(guid.split(" ")) == 1: + _guid_or_stream_url_compare = guid + else: + _guid_or_stream_url_compare = stream_url + if guid_or_stream_url == _guid_or_stream_url_compare: return stream_url return None diff --git a/music_assistant/providers/itunes_podcasts/__init__.py b/music_assistant/providers/itunes_podcasts/__init__.py index a258a901..ce0a3f24 100644 --- a/music_assistant/providers/itunes_podcasts/__init__.py +++ b/music_assistant/providers/itunes_podcasts/__init__.py @@ -275,7 +275,12 @@ class ITunesPodcastsProvider(MusicProvider): if len(episode_enclosures) < 1: raise MediaNotFoundError stream_url: str | None = episode_enclosures[0].get("url", None) - if guid_or_stream_url == episode.get("guid", stream_url): + guid = episode.get("guid") + if guid is not None and len(guid.split(" ")) == 1: + _guid_or_stream_url_compare = guid + else: + _guid_or_stream_url_compare = stream_url + if guid_or_stream_url == _guid_or_stream_url_compare: return stream_url return None -- 2.34.1