-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
25 changed files
with
1,114 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# YouTube Kids | ||
|
||
YouTube Kids is a modified version of the YouTube app, with a simplified interface and curated content. This class allows you to interact with its API. | ||
|
||
## API | ||
|
||
* Kids | ||
* [.search(query)](#search) | ||
* [.getInfo(video_id)](#getinfo) | ||
* [.getHomeFeed()](#gethomefeed) | ||
|
||
<a name="search"></a> | ||
### search(query) | ||
|
||
Searches the given query on YouTube Kids. | ||
|
||
**Returns:** `Promise.<Search>` | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| query | `string` | The query to search | | ||
|
||
|
||
<details> | ||
<summary>Methods & Getters</summary> | ||
<p> | ||
|
||
- `<search>#page` | ||
- Returns the original InnerTube response(s), parsed and sanitized. | ||
|
||
</p> | ||
</details> | ||
|
||
<a name="getinfo"></a> | ||
### getInfo(video_id) | ||
|
||
Retrieves video info. | ||
|
||
**Returns:** `Promise.<VideoInfo>` | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| video_id | `string` | The video id | | ||
|
||
<details> | ||
<summary>Methods & Getters</summary> | ||
<p> | ||
|
||
- `<info>#toDash(url_transformer?)` | ||
- Generates a DASH manifest from the streaming data. | ||
|
||
- `<info>#chooseFormat(options)` | ||
- Selects the format that best matches the given options. This method is used internally by `#download`. | ||
|
||
- `<info>#download(options?)` | ||
- Downloads the video. | ||
|
||
- `<info>#addToWatchHistory()` | ||
- Adds the video to the watch history. | ||
|
||
- `<info>#page` | ||
- Returns the original InnerTube response(s), parsed and sanitized. | ||
|
||
</p> | ||
</details> | ||
|
||
<a name="gethomefeed"></a> | ||
### getHomeFeed() | ||
|
||
Retrieves the home feed. | ||
|
||
**Returns:** `Promise.<HomeFeed>` | ||
|
||
<details> | ||
<summary>Methods & Getters</summary> | ||
<p> | ||
|
||
- `<feed>#selectCategoryTab(tab: string | KidsCategoryTab)` | ||
- Selects the given category tab. | ||
|
||
- `<feed>#categories` | ||
- Returns available categories. | ||
|
||
- `<feed>#page` | ||
- Returns the original InnerTube response(s), parsed and sanitized. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Search from '../parser/ytkids/Search'; | ||
import HomeFeed from '../parser/ytkids/HomeFeed'; | ||
import VideoInfo from '../parser/ytkids/VideoInfo'; | ||
import type Session from './Session'; | ||
import { generateRandomString } from '../utils/Utils'; | ||
|
||
class Kids { | ||
#session: Session; | ||
|
||
constructor(session: Session) { | ||
this.#session = session; | ||
} | ||
|
||
/** | ||
* Searches the given query. | ||
* @param query - The query. | ||
*/ | ||
async search(query: string): Promise<Search> { | ||
const response = await this.#session.actions.execute('/search', { query, client: 'YTKIDS' }); | ||
return new Search(this.#session.actions, response.data); | ||
} | ||
|
||
/** | ||
* Retrieves video info. | ||
* @param video_id - The video id. | ||
*/ | ||
async getInfo(video_id: string): Promise<VideoInfo> { | ||
const cpn = generateRandomString(16); | ||
|
||
const initial_info = this.#session.actions.execute('/player', { | ||
cpn, | ||
client: 'YTKIDS', | ||
videoId: video_id, | ||
playbackContext: { | ||
contentPlaybackContext: { | ||
signatureTimestamp: this.#session.player?.sts || 0 | ||
} | ||
} | ||
}); | ||
|
||
const continuation = this.#session.actions.execute('/next', { videoId: video_id, client: 'YTKIDS' }); | ||
|
||
const response = await Promise.all([ initial_info, continuation ]); | ||
|
||
return new VideoInfo(response, this.#session.actions, cpn); | ||
} | ||
|
||
/** | ||
* Retrieves the home feed. | ||
*/ | ||
async getHomeFeed(): Promise<HomeFeed> { | ||
const response = await this.#session.actions.execute('/browse', { browseId: 'FEkids_home', client: 'YTKIDS' }); | ||
return new HomeFeed(this.#session.actions, response.data); | ||
} | ||
} | ||
|
||
export default Kids; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.