mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Craft the "context" data in a dedicated function
As the amount of API endpoint function grow, this will prevent ugly code copy/pasta
This commit is contained in:
parent
344ccf3b03
commit
cbabf0ae7e
1 changed files with 23 additions and 27 deletions
|
@ -6,6 +6,23 @@
|
||||||
HARDCODED_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"
|
HARDCODED_API_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"
|
||||||
HARDCODED_CLIENT_VERS = "2.20210330.08.00"
|
HARDCODED_CLIENT_VERS = "2.20210330.08.00"
|
||||||
|
|
||||||
|
####################################################################
|
||||||
|
# make_youtube_api_context(region)
|
||||||
|
#
|
||||||
|
# Return, as a Hash, the "context" data required to request the
|
||||||
|
# youtube API endpoints.
|
||||||
|
#
|
||||||
|
def make_youtube_api_context(region : String | Nil) : Hash
|
||||||
|
return {
|
||||||
|
"client" => {
|
||||||
|
"hl" => "en",
|
||||||
|
"gl" => region || "US", # Can't be empty!
|
||||||
|
"clientName" => "WEB",
|
||||||
|
"clientVersion" => HARDCODED_CLIENT_VERS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
# request_youtube_api_browse(continuation)
|
# request_youtube_api_browse(continuation)
|
||||||
# request_youtube_api_browse(browse_id, params)
|
# request_youtube_api_browse(browse_id, params)
|
||||||
|
@ -24,15 +41,8 @@ HARDCODED_CLIENT_VERS = "2.20210330.08.00"
|
||||||
def request_youtube_api_browse(continuation : String)
|
def request_youtube_api_browse(continuation : String)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
"context": {
|
"context" => make_youtube_api_context("US"),
|
||||||
"client": {
|
"continuation" => continuation,
|
||||||
"hl": "en",
|
|
||||||
"gl": "US",
|
|
||||||
"clientName": "WEB",
|
|
||||||
"clientVersion": HARDCODED_CLIENT_VERS,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"continuation": continuation,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _youtube_api_post_json("/youtubei/v1/browse", data)
|
return _youtube_api_post_json("/youtubei/v1/browse", data)
|
||||||
|
@ -42,14 +52,7 @@ def request_youtube_api_browse(browse_id : String, params : String)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
"browseId" => browse_id,
|
"browseId" => browse_id,
|
||||||
"context" => {
|
"context" => make_youtube_api_context("US"),
|
||||||
"client" => {
|
|
||||||
"hl" => "en",
|
|
||||||
"gl" => "US",
|
|
||||||
"clientName" => "WEB",
|
|
||||||
"clientVersion" => HARDCODED_CLIENT_VERS,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Append the additionnal parameters if those were provided
|
# Append the additionnal parameters if those were provided
|
||||||
|
@ -73,16 +76,9 @@ end
|
||||||
def request_youtube_api_search(search_query : String, params : String, region = nil)
|
def request_youtube_api_search(search_query : String, params : String, region = nil)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
"query": URI.encode_www_form(search_query),
|
"query" => URI.encode_www_form(search_query),
|
||||||
"context": {
|
"context" => make_youtube_api_context(region),
|
||||||
"client": {
|
"params" => params,
|
||||||
"hl": "en",
|
|
||||||
"gl": region || "US", # Can't be empty!
|
|
||||||
"clientName": "WEB",
|
|
||||||
"clientVersion": HARDCODED_CLIENT_VERS,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"params": params,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _youtube_api_post_json("/youtubei/v1/search", data)
|
return _youtube_api_post_json("/youtubei/v1/search", data)
|
||||||
|
|
Loading…
Reference in a new issue