get_watch_playlist: fixed an issue when longBylineText is missing
This commit is contained in:
parent
c8af65d643
commit
cc26a63264
3 changed files with 16 additions and 9 deletions
|
|
@ -5,8 +5,8 @@ import pytest
|
||||||
|
|
||||||
class TestBrowsing:
|
class TestBrowsing:
|
||||||
def test_get_home(self, yt, yt_auth):
|
def test_get_home(self, yt, yt_auth):
|
||||||
result = yt.get_home(limit=6)
|
result = yt.get_home()
|
||||||
assert len(result) >= 6
|
assert len(result) == 2
|
||||||
result = yt_auth.get_home(limit=15)
|
result = yt_auth.get_home(limit=15)
|
||||||
assert len(result) >= 15
|
assert len(result) >= 15
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,21 @@ def populate_account():
|
||||||
|
|
||||||
# add some albums, which also populates songs and artists as a side effect
|
# 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"])
|
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:
|
for playlist_id in playlist_ids:
|
||||||
print(f"Adding album {playlist_id}")
|
print(f"Adding album {playlist_id}")
|
||||||
yt_brand.rate_playlist(playlist_id, "LIKE")
|
yt_brand.rate_playlist(playlist_id, "LIKE")
|
||||||
|
|
||||||
# like some songs
|
# like some songs
|
||||||
for track in yt_playlist["tracks"]:
|
videoIds = list(
|
||||||
print(f"liking track {track['videoId']}")
|
set(
|
||||||
yt_brand.rate_song(track["videoId"], "LIKE")
|
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
|
# create own playlist
|
||||||
playlistId = yt_brand.create_playlist(
|
playlistId = yt_brand.create_playlist(
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,6 @@ def parse_watch_track(data):
|
||||||
if "likeEndpoint" in service:
|
if "likeEndpoint" in service:
|
||||||
like_status = parse_like_status(service)
|
like_status = parse_like_status(service)
|
||||||
|
|
||||||
song_info = parse_song_runs(data["longBylineText"]["runs"])
|
|
||||||
|
|
||||||
track = {
|
track = {
|
||||||
"videoId": data["videoId"],
|
"videoId": data["videoId"],
|
||||||
"title": nav(data, TITLE_TEXT),
|
"title": nav(data, TITLE_TEXT),
|
||||||
|
|
@ -49,7 +47,10 @@ def parse_watch_track(data):
|
||||||
"inLibrary": library_status,
|
"inLibrary": library_status,
|
||||||
"videoType": nav(data, ["navigationEndpoint", *NAVIGATION_VIDEO_TYPE], True),
|
"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
|
return track
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue