get_home: fix song artist parsing (#798)

* get_home: fix song artist parsing

extra text is now excluded from `artists`:

- `get_home`/`get_song_related`: play counts in certain track carousels
- `get_home`: "Song" specifiers for audio tracks

`get_explore` song charts are also no longer missing `album` data

* skip type specifiers in parse_song_runs without comparing text
This commit is contained in:
Solomon 2025-08-23 17:21:54 +00:00 • committed by GitHub
commit e738b2a70f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 118 additions and 68 deletions

View file

@ -15,6 +15,16 @@ class TestBrowsing:
assert len(result) >= 2
result = yt_auth.get_home(limit=15)
assert len(result) >= 15
assert all(
# ensure we aren't parsing specifiers like "Song" as artist names
[
item["artists"][0]["id"]
or item["artists"][0]["name"].lower() not in yt_auth.parser.get_api_result_types()
for section in result
for item in section["contents"]
if item and len(item.get("artists", [])) > 1
]
)
def test_get_artist(self, yt):
results = yt.get_artist("MPLAUCmMUZbaYdNH0bEd1PAlAqsA")
@ -179,6 +189,15 @@ class TestBrowsing:
song = yt_oauth.get_watch_playlist(sample_video)
song = yt_oauth.get_song_related(song["related"])
assert len(song) >= 5
assert all(
# ensure every video is associated with a view count or music album
[
item.get("views") or item.get("album")
for section in song
for item in section["contents"]
if "videoId" in item
]
)
def test_get_lyrics(self, config, yt, sample_video):
playlist = yt.get_watch_playlist(sample_video)

View file

@ -16,7 +16,10 @@ class TestExplore:
assert all(item["audioPlaylistId"].startswith("OLA") for item in explore["new_releases"])
# check top_songs if present
assert all(item["videoId"] for item in explore.get("top_songs", {"items": []})["items"])
assert all(
item["videoId"] and (item.get("views") or item.get("album"))
for item in explore.get("top_songs", {"items": []})["items"]
)
assert all(
item["videoId"] and all(artist["id"] for artist in item["artists"])

View file

@ -142,6 +142,16 @@ class TestSearch:
"name": "Stanford GSB Podcasts",
}
def test_search_top_result_video(self, yt):
results = yt.search("Fuel Eminem")
assert results[0]["category"] == "Top result"
assert results[0]["resultType"] == "video"
assert results[0]["videoId"] == "t5H_CewqpKA"
assert results[0]["artists"] == [
{"name": "Eminem", "id": "UCedvOgsKFzcK3hA5taf3KoQ"},
{"name": "JID", "id": "UCRlGNubLJBgW9VRCuiUnuYw"},
]
def test_search_uploads(self, config, yt, yt_oauth):
with pytest.raises(Exception, match="No filter can be set when searching uploads"):
yt.search(