From f99d62a2bcd5992656217f727beb25751e11d143 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sat, 20 Mar 2021 20:57:18 +0000 Subject: [PATCH] Create youtube API wrapper fo /youtubei/v1/browse --- src/invidious/helpers/youtube_api.cr | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/invidious/helpers/youtube_api.cr diff --git a/src/invidious/helpers/youtube_api.cr b/src/invidious/helpers/youtube_api.cr new file mode 100644 index 00000000..0ae80318 --- /dev/null +++ b/src/invidious/helpers/youtube_api.cr @@ -0,0 +1,31 @@ +# +# This file contains youtube API wrappers +# + +# Hard-coded constants required by the API +HARDCODED_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8" +HARDCODED_CLIENT_VERS = "2.20210318.08.00" + +def request_youtube_api_browse(continuation) + # JSON Request data, required by the API + data = { + "context": { + "client": { + "hl": "en", + "gl": "US", + "clientName": "WEB", + "clientVersion": HARDCODED_CLIENT_VERS, + }, + }, + "continuation": continuation, + } + + # Send the POST request and return result + response = YT_POOL.client &.post( + "/youtubei/v1/browse?key=#{HARDCODED_API_KEY}", + headers: HTTP::Headers{"content-type" => "application/json"}, + body: data.to_json + ) + + return response.body +end