YoutubeAPI: Add the player() endpoint handler

This commit is contained in:
Samantaz Fox 2021-07-26 17:23:53 +02:00
parent c39413289a
commit 75e196adcc
No known key found for this signature in database
GPG Key ID: F42821059186176E

View File

@ -221,6 +221,38 @@ module YoutubeAPI
return self.next(data.to_h, client_config: client_config)
end
####################################################################
# player(video_id, params, client_config?)
#
# Requests the youtubei/v1/player endpoint with the required headers
# and POST data in order to get a JSON reply.
#
# The requested data is a video ID (`v=` parameter), with some
# additional paramters, formatted as a base64 string.
#
# An optional ClientConfig parameter can be passed, too (see
# `struct ClientConfig` above for more details).
#
def player(
video_id : String,
*, # Force the following paramters to be passed by name
params : String,
client_config : ClientConfig | Nil = nil
)
# JSON Request data, required by the API
data = {
"videoId" => video_id,
"context" => self.make_context(client_config),
}
# Append the additionnal parameters if those were provided
if params != ""
data["params"] = params
end
return self._post_json("/youtubei/v1/player", data, client_config)
end
####################################################################
# search(search_query, params, client_config?)
#