YoutubeAPI: Add the resolve_url() endpoint handler

This commit is contained in:
Samantaz Fox 2021-07-26 17:27:47 +02:00
parent 75e196adcc
commit 79a638e059
No known key found for this signature in database
GPG key ID: F42821059186176E

View file

@ -253,6 +253,40 @@ module YoutubeAPI
return self._post_json("/youtubei/v1/player", data, client_config)
end
####################################################################
# resolve_url(url)
#
# Requests the youtubei/v1/navigation/resolve_url endpoint with the
# required headers and POST data in order to get a JSON reply.
#
# Output:
#
# ```
# # Valid channel "brand URL" gives the related UCID and browse ID
# channel_a = YoutubeAPI.resolve_url("https://youtube.com/c/google")
# channel_a # => {
# "endpoint": {
# "browseEndpoint": {
# "params": "EgC4AQA%3D",
# "browseId":"UCK8sQmJBp8GCxrOtXWBpyEA"
# },
# ...
# }
# }
#
# # Invalid URL returns throws an InfoException
# channel_b = YoutubeAPI.resolve_url("https://youtube.com/c/invalid")
# ```
#
def resolve_url(url : String)
data = {
"context" => self.make_context(nil),
"url" => url,
}
return self._post_json("/youtubei/v1/navigation/resolve_url", data)
end
####################################################################
# search(search_query, params, client_config?)
#