get_watch_playlist: move playlistId to top level of dictionary (same for all results)
This commit is contained in:
parent
755eed2753
commit
a883f1c6ab
2 changed files with 15 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Dict
|
from typing import List, Dict, Union
|
||||||
from ytmusicapi.parsers.watch import *
|
from ytmusicapi.parsers.watch import *
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ class WatchMixin:
|
||||||
videoId: str = None,
|
videoId: str = None,
|
||||||
playlistId: str = None,
|
playlistId: str = None,
|
||||||
limit=25,
|
limit=25,
|
||||||
params: str = None) -> Dict[List[Dict], str]:
|
params: str = None) -> Dict[str, Union[List[Dict]]]:
|
||||||
"""
|
"""
|
||||||
Get a watch list of tracks. This watch playlist appears when you press
|
Get a watch list of tracks. This watch playlist appears when you press
|
||||||
play on a track in YouTube Music.
|
play on a track in YouTube Music.
|
||||||
|
|
@ -31,7 +31,6 @@ class WatchMixin:
|
||||||
"byline": "Patrik Pietschmann • 47M views",
|
"byline": "Patrik Pietschmann • 47M views",
|
||||||
"length": "4:47",
|
"length": "4:47",
|
||||||
"videoId": "4y33h81phKU",
|
"videoId": "4y33h81phKU",
|
||||||
"playlistId": "RDAMVM4y33h81phKU",
|
|
||||||
"thumbnail": [
|
"thumbnail": [
|
||||||
{
|
{
|
||||||
"url": "https://i.ytimg.com/vi/4y...",
|
"url": "https://i.ytimg.com/vi/4y...",
|
||||||
|
|
@ -43,6 +42,7 @@ class WatchMixin:
|
||||||
"likeStatus": "LIKE"
|
"likeStatus": "LIKE"
|
||||||
},...
|
},...
|
||||||
],
|
],
|
||||||
|
"playlist": "RDAMVM4y33h81phKU",
|
||||||
"lyrics": "MPLYt_HNNclO0Ddoc-17"
|
"lyrics": "MPLYt_HNNclO0Ddoc-17"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +77,12 @@ class WatchMixin:
|
||||||
|
|
||||||
results = nav(watchNextRenderer,
|
results = nav(watchNextRenderer,
|
||||||
TAB_CONTENT + ['musicQueueRenderer', 'content', 'playlistPanelRenderer'])
|
TAB_CONTENT + ['musicQueueRenderer', 'content', 'playlistPanelRenderer'])
|
||||||
|
playlist = next(
|
||||||
|
filter(
|
||||||
|
bool,
|
||||||
|
map(
|
||||||
|
lambda x: nav(x, ['playlistPanelVideoRenderer'] + NAVIGATION_PLAYLIST_ID, True
|
||||||
|
), results['contents'])), None)
|
||||||
tracks = parse_watch_playlist(results['contents'])
|
tracks = parse_watch_playlist(results['contents'])
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
|
|
@ -87,12 +93,12 @@ class WatchMixin:
|
||||||
get_continuations(results, 'playlistPanelContinuation', limit - len(tracks),
|
get_continuations(results, 'playlistPanelContinuation', limit - len(tracks),
|
||||||
request_func, parse_func, '' if is_playlist else 'Radio'))
|
request_func, parse_func, '' if is_playlist else 'Radio'))
|
||||||
|
|
||||||
return {'tracks': tracks, 'lyrics': lyrics_browse_id}
|
return dict(tracks=tracks, playlistId=playlist, lyrics=lyrics_browse_id)
|
||||||
|
|
||||||
def get_watch_playlist_shuffle(self,
|
def get_watch_playlist_shuffle(self,
|
||||||
videoId: str = None,
|
videoId: str = None,
|
||||||
playlistId: str = None,
|
playlistId: str = None,
|
||||||
limit=50) -> Dict[List[Dict], str]:
|
limit=50) -> Dict[str, Union[List[Dict]]]:
|
||||||
"""
|
"""
|
||||||
Shuffle any playlist
|
Shuffle any playlist
|
||||||
|
|
||||||
|
|
@ -101,4 +107,7 @@ class WatchMixin:
|
||||||
:param limit: The number of watch playlist items to return
|
:param limit: The number of watch playlist items to return
|
||||||
:return: A list of watch playlist items (see :py:func:`get_watch_playlist`)
|
:return: A list of watch playlist items (see :py:func:`get_watch_playlist`)
|
||||||
"""
|
"""
|
||||||
return self.get_watch_playlist(videoId=videoId, playlistId=playlistId, limit=limit, params='wAEB8gECKAE%3D')
|
return self.get_watch_playlist(videoId=videoId,
|
||||||
|
playlistId=playlistId,
|
||||||
|
limit=limit,
|
||||||
|
params='wAEB8gECKAE%3D')
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ def parse_watch_playlist(results):
|
||||||
'videoId': data['videoId'],
|
'videoId': data['videoId'],
|
||||||
'title': nav(data, TITLE_TEXT),
|
'title': nav(data, TITLE_TEXT),
|
||||||
'length': nav(data, ['lengthText', 'runs', 0, 'text'], True),
|
'length': nav(data, ['lengthText', 'runs', 0, 'text'], True),
|
||||||
'playlistId': nav(data, NAVIGATION_PLAYLIST_ID),
|
|
||||||
'thumbnail': nav(data, THUMBNAIL),
|
'thumbnail': nav(data, THUMBNAIL),
|
||||||
'feedbackTokens': feedback_tokens,
|
'feedbackTokens': feedback_tokens,
|
||||||
'likeStatus': like_status
|
'likeStatus': like_status
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue