get_watch_playlist: parse and return counterpart for songs with video counterparts
This commit is contained in:
parent
e1c77f1da0
commit
7ebb57d2a5
2 changed files with 91 additions and 34 deletions
|
|
@ -20,26 +20,72 @@ class WatchMixin:
|
||||||
:param playlistId: playlistId of the played playlist or album
|
:param playlistId: playlistId of the played playlist or album
|
||||||
:param limit: minimum number of watch playlist items to return
|
:param limit: minimum number of watch playlist items to return
|
||||||
:param params: only used internally by :py:func:`get_watch_playlist_shuffle`
|
:param params: only used internally by :py:func:`get_watch_playlist_shuffle`
|
||||||
:return: List of watch playlist items.
|
:return: List of watch playlist items. The counterpart key is optional and only
|
||||||
|
appears if a song has a corresponding video counterpart (UI song/video
|
||||||
|
switcher).
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
{
|
{
|
||||||
"tracks": [
|
"tracks": [
|
||||||
{
|
{
|
||||||
"title": "Interstellar (Main Theme) - Piano Version",
|
"videoId": "9mWr4c_ig54",
|
||||||
"byline": "Patrik Pietschmann • 47M views",
|
"title": "Foolish Of Me (feat. Jonathan Mendelsohn)",
|
||||||
"length": "4:47",
|
"length": "3:07",
|
||||||
"videoId": "4y33h81phKU",
|
|
||||||
"thumbnail": [
|
"thumbnail": [
|
||||||
{
|
{
|
||||||
"url": "https://i.ytimg.com/vi/4y...",
|
"url": "https://lh3.googleusercontent.com/ulK2YaLtOW0PzcN7ufltG6e4ae3WZ9Bvg8CCwhe6LOccu1lCKxJy2r5AsYrsHeMBSLrGJCNpJqXgwczk=w60-h60-l90-rj",
|
||||||
"width": 400,
|
"width": 60,
|
||||||
"height": 225
|
"height": 60
|
||||||
|
}...
|
||||||
|
],
|
||||||
|
"feedbackTokens": {
|
||||||
|
"add": "AB9zfpIGg9XN4u2iJ...",
|
||||||
|
"remove": "AB9zfpJdzWLcdZtC..."
|
||||||
|
},
|
||||||
|
"likeStatus": "INDIFFERENT",
|
||||||
|
"artists": [
|
||||||
|
{
|
||||||
|
"name": "Seven Lions",
|
||||||
|
"id": "UCYd2yzYRx7b9FYnBSlbnknA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jason Ross",
|
||||||
|
"id": "UCVCD9Iwnqn2ipN9JIF6B-nA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Crystal Skies",
|
||||||
|
"id": "UCTJZESxeZ0J_M7JXyFUVmvA"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"feedbackTokens": [],
|
"album": {
|
||||||
"likeStatus": "LIKE"
|
"name": "Foolish Of Me",
|
||||||
|
"id": "MPREb_C8aRK1qmsDJ"
|
||||||
|
},
|
||||||
|
"year": "2020",
|
||||||
|
"counterpart": {
|
||||||
|
"videoId": "E0S4W34zFMA",
|
||||||
|
"title": "Foolish Of Me [ABGT404] (feat. Jonathan Mendelsohn)",
|
||||||
|
"length": "3:07",
|
||||||
|
"thumbnail": [...],
|
||||||
|
"feedbackTokens": null,
|
||||||
|
"likeStatus": "LIKE",
|
||||||
|
"artists": [
|
||||||
|
{
|
||||||
|
"name": "Jason Ross",
|
||||||
|
"id": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Seven Lions",
|
||||||
|
"id": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Crystal Skies",
|
||||||
|
"id": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"views": "6.6K"
|
||||||
|
}
|
||||||
},...
|
},...
|
||||||
],
|
],
|
||||||
"playlistId": "RDAMVM4y33h81phKU",
|
"playlistId": "RDAMVM4y33h81phKU",
|
||||||
|
|
|
||||||
|
|
@ -4,35 +4,46 @@ from .songs import *
|
||||||
|
|
||||||
def parse_watch_playlist(results):
|
def parse_watch_playlist(results):
|
||||||
tracks = []
|
tracks = []
|
||||||
|
PPVWR = 'playlistPanelVideoWrapperRenderer'
|
||||||
|
PPVR = 'playlistPanelVideoRenderer'
|
||||||
for result in results:
|
for result in results:
|
||||||
if 'playlistPanelVideoWrapperRenderer' in result:
|
counterpart = None
|
||||||
result = result['playlistPanelVideoWrapperRenderer']['primaryRenderer']
|
if PPVWR in result:
|
||||||
if 'playlistPanelVideoRenderer' not in result:
|
counterpart = result[PPVWR]['counterpart'][0]['counterpartRenderer'][PPVR]
|
||||||
|
result = result[PPVWR]['primaryRenderer']
|
||||||
|
if PPVR not in result:
|
||||||
continue
|
continue
|
||||||
data = result['playlistPanelVideoRenderer']
|
data = result[PPVR]
|
||||||
if 'unplayableText' in data:
|
if 'unplayableText' in data:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
feedback_tokens = like_status = None
|
track = parse_watch_track(data)
|
||||||
for item in nav(data, MENU_ITEMS):
|
if counterpart:
|
||||||
if TOGGLE_MENU in item:
|
track['counterpart'] = parse_watch_track(counterpart)
|
||||||
service = item[TOGGLE_MENU]['defaultServiceEndpoint']
|
|
||||||
if 'feedbackEndpoint' in service:
|
|
||||||
feedback_tokens = parse_song_menu_tokens(item)
|
|
||||||
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),
|
|
||||||
'length': nav(data, ['lengthText', 'runs', 0, 'text'], True),
|
|
||||||
'thumbnail': nav(data, THUMBNAIL),
|
|
||||||
'feedbackTokens': feedback_tokens,
|
|
||||||
'likeStatus': like_status
|
|
||||||
}
|
|
||||||
track.update(song_info)
|
|
||||||
tracks.append(track)
|
tracks.append(track)
|
||||||
|
|
||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
|
|
||||||
|
def parse_watch_track(data):
|
||||||
|
feedback_tokens = like_status = None
|
||||||
|
for item in nav(data, MENU_ITEMS):
|
||||||
|
if TOGGLE_MENU in item:
|
||||||
|
service = item[TOGGLE_MENU]['defaultServiceEndpoint']
|
||||||
|
if 'feedbackEndpoint' in service:
|
||||||
|
feedback_tokens = parse_song_menu_tokens(item)
|
||||||
|
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),
|
||||||
|
'length': nav(data, ['lengthText', 'runs', 0, 'text'], True),
|
||||||
|
'thumbnail': nav(data, THUMBNAIL),
|
||||||
|
'feedbackTokens': feedback_tokens,
|
||||||
|
'likeStatus': like_status
|
||||||
|
}
|
||||||
|
track.update(song_info)
|
||||||
|
return track
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue