module YoutubeAPI
Extended Modules
Defined in:
invidious/helpers/youtube_api.crConstant Summary
-
DEFAULT_CLIENT_CONFIG =
ClientConfig.new
-
Default client config, used if nothing is passed
-
HARDCODED_CLIENTS =
{ClientType::Web => {name: "WEB", version: "2.20210721.00.00", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: "WATCH_FULL_SCREEN"}, ClientType::WebEmbeddedPlayer => {name: "WEB_EMBEDDED_PLAYER", version: "1.20210721.1.0", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: "EMBED"}, ClientType::WebMobile => {name: "MWEB", version: "2.20210726.08.00", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: ""}, ClientType::WebScreenEmbed => {name: "WEB", version: "2.20210721.00.00", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: "EMBED"}, ClientType::Android => {name: "ANDROID", version: "16.20", api_key: "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w", screen: ""}, ClientType::AndroidEmbeddedPlayer => {name: "ANDROID_EMBEDDED_PLAYER", version: "16.20", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: ""}, ClientType::AndroidScreenEmbed => {name: "ANDROID", version: "16.20", api_key: "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8", screen: "EMBED"}}
-
List of hard-coded values used by the different clients
Instance Method Summary
-
#_post_json(endpoint : String, data : Hash, client_config : ClientConfig | Nil) : Hash(String, JSON::Any)
################################################################### _post_json(endpoint, data, client_config?)
-
#browse(continuation : String, client_config : ClientConfig | Nil = nil)
################################################################### browse(continuation, client_config?) browse(browse_id, params, client_config?)
-
#browse(browse_id : String, *, params : String, client_config : ClientConfig | Nil = nil)
################################################################### browse(continuation, client_config?) browse(browse_id, params, client_config?)
-
#next(continuation : String, *, client_config : ClientConfig | Nil = nil)
################################################################### next(continuation, client_config?) next(data, client_config?)
-
#next(data : Hash, *, client_config : ClientConfig | Nil = nil)
################################################################### next(continuation, client_config?) next(data, client_config?)
-
#next(data : NamedTuple, *, client_config : ClientConfig | Nil = nil)
Allow a NamedTuple to be passed, too.
-
#player(video_id : String, *, params : String, client_config : ClientConfig | Nil = nil)
################################################################### player(video_id, params, client_config?)
-
#resolve_url(url : String, client_config : ClientConfig | Nil = nil)
################################################################### resolve_url(url, client_config?)
-
#search(search_query : String, params : String, client_config : ClientConfig | Nil = nil)
################################################################### search(search_query, params, client_config?)
Instance Method Detail
################################################################### _post_json(endpoint, data, client_config?)
Internal function that does the actual request to youtube servers and handles errors.
The requested data is an endpoint (URL without the domain part) and the data as a Hash object.
################################################################### browse(continuation, client_config?) browse(browse_id, params, client_config?)
Requests the youtubei/v1/browse endpoint with the required headers and POST data in order to get a JSON reply in english that can be easily parsed.
Both forms can take an optional ClientConfig parameter (see
struct ClientConfig
above for more details).
The requested data can either be:
-
A continuation token (ctoken). Depending on this token's contents, the returned data can be playlist videos, channel community tab content, channel info, ...
-
A playlist ID (parameters MUST be an empty string)
################################################################### browse(continuation, client_config?) browse(browse_id, params, client_config?)
Requests the youtubei/v1/browse endpoint with the required headers and POST data in order to get a JSON reply in english that can be easily parsed.
Both forms can take an optional ClientConfig parameter (see
struct ClientConfig
above for more details).
The requested data can either be:
-
A continuation token (ctoken). Depending on this token's contents, the returned data can be playlist videos, channel community tab content, channel info, ...
-
A playlist ID (parameters MUST be an empty string)
################################################################### next(continuation, client_config?) next(data, client_config?)
Requests the youtubei/v1/next endpoint with the required headers and POST data in order to get a JSON reply in english that can be easily parsed.
Both forms can take an optional ClientConfig parameter (see
struct ClientConfig
above for more details).
The requested data can be:
-
A continuation token (ctoken). Depending on this token's contents, the returned data can be videos comments, their replies, ... In this case, the string must be passed directly to the function. E.g:
YoutubeAPI::next("ABCDEFGH_abcdefgh==")
-
Arbitrary parameters, in Hash form. See examples below for known examples of arbitrary data that can be passed to YouTube:
# Get the videos related to a specific video ID YoutubeAPI::next({"videoId" => "dQw4w9WgXcQ"}) # Get a playlist video's details YoutubeAPI::next({ "videoId" => "9bZkp7q19f0", "playlistId" => "PL_oFlvgqkrjUVQwiiE3F3k3voF4tjXeP0", })
################################################################### next(continuation, client_config?) next(data, client_config?)
Requests the youtubei/v1/next endpoint with the required headers and POST data in order to get a JSON reply in english that can be easily parsed.
Both forms can take an optional ClientConfig parameter (see
struct ClientConfig
above for more details).
The requested data can be:
-
A continuation token (ctoken). Depending on this token's contents, the returned data can be videos comments, their replies, ... In this case, the string must be passed directly to the function. E.g:
YoutubeAPI::next("ABCDEFGH_abcdefgh==")
-
Arbitrary parameters, in Hash form. See examples below for known examples of arbitrary data that can be passed to YouTube:
# Get the videos related to a specific video ID YoutubeAPI::next({"videoId" => "dQw4w9WgXcQ"}) # Get a playlist video's details YoutubeAPI::next({ "videoId" => "9bZkp7q19f0", "playlistId" => "PL_oFlvgqkrjUVQwiiE3F3k3voF4tjXeP0", })
Allow a NamedTuple to be passed, too.
################################################################### 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).
################################################################### resolve_url(url, client_config?)
Requests the youtubei/v1/navigation/resolve_url endpoint with the required headers and POST data in order to get a JSON reply.
An optional ClientConfig parameter can be passed, too (see
struct ClientConfig
above for more details).
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")
################################################################### search(search_query, params, client_config?)
Requests the youtubei/v1/search endpoint with the required headers and POST data in order to get a JSON reply. As the search results vary depending on the region, a region code can be specified in order to get non-US results.
The requested data is a search string, with some additional paramters, formatted as a base64 string.
An optional ClientConfig parameter can be passed, too (see
struct ClientConfig
above for more details).