mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-18 12:02:11 +00:00
feat: add support for YouTube Kids (#291)
* dev: add `WEB_KIDS` innertube client * refactor: move DASH manifest stuff out of `VideoInfo` This makes it easier to use these functions elsewhere. * feat(ytkids): add `Kids#getInfo()` & `Kids#search()` * feat: add `Innertube#kids.getHomeFeed()` * docs: add YouTube Kids API ref * docs: fix typo * docs: fix yet another typo * docs: update YouTube Music API ref Unrelated but required to reflect changes made to the DASH manifest generation functions * chore: lint * chore: add tests * feat: include `captions` in `VideoInfo` * chore: fix tests
This commit is contained in:
@@ -40,8 +40,8 @@ export default class HTTPClient {
|
||||
|
||||
const headers =
|
||||
init?.headers ||
|
||||
(input instanceof Request ? input.headers : new Headers()) ||
|
||||
new Headers();
|
||||
(input instanceof Request ? input.headers : new Headers()) ||
|
||||
new Headers();
|
||||
|
||||
const body = init?.body || (input instanceof Request ? input.body : undefined);
|
||||
|
||||
@@ -65,6 +65,7 @@ export default class HTTPClient {
|
||||
const content_type = request_headers.get('Content-Type');
|
||||
|
||||
let request_body = body;
|
||||
let is_web_kids = false;
|
||||
|
||||
const is_innertube_req =
|
||||
baseURL === innertube_url ||
|
||||
@@ -85,11 +86,12 @@ export default class HTTPClient {
|
||||
|
||||
delete n_body.client;
|
||||
|
||||
is_web_kids = n_body.context.client.clientName === 'WEB_KIDS';
|
||||
request_body = JSON.stringify(n_body);
|
||||
}
|
||||
|
||||
// Authenticate
|
||||
if (this.#session.logged_in && is_innertube_req) {
|
||||
// Authenticate (NOTE: YouTube Kids does not support regular bearer tokens)
|
||||
if (this.#session.logged_in && is_innertube_req && !is_web_kids) {
|
||||
const oauth = this.#session.oauth;
|
||||
|
||||
if (oauth.validateCredentials()) {
|
||||
@@ -157,6 +159,40 @@ export default class HTTPClient {
|
||||
ctx.client.clientScreen = 'EMBED';
|
||||
ctx.thirdParty = { embedUrl: Constants.URLS.YT_BASE };
|
||||
break;
|
||||
case 'YTKIDS':
|
||||
ctx.client.clientVersion = Constants.CLIENTS.WEB_KIDS.VERSION;
|
||||
ctx.client.clientName = Constants.CLIENTS.WEB_KIDS.NAME;
|
||||
ctx.client.kidsAppInfo = { // TODO: Make this customizable
|
||||
categorySettings: {
|
||||
enabledCategories: [
|
||||
'approved_for_you',
|
||||
'black_joy',
|
||||
'camp',
|
||||
'collections',
|
||||
'earth',
|
||||
'explore',
|
||||
'favorites',
|
||||
'gaming',
|
||||
'halloween',
|
||||
'hero',
|
||||
'learning',
|
||||
'move',
|
||||
'music',
|
||||
'reading',
|
||||
'shared_by_parents',
|
||||
'shows',
|
||||
'soccer',
|
||||
'sports',
|
||||
'spotlight',
|
||||
'winter'
|
||||
]
|
||||
},
|
||||
contentSettings: {
|
||||
corpusPreference: 'KIDS_CORPUS_PREFERENCE_YOUNGER',
|
||||
kidsNoSearchMode: 'YT_KIDS_NO_SEARCH_MODE_OFF'
|
||||
}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user