summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2021-03-20 20:57:18 +0000
committerSamantaz Fox <coding@samantaz.fr>2021-03-21 15:44:18 +0100
commitf99d62a2bcd5992656217f727beb25751e11d143 (patch)
tree27d9e2fc8bc1fdbb1eb777414104d7506048254f /src
parent89be1975ea6363b864eae1974c1e07fbdf90eeb4 (diff)
downloadinvidious-f99d62a2bcd5992656217f727beb25751e11d143.tar.gz
invidious-f99d62a2bcd5992656217f727beb25751e11d143.tar.bz2
invidious-f99d62a2bcd5992656217f727beb25751e11d143.zip
Create youtube API wrapper fo /youtubei/v1/browse
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/youtube_api.cr31
1 files changed, 31 insertions, 0 deletions
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