From c33d4cc64e139098e042220f03688de7f59807bd Mon Sep 17 00:00:00 2001 From: Solomon Date: Tue, 26 Aug 2025 11:09:10 +0000 Subject: [PATCH] get_home: parse recommended channels (#807) Handle channel links in `parse_mixed_content`: ```diff [ { "title": "Channels you may like", "contents": [ - None + { + "title": "MTV UK", + "browseId": "UCuwUfM8E79h2sqp34Fut6kw", + "subscribers": "2.32M", + "thumbnails": [...] + } ``` --- tests/mixins/test_browsing.py | 6 +++++- ytmusicapi/parsers/browsing.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/mixins/test_browsing.py b/tests/mixins/test_browsing.py index f733dd5..0c7b735 100644 --- a/tests/mixins/test_browsing.py +++ b/tests/mixins/test_browsing.py @@ -13,7 +13,7 @@ class TestBrowsing: def test_get_home(self, yt, yt_auth): result = yt.get_home() assert len(result) >= 2 - result = yt_auth.get_home(limit=15) + result = yt_auth.get_home(limit=20) assert len(result) >= 15 assert all( # ensure we aren't parsing specifiers like "Song" as artist names @@ -25,6 +25,10 @@ class TestBrowsing: if item and len(item.get("artists", [])) > 1 ] ) + assert all( + # ensure all links are supported by parse_mixed_content + [item is not None for section in result for item in section["contents"]] + ) def test_get_artist(self, yt): results = yt.get_artist("MPLAUCmMUZbaYdNH0bEd1PAlAqsA") diff --git a/ytmusicapi/parsers/browsing.py b/ytmusicapi/parsers/browsing.py index 1862705..e3efea7 100644 --- a/ytmusicapi/parsers/browsing.py +++ b/ytmusicapi/parsers/browsing.py @@ -34,7 +34,7 @@ def parse_mixed_content( content = parse_song(data) elif page_type == "MUSIC_PAGE_TYPE_ALBUM": content = parse_album(data) - elif page_type == "MUSIC_PAGE_TYPE_ARTIST": + elif page_type in ["MUSIC_PAGE_TYPE_ARTIST", "MUSIC_PAGE_TYPE_USER_CHANNEL"]: content = parse_related_artist(data) elif page_type == "MUSIC_PAGE_TYPE_PLAYLIST": content = parse_playlist(data)