From ccb39c09a54a342620553bbcf4f9b3eeaf80996d Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 13 Nov 2021 21:27:54 +0100 Subject: [PATCH] allow specifying fetch_ajax() endpoint and make payload configurable in preperation to move search to new api --- app/browse/__init__.py | 4 ++-- app/browse/lib.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/browse/__init__.py b/app/browse/__init__.py index 3abb294..48326ca 100644 --- a/app/browse/__init__.py +++ b/app/browse/__init__.py @@ -66,7 +66,7 @@ def channel(channel_id, subpage="videos"): # if we don't have a continuation, we create parameters for page 1 manually: continuation = request.args.get('continuation') or \ make_channel_params(channel_id, subpage, 1, sort_by, query, v3=(subpage != "search")) - result = fetch_ajax(continuation) + result = fetch_ajax("browse", continuation=continuation) error = find_and_parse_error(result) if result is None: # if fetching from innertube failed, fall back to xmlfeed: @@ -143,7 +143,7 @@ def playlist(): # if we don't have a continuation, we create parameters for page 1 manually: continuation = request.args.get('continuation') or \ make_playlist_params(playlist_id, 0) - result = fetch_ajax(continuation) + result = fetch_ajax("browse", continuation=continuation) error = find_and_parse_error(result) if result is None: diff --git a/app/browse/lib.py b/app/browse/lib.py index 4081482..f5a4afa 100644 --- a/app/browse/lib.py +++ b/app/browse/lib.py @@ -32,7 +32,7 @@ def fetch_searchresults(q=None, sp=None): except: continue # will return None once we break out of the loop -def fetch_ajax(params): +def fetch_ajax(endpoint, **kwargs): """ fetch data using a continuation protobuf """ @@ -41,8 +41,8 @@ def fetch_ajax(params): # TODO: this is not cached any more! -> https://github.com/reclosedev/requests-cache/issues/154 # Note: this 'innertube' API key exists since at least 2015: https://stackoverflow.com/q/33511165 - r = requests.post(f"https://www.youtube.com/youtubei/v1/browse?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", json={ - 'continuation': params, + r = requests.post(f"https://www.youtube.com/youtubei/v1/{endpoint}?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", json={ + **kwargs, 'context': {'client': { 'gl': 'US', 'hl': 'en', -- 2.39.3