remove get_playlist_suggestions - add suggestions and related to get_playlist
get_playlist_suggestions was not working anymore due to changes on YouTube's end calls to the playlist page on YouTube Music now also return co-dependent continuations for suggestions and related items to support both, these continuations are now part of get_playlist, but made optional through function parameters default values are set backwards-compatible, i.e. no extra requests are performed without setting the new parameters
This commit is contained in:
parent
3ab1d91a93
commit
c2d5e46805
4 changed files with 94 additions and 45 deletions
|
|
@ -1,10 +1,17 @@
|
|||
from ytmusicapi.navigation import nav
|
||||
|
||||
|
||||
def get_continuations(results, continuation_type, limit, request_func, parse_func, ctoken_path=""):
|
||||
def get_continuations(results,
|
||||
continuation_type,
|
||||
limit,
|
||||
request_func,
|
||||
parse_func,
|
||||
ctoken_path="",
|
||||
reloadable=False):
|
||||
items = []
|
||||
while 'continuations' in results and (limit is None or len(items) < limit):
|
||||
additionalParams = get_continuation_params(results, ctoken_path)
|
||||
additionalParams = get_reloadable_continuation_params(results) if reloadable \
|
||||
else get_continuation_params(results, ctoken_path)
|
||||
response = request_func(additionalParams)
|
||||
if 'continuationContents' in response:
|
||||
results = response['continuationContents'][continuation_type]
|
||||
|
|
@ -46,12 +53,17 @@ def get_parsed_continuation_items(response, parse_func, continuation_type):
|
|||
return {'results': results, 'parsed': get_continuation_contents(results, parse_func)}
|
||||
|
||||
|
||||
def get_continuation_params(results, ctoken_path):
|
||||
def get_continuation_params(results, ctoken_path=''):
|
||||
ctoken = nav(results,
|
||||
['continuations', 0, 'next' + ctoken_path + 'ContinuationData', 'continuation'])
|
||||
return get_continuation_string(ctoken)
|
||||
|
||||
|
||||
def get_reloadable_continuation_params(results):
|
||||
ctoken = nav(results, ['continuations', 0, 'reloadContinuationData', 'continuation'])
|
||||
return get_continuation_string(ctoken)
|
||||
|
||||
|
||||
def get_continuation_string(ctoken):
|
||||
return "&ctoken=" + ctoken + "&continuation=" + ctoken
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue