Skip to content

Commit

Permalink
get_watch_playlist: fixed an issue when longBylineText is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Feb 4, 2024
1 parent c8af65d commit cc26a63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/mixins/test_browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

class TestBrowsing:
def test_get_home(self, yt, yt_auth):
result = yt.get_home(limit=6)
assert len(result) >= 6
result = yt.get_home()
assert len(result) == 2
result = yt_auth.get_home(limit=15)
assert len(result) >= 15

Expand Down
14 changes: 10 additions & 4 deletions tests/setup/setup_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ def populate_account():

# add some albums, which also populates songs and artists as a side effect
unique_albums = set(track["album"]["id"] for track in yt_playlist["tracks"])
playlist_ids = [yt_brand.get_album(album)["audioPlaylistId"] for album in unique_albums if album]
albums = [yt_brand.get_album(album) for album in unique_albums if album]
playlist_ids = [album["audioPlaylistId"] for album in albums]
for playlist_id in playlist_ids:
print(f"Adding album {playlist_id}")
yt_brand.rate_playlist(playlist_id, "LIKE")

# like some songs
for track in yt_playlist["tracks"]:
print(f"liking track {track['videoId']}")
yt_brand.rate_song(track["videoId"], "LIKE")
videoIds = list(
set(
track["videoId"] for track in itertools.chain.from_iterable([album["tracks"] for album in albums])
)
)
for videoId in videoIds[:200]:
print(f"Liking track {videoId}")
yt_brand.rate_song(videoId, "LIKE")

# create own playlist
playlistId = yt_brand.create_playlist(
Expand Down
7 changes: 4 additions & 3 deletions ytmusicapi/parsers/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def parse_watch_track(data):
if "likeEndpoint" in service:
like_status = parse_like_status(service)

song_info = parse_song_runs(data["longBylineText"]["runs"])

track = {
"videoId": data["videoId"],
"title": nav(data, TITLE_TEXT),
Expand All @@ -49,7 +47,10 @@ def parse_watch_track(data):
"inLibrary": library_status,
"videoType": nav(data, ["navigationEndpoint", *NAVIGATION_VIDEO_TYPE], True),
}
track.update(song_info)
if longBylineText := nav(data, ["longBylineText"]):
song_info = parse_song_runs(longBylineText["runs"])
track.update(song_info)

return track


Expand Down

0 comments on commit cc26a63

Please sign in to comment.