Compare commits

..

112 Commits

Author SHA1 Message Date
github-actions[bot]
83cbfd631b chore(main): release 5.2.0 (#406)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-06-28 17:13:36 -03:00
RikThePixel
4f9427d752 fix(Playlist): Add thumbnail_renderer on Playlist when response includes it (#424) 2023-06-28 17:12:06 -03:00
Patrick Kan
07c1b3e0e5 fix(OAuth): client identity matching (#421) 2023-06-28 16:26:33 -03:00
absidue
89548ad48a chore(constants): Update web client version (#420) 2023-06-28 06:56:57 -03:00
absidue
519be72445 fix(PlayerEndpoint): Use different player params (#419)
* fix(PlayerEndpoint): Use different player params

* fix(PlayerEndpoint): Use new throttling bypass player params
2023-06-28 06:56:21 -03:00
Emma
e434bb2632 fix(VideoInfo.ts): reimplement get music_tracks (#409)
* fix(VideoInfo.ts): reimplement `get music_tracks`

- Add parser classes to parse needed data
  - Add `CarouselLockup`
  - Add `EngagementPanelSectionList`
  - Add `InfoRow`
  - Add `StructuredDescriptionContent`
  - Add `VideoDescriptionMusicSection`
  - Add `VideoDescriptionHeader`
  - Add `Factoid`
  - Add `ExpandableVideoDescriptionBody`
  - Add `AdsEngagementPanelContent`
- Add `engagement_panels` to raw and parsed next responses
- Add `engagement_panels` parsing code to `parser.ts`

* Check for song inside of video_lockup first before checking info_rows

* Add support for pulling artist ids out of music_tracks

- Add support for WRITERS InfoRow
- Check for video id inside of naviagation endpoint on info_row metadata

* Add `AdsEngagementPanelContent` to ignore list

* Switch `map => parseItem` to `parseArray`

* Use `Text` && `NavigationEndpoint`

* Replace `String` with `Text` in `ExpandableVideoDescriptionBody`
2023-06-28 06:54:55 -03:00
absidue
a11e5962c6 feat(VideoDetails): Add is_post_live_dvr property (#411) 2023-05-31 19:12:19 -03:00
Jake Reid Browning
77b39c79ee feat(ytmusic): Add support for YouTube Music mood filters (#404)
* add filters property to ytmusic HomeFeed

* remove implied type

* add applyFilter to HomeFeed

* add test

* remove section_list var
2023-05-23 15:00:05 -03:00
absidue
7c530d30ee chore(parser): Remove extra Array.from call (#407) 2023-05-20 18:00:15 -03:00
absidue
1e07a184ff perf(Search): Speed up results parsing (#408) 2023-05-20 17:57:48 -03:00
absidue
5de7b24dc5 perf(toDash): Speed up format filtering (#405) 2023-05-18 14:41:21 -03:00
github-actions[bot]
01fd1ee72a chore(main): release 5.1.0 (#403)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-05-14 01:12:16 -03:00
absidue
84b4f1efd1 feat(toDash): Add audio track labels to the manifest when available (#402) 2023-05-14 01:11:02 -03:00
absidue
046103a4d8 feat(ReelItem): Add accessibility label (#401) 2023-05-14 01:09:51 -03:00
github-actions[bot]
beb4733e84 chore(main): release 5.0.4 (#399)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-05-10 15:35:11 -03:00
absidue
66b026bf49 fix(Utils): Circular dependency introduced in 38a83c3c2a (#400) 2023-05-10 15:32:00 -03:00
absidue
26734194ab fix(bundles): Use ESM tslib build for the browser bundles (#397) 2023-05-06 15:54:18 -03:00
absidue
38a83c3c2a fix(Utils): Use instanceof in deepCompare instead of the constructor name (#398) 2023-05-06 15:47:51 -03:00
absidue
b1f19f16ac refactor(constants): Use namespace import internally (#396) 2023-05-06 15:46:20 -03:00
github-actions[bot]
891d889408 chore(main): release 5.0.3 (#395)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-05-03 19:47:01 -03:00
LuanRT
d4adb9eb6b chore(PlayerEndpoint.ts): add back attestationRequest field
This was accidentally removed in a recent PR. It tells InnerTube to omit the botguard program data.
2023-05-03 19:31:59 -03:00
LuanRT
3b0498b68b fix(Video): typo causing node parsing to fail 2023-05-02 03:21:02 -03:00
github-actions[bot]
154a5d2868 chore(main): release 5.0.2 (#394)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-04-30 17:24:14 -03:00
absidue
7c0abfccd7 fix(VideoInfo): Use microformat view_count when videoDetails view_count is NaN (#393) 2023-04-30 17:21:57 -03:00
github-actions[bot]
8f50c668aa chore(main): release 5.0.1 (#392)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-04-30 00:51:44 -03:00
LuanRT
4f7ec07c3f fix(web): slow downloads due to visitor data (#391)
* fix(web): slow downloads due to visitor data

It seems that YouTube will throttle clients if a shared visitor id is used.

* dev: include `params` for `/player` reqs
2023-04-30 00:50:08 -03:00
github-actions[bot]
ab3d5ab16c chore(main): release 5.0.0 (#389)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-04-29 02:14:26 -03:00
LuanRT
dd21f8c75a feat(NavigationEndpoint): parse content prop
This usually has dialog nodes.
2023-04-29 01:54:34 -03:00
LuanRT
3a7e58d2b9 chore(eslint): enforce the use of import type 2023-04-28 22:35:09 -03:00
LuanRT
75ea09dde8 fix(android): workaround streaming URLs returning 403 (#390) 2023-04-28 22:02:45 -03:00
LuanRT
95e0294eab refactor!: overhaul core classes and remove redundant code (#388)
* feat(Player.ts): append `cver` to deciphered URLs

* refactor(Actions.ts): remove redundant `getVideoInfo` function

This is leftover code from previous versions. It had many problems and it is no longer required.

* fix(Kids.ts): remove unneeded `await` keywords

* dev: add more endpoints

* chore: update deps

* refactor: separate endpoints into files

* dev: improve types

* dev: add more endpoints

* refactor: put clients in a separate directory inside `core`

* chore: lint

* refactor: move mixins and managers to separate folders

* chore: fix tests

* dev: add `CreateVideoEndpoint`

* chore: clean up

* chore: lint

* chore: add some comments

* chore: remove unnecessary test

* dev: add `playlist/CreateEndpoint`

* dev: add `playlist/DeleteEndpoint`

* dev: add `browse/EditPlaylistEndpoint`

* fix(parser): add a few checks to avoid parsing errors
2023-04-28 19:01:04 -03:00
LuanRT
22ae6c93ee chore(contributing.md): reword 2023-04-23 06:41:02 -03:00
LuanRT
257bd475a0 refactor: clean up parser and tests (#387)
* tests: improve coverage

* refactor: clean up nodes

* chore: lint

* feat(parser): ignore `BrandVideoShelf`

Seems to be used for ads.

* feat(parser): ignore `BrandVideoSingleton` too
2023-04-23 06:37:33 -03:00
github-actions[bot]
f66f0bd656 chore(main): release 4.3.0 (#384)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-04-13 07:52:42 -03:00
LuanRT
05de3ec97a feat(GridVideo): add upcoming, upcoming_text, is_reminder_set and buttons
Closes: #380
2023-04-13 07:50:18 -03:00
LuanRT
a0566969ba feat(ToggleMenuServiceItem): parse default nav endpoint 2023-04-13 06:10:17 -03:00
LuanRT
a9cad49333 feat(ytmusic): add taste builder nodes (#383)
Adds MusicTastebuilderShelf and MusicTastebuilderShelfThumbnail. These usually appear on new accounts.
2023-04-13 05:37:49 -03:00
LuanRT
096bf362c9 feat(MusicResponsiveListItem): make flex/fixed cols public (#382)
Plus refactor a few things.
2023-04-13 05:35:46 -03:00
LuanRT
ec9c0979f5 refactor: fix inconsistencies in the guide nodes (#379) 2023-04-11 05:52:47 -03:00
LuanRT
342d1d95e9 chore: fix readme formatting [skip ci] 2023-04-11 05:06:03 -03:00
github-actions[bot]
dbfc569602 chore(main): release 4.2.0 (#377)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-04-09 03:40:01 -03:00
LuanRT
c16a967987 chore(docs): minor improvements 2023-04-09 03:38:09 -03:00
LuanRT
a07375eb20 chore(docs): rewording [skip ci] 2023-04-09 03:02:23 -03:00
LuanRT
ce9d9c56b4 feat(parser): ignore PrimetimePromo node
This node is used to display advertisements.
2023-04-09 02:51:29 -03:00
LuanRT
f50ce1a06b chore: simplify Pull Request template 2023-04-09 02:43:19 -03:00
LuanRT
3b6ccfa3d8 chore: fix cjs build 2023-04-09 02:18:53 -03:00
LuanRT
878488d1b3 chore: clean up README.md 2023-04-09 01:20:27 -03:00
LuanRT
3c94c9da4b deps: bump Jinter to v1.0.0 2023-04-08 23:53:59 -03:00
absidue
0b301de6a1 feat: Enable importHelpers in tsconfig to reduce output size (#378) 2023-04-08 20:19:20 -03:00
absidue
c9135e66d3 feat(PlaylistVideo): Extract video_info and accessibility_label texts (#376) 2023-04-07 20:43:20 -03:00
github-actions[bot]
e82c843928 chore(main): release 4.1.1 (#374)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-28 22:29:08 -03:00
LuanRT
be71d7c937 chore: fix some inconsistencies 2023-03-28 21:22:12 -03:00
LuanRT
470d8d9406 fix(PlayerCaptionsTracklist): parse props only if they exist in the node
Fixes #372
2023-03-28 20:50:50 -03:00
absidue
2c5907f80f fix(Search): Return search results even if there are ads (#373) 2023-03-27 15:00:57 -03:00
github-actions[bot]
ade5feb31c chore(main): release 4.1.0 (#362)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-24 01:34:29 -03:00
LuanRT
13ebf0a039 feat(Session): allow setting a custom visitor data token (#371)
* feat(Session): allow setting a custom visitor data token

* docs: update init options

* chore: lint
2023-03-24 01:30:24 -03:00
Araxeus
cb8fafe94b fix(http): android tv http client missing clientName (#370) 2023-03-22 19:45:37 -03:00
absidue
bd35faa597 fix(parser): Make Video.is_live work on channel pages (#368) 2023-03-22 18:02:21 -03:00
absidue
a8b507ee65 fix(toDash): Generate unique Representation ids (#366) 2023-03-22 17:48:09 -03:00
Araxeus
e7eacd9742 fix(node) Electron apps crashing (#367)
Inside a `app.asar` file, the package.json might get trimmed and the `bugs_url` might be missing

`repo_url` conditional check was added for good measure

* fix(node) resolve `bugs_url` from repo_url
2023-03-22 17:13:40 -03:00
absidue
1c72a41675 fix(Utils): Properly parse timestamps with thousands separators (#363) 2023-03-22 03:48:01 -03:00
LuanRT
62a68b207c chore(docs): fix typo 2023-03-17 18:19:10 -03:00
LuanRT
1d9587e8c1 feat(ShowingResultsFor): parse all props 2023-03-17 07:27:00 -03:00
github-actions[bot]
a90e5e0d07 chore(main): release 4.0.1 (#360)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-16 04:55:10 -03:00
LuanRT
955c8010a6 chore: lint 2023-03-16 04:53:48 -03:00
LuanRT
b2269deb79 chore: add Button type
Oops :D
2023-03-16 04:52:07 -03:00
LuanRT
573c8643aa fix(Channel): type mismatch in subscribe_button prop
The `subscribe_button` property can also be of type `Button`.
2023-03-16 04:48:59 -03:00
github-actions[bot]
e21542c227 chore(main): release 4.0.0 (#353)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-15 21:08:37 -03:00
LuanRT
9d912e5938 refactor: use getters instead of props in the Innertube class 2023-03-15 20:34:58 -03:00
LuanRT
7ca0607004 refactor(ytmusic): rename SearchFilters interface to MusicSearchFilters
This allows us to expose the types from the InnerTube class as there is another interface there named `SearchFilters`
2023-03-15 19:24:17 -03:00
LuanRT
20d84265b5 chore(docs): minor improvements 2023-03-15 18:50:34 -03:00
Daniel Wykerd
b13bf6e992 refactor(Parser)!: general refactoring of parsers (#344)
* refactor: move common info into MediaInfo

* refactor: better inference on Memo

* refactor: improved typesafety in parser methods

* refactor: remove PlaylistAuthor in favor of Author

* refactor: cleanup live chat parsers

- Replace non standard author type with Author class
- Remove redundant code

* fix: new errors due to changes

* fix: pass actions to FormatUtils#toDash

* refactor!: merge NavigatableText and Text into single class
2023-03-15 18:25:12 -03:00
LuanRT
3d3436472f refactor(parser): fix many minor inconsistencies 2023-03-15 06:43:04 -03:00
LuanRT
1a2fc3abd7 chore(docs): add documentation for search filters 2023-03-15 05:35:00 -03:00
LuanRT
8ef4b42d44 feat(parser): add GridShow and ShowCustomThumbnail
Closes #459
2023-03-15 05:15:16 -03:00
LuanRT
b71f03caf2 chore(docs): oops, fix a typo 2023-03-15 04:15:35 -03:00
LuanRT
dae7d6e40c chore: update parser docs to reflect latest changes 2023-03-15 04:12:21 -03:00
Daniel Wykerd
2cee59024c feat(Parser): just-in-time YTNode generation (#310)
* refactor: merge NavigatableText into Text

* fix(Text): data might not be object

* refactor: remove GetParserByName from map

* feat(Parser): just-in-time YTNode generation

* refactor: cleanup YTNodeGenerator

* fix: YTNode map imports

* feat(YTNodeGenerator): primative types

Add support for inferring primatives types

* fix(YTNodeGenerator): NavigationEndpoint detection

* fix(YTNodeGenerator): fix generated typescript

Correct types and linting for generated typescript class

* chore: update parsers after merge

* feat: add support for object type inference

* fix: object type def

* docs: basic YTNodeGenerator explanation

* docs: tsdoc for YTNodeGenerator

* docs: update parser updating guide

* fix: apply suggested changes

* docs: accessing generated nodes
2023-03-15 03:39:36 -03:00
absidue
ffd7d79308 refactor(shim): Move node CustomEvent polyfill to Platform.shim (#357) 2023-03-15 00:49:33 -03:00
LuanRT
9b005d62d6 feat(parser): add MusicCardShelf (#358) 2023-03-14 20:16:31 -03:00
Patrick Kan
a8e7e644ec feat(parser): add GridMix (#356) 2023-03-14 06:19:22 -03:00
LuanRT
ad1d3dbf91 chore(docs): overhaul parser documentation
[skip ci]
2023-03-14 05:57:37 -03:00
LuanRT
3df3261488 chore(docs): improve contributing guidelines 2023-03-14 05:56:01 -03:00
LuanRT
1b1ce41c00 chore: overhaul documentation
Fix typos, add missing docs, rephrase some things and add a `COLLABORATORS.md`

[skip ci]
2023-03-13 07:08:26 -03:00
LuanRT
b82b720e4b docs: update browser example [skip ci] 2023-03-13 01:40:25 -03:00
LuanRT
4784dfa563 feat(parser): add InfoPanelContent and InfoPanelContainer nodes
These are usually used to add more context to videos that discuss misinformation.

Fixes: #326
2023-03-13 01:04:03 -03:00
absidue
3e4d41bf06 feat!: Add support for OTF format streams (#351) 2023-03-12 23:48:58 -03:00
Patrick Kan
9f1c31d7a0 feat(yt): add support for movie items and trailers (#349) 2023-03-12 18:15:21 -03:00
Patrick Kan
9cb4530299 feat(parser): add view_playlist to Playlist (#348) 2023-03-12 18:10:48 -03:00
Patrick Kan
cb9a0c5410 Add status to SearchFilter and fix endpoint (#347)
* feat(parser): add `status` to `SearchFilter`

* fix(parser): `SearchFilter` endpoint parsing
2023-03-12 18:07:59 -03:00
Patrick Kan
427db5bbc2 feat(parser): Add play_all_button to Shelf (#345) 2023-03-12 18:04:35 -03:00
github-actions[bot]
2b29244b41 chore(main): release 3.3.0 (#343)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-09 01:24:26 -03:00
LuanRT
f9754f5ac6 fix(ytmusic): use static visitor id to avoid empty API responses
Fixes #279
2023-03-09 01:21:13 -03:00
LuanRT
b2253df802 feat(parser): add ConversationBar node 2023-03-08 18:09:21 -03:00
LuanRT
f3517708ff fix(MultiMarkersPlayerBar): avoid observing undefined objects 2023-03-08 17:43:20 -03:00
Patrick Kan
0d35fe0ca5 feat(VideoInfo): support get by endpoint + more info (#342)
* feat(VideoInfo): get by endpoint + more info

* chore: fix param description for `getInfo()`
2023-03-08 16:42:41 -03:00
LuanRT
3e3dc351bb fix(SharedPost): import Menu node directly (oops) 2023-03-08 11:29:39 -03:00
github-actions[bot]
197bb759cd chore(main): release 3.2.0 (#334)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-08 07:20:21 -03:00
LuanRT
c76b24b3f4 chore(parser): import YTNodes directly to reduce web bundle size 2023-03-08 07:18:01 -03:00
absidue
574b67a1f7 feat: Add support for descriptive audio tracks (#338) 2023-03-08 05:36:01 -03:00
LuanRT
9b2738f128 fix(SegmentedLikeDislikeButton): like/dislike buttons can also be a simple Button 2023-03-07 05:43:32 -03:00
LuanRT
95f1d4077f fix(YouTube): fix warnings when retrieving members-only content (#341) 2023-03-07 05:15:46 -03:00
LuanRT
a511608f18 feat(YouTube/Search): add SearchSubMenu node (#340) 2023-03-07 04:17:58 -03:00
LuanRT
cf8a33c79f fix(ytmusic): export search filters type 2023-03-07 03:02:44 -03:00
Chinmay Kumar
cfc1a183e0 refactor(parser): type YTNodes' data arg as RawNode (wip) (#339)
* replaced YTNode's data arg as RawNode

* updated documentation

* removed unused import

---- Note that there are still many nodes that need to be updated, hence the WIP status.
2023-03-07 02:02:07 -03:00
Patrick Kan
95033e723e feat(parser): add banner to PlaylistHeader (#337) 2023-03-05 22:44:09 -03:00
Patrick Kan
2cc7b8bcd6 feat(yt): add getGuide() (#335)
* feat(yt): add `getGuide()`

* chore: lint

* fix(Guide): wrong prop

* fix(Guide): include subscription section

* fix(Guide): wrong import

* feat(Guide): add `page`
2023-03-04 06:23:17 -03:00
LuanRT
2d774e26aa feat: export FormatUtils' types 2023-03-04 04:06:19 -03:00
Nico K
214aa147ce feat(VideoInfo): add game_info and category (#333) 2023-03-03 03:47:20 -03:00
Daniel Wykerd
ce53ac1843 feat(parser): SharedPost (#332)
Add support for SharedPost in community tab.
Related to issue #331
2023-03-03 03:41:04 -03:00
github-actions[bot]
0ad26f28d9 chore(main): release 3.1.1 (#330)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-01 16:30:10 -03:00
ChunkyProgrammer
4c7b8a3403 fix(Channel): getting community continuations (#329) 2023-03-01 16:28:26 -03:00
493 changed files with 8440 additions and 6349 deletions

View File

@@ -8,6 +8,8 @@ extends: [ eslint:recommended, 'plugin:@typescript-eslint/recommended' ]
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: latest
project:
- tsconfig.json
overrides:
-
files:
@@ -30,6 +32,8 @@ rules:
'@typescript-eslint/ban-types': 'off'
'tsdoc/syntax': 'warn'
'@typescript-eslint/no-explicit-any': 'off'
'@typescript-eslint/consistent-type-imports': 'error'
'@typescript-eslint/consistent-type-exports': 'error'
no-template-curly-in-string: error
no-unreachable-loop: error

View File

@@ -1,27 +1,6 @@
# Pull Request Template
## Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
## Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] I have checked my code and corrected any misspellings
<!-- Thank you for submitting a Pull Request! Please:
* Read our contributing guidelines: https://github.com/LuanRT/YouTube.js/blob/main/CONTRIBUTING.md
* Add "Fixes #<issue_number>" to the PR description if you are fixing an issue.
* Ensure that the code is up-to-date with the `main` branch.
* Include a description of the proposed changes and how to test them.
-->

View File

@@ -1,5 +1,204 @@
# Changelog
## [5.2.0](https://github.com/LuanRT/YouTube.js/compare/v5.1.0...v5.2.0) (2023-06-28)
### Features
* **VideoDetails:** Add is_post_live_dvr property ([#411](https://github.com/LuanRT/YouTube.js/issues/411)) ([a11e596](https://github.com/LuanRT/YouTube.js/commit/a11e5962c6eb73b14623a9de1e6c8c2534146b1e))
* **ytmusic:** Add support for YouTube Music mood filters ([#404](https://github.com/LuanRT/YouTube.js/issues/404)) ([77b39c7](https://github.com/LuanRT/YouTube.js/commit/77b39c79ee0768eb203b7d47ea81286d470c21f2))
### Bug Fixes
* **OAuth:** client identity matching ([#421](https://github.com/LuanRT/YouTube.js/issues/421)) ([07c1b3e](https://github.com/LuanRT/YouTube.js/commit/07c1b3e0e57cb1fa42e4772775bfd1437bbc731f))
* **PlayerEndpoint:** Use different player params ([#419](https://github.com/LuanRT/YouTube.js/issues/419)) ([519be72](https://github.com/LuanRT/YouTube.js/commit/519be72445b7ff392b396e16bcb1dc05c7df8976))
* **Playlist:** Add thumbnail_renderer on Playlist when response includes it ([#424](https://github.com/LuanRT/YouTube.js/issues/424)) ([4f9427d](https://github.com/LuanRT/YouTube.js/commit/4f9427d752e89faec8dd1c4fd7a9607dca998c7a))
* **VideoInfo.ts:** reimplement `get music_tracks` ([#409](https://github.com/LuanRT/YouTube.js/issues/409)) ([e434bb2](https://github.com/LuanRT/YouTube.js/commit/e434bb2632fe2b20aab6f1e707a93ca76f9d5c91))
### Performance Improvements
* **Search:** Speed up results parsing ([#408](https://github.com/LuanRT/YouTube.js/issues/408)) ([1e07a18](https://github.com/LuanRT/YouTube.js/commit/1e07a184ffaff508ad5ba869cb5e7dc9f095f744))
* **toDash:** Speed up format filtering ([#405](https://github.com/LuanRT/YouTube.js/issues/405)) ([5de7b24](https://github.com/LuanRT/YouTube.js/commit/5de7b24dc55fca3eb8fccc6fa30d3c2cd60b8184))
## [5.1.0](https://github.com/LuanRT/YouTube.js/compare/v5.0.4...v5.1.0) (2023-05-14)
### Features
* **ReelItem:** Add accessibility label ([#401](https://github.com/LuanRT/YouTube.js/issues/401)) ([046103a](https://github.com/LuanRT/YouTube.js/commit/046103a4d8af09fafefab6e9f971184eeca75c2e))
* **toDash:** Add audio track labels to the manifest when available ([#402](https://github.com/LuanRT/YouTube.js/issues/402)) ([84b4f1e](https://github.com/LuanRT/YouTube.js/commit/84b4f1efd111321e4f3e5a87844790c4ec9b0b52))
## [5.0.4](https://github.com/LuanRT/YouTube.js/compare/v5.0.3...v5.0.4) (2023-05-10)
### Bug Fixes
* **bundles:** Use ESM tslib build for the browser bundles ([#397](https://github.com/LuanRT/YouTube.js/issues/397)) ([2673419](https://github.com/LuanRT/YouTube.js/commit/26734194ab0bc5a9f57e1c509d7646ce8903d0c6))
* **Utils:** Circular dependency introduced in 38a83c3c2aa814150d1d9b8ed99fca915c1d67fe ([#400](https://github.com/LuanRT/YouTube.js/issues/400)) ([66b026b](https://github.com/LuanRT/YouTube.js/commit/66b026bf493d71a39e12825938fe54dc63aefd16))
* **Utils:** Use instanceof in deepCompare instead of the constructor name ([#398](https://github.com/LuanRT/YouTube.js/issues/398)) ([38a83c3](https://github.com/LuanRT/YouTube.js/commit/38a83c3c2aa814150d1d9b8ed99fca915c1d67fe))
## [5.0.3](https://github.com/LuanRT/YouTube.js/compare/v5.0.2...v5.0.3) (2023-05-03)
### Bug Fixes
* **Video:** typo causing node parsing to fail ([3b0498b](https://github.com/LuanRT/YouTube.js/commit/3b0498b68b5378e63283e792bd45571c0b919e0b))
## [5.0.2](https://github.com/LuanRT/YouTube.js/compare/v5.0.1...v5.0.2) (2023-04-30)
### Bug Fixes
* **VideoInfo:** Use microformat view_count when videoDetails view_count is NaN ([#393](https://github.com/LuanRT/YouTube.js/issues/393)) ([7c0abfc](https://github.com/LuanRT/YouTube.js/commit/7c0abfccd78a6c291d898f898d73a4f16170e2a9))
## [5.0.1](https://github.com/LuanRT/YouTube.js/compare/v5.0.0...v5.0.1) (2023-04-30)
### Bug Fixes
* **web:** slow downloads due to visitor data ([#391](https://github.com/LuanRT/YouTube.js/issues/391)) ([4f7ec07](https://github.com/LuanRT/YouTube.js/commit/4f7ec07c3f689219b07e8291877c23b6fbf45fb1))
## [5.0.0](https://github.com/LuanRT/YouTube.js/compare/v4.3.0...v5.0.0) (2023-04-29)
### ⚠ BREAKING CHANGES
* overhaul core classes and remove redundant code ([#388](https://github.com/LuanRT/YouTube.js/issues/388))
### Features
* **NavigationEndpoint:** parse `content` prop ([dd21f8c](https://github.com/LuanRT/YouTube.js/commit/dd21f8c75ae1d76180faab4f0ef9ee40920966e3))
### Bug Fixes
* **android:** workaround streaming URLs returning 403 ([#390](https://github.com/LuanRT/YouTube.js/issues/390)) ([75ea09d](https://github.com/LuanRT/YouTube.js/commit/75ea09dde86b1bdf13b197d6e02701899300a371))
### Code Refactoring
* overhaul core classes and remove redundant code ([#388](https://github.com/LuanRT/YouTube.js/issues/388)) ([95e0294](https://github.com/LuanRT/YouTube.js/commit/95e0294eabfdb20bbee2a4bfb751fd101402c5d6))
## [4.3.0](https://github.com/LuanRT/YouTube.js/compare/v4.2.0...v4.3.0) (2023-04-13)
### Features
* **GridVideo:** add `upcoming`, `upcoming_text`, `is_reminder_set` and `buttons` ([05de3ec](https://github.com/LuanRT/YouTube.js/commit/05de3ec97a1fea92543b5e5f84933b86a07ab830)), closes [#380](https://github.com/LuanRT/YouTube.js/issues/380)
* **MusicResponsiveListItem:** make flex/fixed cols public ([#382](https://github.com/LuanRT/YouTube.js/issues/382)) ([096bf36](https://github.com/LuanRT/YouTube.js/commit/096bf362c9bd46a510ecb0d01623c70841e26e26))
* **ToggleMenuServiceItem:** parse default nav endpoint ([a056696](https://github.com/LuanRT/YouTube.js/commit/a0566969ba436f31ca3722d09442a0c6302235d7))
* **ytmusic:** add taste builder nodes ([#383](https://github.com/LuanRT/YouTube.js/issues/383)) ([a9cad49](https://github.com/LuanRT/YouTube.js/commit/a9cad49333aa85c98bbb96e5f2d5b57d9beeb0c7))
## [4.2.0](https://github.com/LuanRT/YouTube.js/compare/v4.1.1...v4.2.0) (2023-04-09)
### Features
* Enable importHelpers in tsconfig to reduce output size ([#378](https://github.com/LuanRT/YouTube.js/issues/378)) ([0b301de](https://github.com/LuanRT/YouTube.js/commit/0b301de6a1e1352a64881c1751a84360922a77cd))
* **parser:** ignore PrimetimePromo node ([ce9d9c5](https://github.com/LuanRT/YouTube.js/commit/ce9d9c56b4f45c0139d74edc95c295ecfd1ee4b1))
* **PlaylistVideo:** Extract video_info and accessibility_label texts ([#376](https://github.com/LuanRT/YouTube.js/issues/376)) ([c9135e6](https://github.com/LuanRT/YouTube.js/commit/c9135e66d3c9c72b8d063eedcf3cc2123800946d))
## [4.1.1](https://github.com/LuanRT/YouTube.js/compare/v4.1.0...v4.1.1) (2023-03-29)
### Bug Fixes
* **PlayerCaptionsTracklist:** parse props only if they exist in the node ([470d8d9](https://github.com/LuanRT/YouTube.js/commit/470d8d94063f0159cd005c9eb15fd1a4a175bea0)), closes [#372](https://github.com/LuanRT/YouTube.js/issues/372)
* **Search:** Return search results even if there are ads ([#373](https://github.com/LuanRT/YouTube.js/issues/373)) ([2c5907f](https://github.com/LuanRT/YouTube.js/commit/2c5907f80fd76452afe87d1722fe35a4f45a22e0))
## [4.1.0](https://github.com/LuanRT/YouTube.js/compare/v4.0.1...v4.1.0) (2023-03-24)
### Features
* **Session:** allow setting a custom visitor data token ([#371](https://github.com/LuanRT/YouTube.js/issues/371)) ([13ebf0a](https://github.com/LuanRT/YouTube.js/commit/13ebf0a03973e7ba7b65e9f72c4333927e4254f6))
* **ShowingResultsFor:** parse all props ([1d9587e](https://github.com/LuanRT/YouTube.js/commit/1d9587e8c1ee0b11bb0e444c3d1e98162e9e1059))
### Bug Fixes
* **http:** android tv http client missing `clientName` ([#370](https://github.com/LuanRT/YouTube.js/issues/370)) ([cb8fafe](https://github.com/LuanRT/YouTube.js/commit/cb8fafe94b8ab330ae58211a892923321d65d890))
* **node:** Electron apps crashing ([#367](https://github.com/LuanRT/YouTube.js/issues/367)) ([e7eacd9](https://github.com/LuanRT/YouTube.js/commit/e7eacd974211c90e7fbddfbf8019388cda3dfa5a))
* **parser:** Make Video.is_live work on channel pages ([#368](https://github.com/LuanRT/YouTube.js/issues/368)) ([bd35faa](https://github.com/LuanRT/YouTube.js/commit/bd35faa5978f0b822e98d019523be1303374ddc0))
* **toDash:** Generate unique Representation ids ([#366](https://github.com/LuanRT/YouTube.js/issues/366)) ([a8b507e](https://github.com/LuanRT/YouTube.js/commit/a8b507ee65ccd8edc9aea2aef8a908fa272bb23c))
* **Utils:** Properly parse timestamps with thousands separators ([#363](https://github.com/LuanRT/YouTube.js/issues/363)) ([1c72a41](https://github.com/LuanRT/YouTube.js/commit/1c72a41675e47f711bd61ebb898bca5527406a79))
## [4.0.1](https://github.com/LuanRT/YouTube.js/compare/v4.0.0...v4.0.1) (2023-03-16)
### Bug Fixes
* **Channel:** type mismatch in `subscribe_button` prop ([573c864](https://github.com/LuanRT/YouTube.js/commit/573c8643aae16ec7b6be5b333619a5d8c91ca5c1))
## [4.0.0](https://github.com/LuanRT/YouTube.js/compare/v3.3.0...v4.0.0) (2023-03-15)
### ⚠ BREAKING CHANGES
* **Parser:** general refactoring of parsers ([#344](https://github.com/LuanRT/YouTube.js/issues/344))
* The `toDash` functions are now asynchronous, they now return a `Promise<string>` instead of a `string`, as we need to fetch the first sequence of the OTF format streams while building the manifest.
### Features
* Add support for OTF format streams ([3e4d41b](https://github.com/LuanRT/YouTube.js/commit/3e4d41bf06ba16232979977c705444f2032bcde6))
* **parser:** add `GridMix` ([#356](https://github.com/LuanRT/YouTube.js/issues/356)) ([a8e7e64](https://github.com/LuanRT/YouTube.js/commit/a8e7e644ec6df3b3c98a313f0321da27b4ca456e))
* **parser:** add `GridShow` and `ShowCustomThumbnail` ([8ef4b42](https://github.com/LuanRT/YouTube.js/commit/8ef4b42d444c4fbe5cd65a55c0e0e7aa31738755)), closes [#459](https://github.com/LuanRT/YouTube.js/issues/459)
* **parser:** add `MusicCardShelf` ([#358](https://github.com/LuanRT/YouTube.js/issues/358)) ([9b005d6](https://github.com/LuanRT/YouTube.js/commit/9b005d62d6590a2ddf6848dabfa33fce36e8df9c))
* **parser:** Add `play_all_button` to `Shelf` ([#345](https://github.com/LuanRT/YouTube.js/issues/345)) ([427db5b](https://github.com/LuanRT/YouTube.js/commit/427db5bbc2bf3e8ec60371d504c2ab1cdae6e918))
* **parser:** add `view_playlist` to `Playlist` ([#348](https://github.com/LuanRT/YouTube.js/issues/348)) ([9cb4530](https://github.com/LuanRT/YouTube.js/commit/9cb45302997771d909487b1ecba6f38655abef48))
* **parser:** add InfoPanelContent and InfoPanelContainer nodes ([4784dfa](https://github.com/LuanRT/YouTube.js/commit/4784dfa563a4dbeaee31811824d5aa37a67f5557)), closes [#326](https://github.com/LuanRT/YouTube.js/issues/326)
* **Parser:** just-in-time YTNode generation ([#310](https://github.com/LuanRT/YouTube.js/issues/310)) ([2cee590](https://github.com/LuanRT/YouTube.js/commit/2cee59024c730c34aa06052849ed6fb3f862ef33))
* **yt:** add support for movie items and trailers ([#349](https://github.com/LuanRT/YouTube.js/issues/349)) ([9f1c31d](https://github.com/LuanRT/YouTube.js/commit/9f1c31d7a09532e80a187b14acceff31c22579bf))
### Code Refactoring
* **Parser:** general refactoring of parsers ([#344](https://github.com/LuanRT/YouTube.js/issues/344)) ([b13bf6e](https://github.com/LuanRT/YouTube.js/commit/b13bf6e9926c19a1939e0f4b69cbd53d1af0f7c8))
## [3.3.0](https://github.com/LuanRT/YouTube.js/compare/v3.2.0...v3.3.0) (2023-03-09)
### Features
* **parser:** add `ConversationBar` node ([b2253df](https://github.com/LuanRT/YouTube.js/commit/b2253df8022217dc486155d8cacbf22db04dd9c2))
* **VideoInfo:** support get by endpoint + more info ([#342](https://github.com/LuanRT/YouTube.js/issues/342)) ([0d35fe0](https://github.com/LuanRT/YouTube.js/commit/0d35fe0ca5e87a877b76cbb6cf3c92843eac5a99))
### Bug Fixes
* **MultiMarkersPlayerBar:** avoid observing undefined objects ([f351770](https://github.com/LuanRT/YouTube.js/commit/f3517708ff34093a544c09d6f5f1ec806130d5cc))
* **SharedPost:** import `Menu` node directly (oops) ([3e3dc35](https://github.com/LuanRT/YouTube.js/commit/3e3dc351bb44faec87616d9b922924d14a95f29f))
* **ytmusic:** use static visitor id to avoid empty API responses ([f9754f5](https://github.com/LuanRT/YouTube.js/commit/f9754f5ac61d0f11b025f37f93783f971560268b)), closes [#279](https://github.com/LuanRT/YouTube.js/issues/279)
## [3.2.0](https://github.com/LuanRT/YouTube.js/compare/v3.1.1...v3.2.0) (2023-03-08)
### Features
* Add support for descriptive audio tracks ([#338](https://github.com/LuanRT/YouTube.js/issues/338)) ([574b67a](https://github.com/LuanRT/YouTube.js/commit/574b67a1f707a32378586dd2fe7b2f36f4ab6ddb))
* export `FormatUtils`' types ([2d774e2](https://github.com/LuanRT/YouTube.js/commit/2d774e26aae79f3d1b115e0e85c148ae80985529))
* **parser:** add `banner` to `PlaylistHeader` ([#337](https://github.com/LuanRT/YouTube.js/issues/337)) ([95033e7](https://github.com/LuanRT/YouTube.js/commit/95033e723ef912706e4d176de6b2760f017184e1))
* **parser:** SharedPost ([#332](https://github.com/LuanRT/YouTube.js/issues/332)) ([ce53ac1](https://github.com/LuanRT/YouTube.js/commit/ce53ac18435cbcb20d6d4c4ab52fd156091e7592))
* **VideoInfo:** add `game_info` and `category` ([#333](https://github.com/LuanRT/YouTube.js/issues/333)) ([214aa14](https://github.com/LuanRT/YouTube.js/commit/214aa147ce6306e37a6bf860a7bed5635db4797e))
* **YouTube/Search:** add `SearchSubMenu` node ([#340](https://github.com/LuanRT/YouTube.js/issues/340)) ([a511608](https://github.com/LuanRT/YouTube.js/commit/a511608f18b37b0d9f2c7958ed5128330fabcfa0))
* **yt:** add `getGuide()` ([#335](https://github.com/LuanRT/YouTube.js/issues/335)) ([2cc7b8b](https://github.com/LuanRT/YouTube.js/commit/2cc7b8bcd6938c7fb3af4f854a1d78b86d153873))
### Bug Fixes
* **SegmentedLikeDislikeButton:** like/dislike buttons can also be a simple `Button` ([9b2738f](https://github.com/LuanRT/YouTube.js/commit/9b2738f1285b278c3e83541857651be9a6248288))
* **YouTube:** fix warnings when retrieving members-only content ([#341](https://github.com/LuanRT/YouTube.js/issues/341)) ([95f1d40](https://github.com/LuanRT/YouTube.js/commit/95f1d4077ff3775f36967dca786139a09e2830a2))
* **ytmusic:** export search filters type ([cf8a33c](https://github.com/LuanRT/YouTube.js/commit/cf8a33c79f5432136b865d535fd0ecedc2393382))
## [3.1.1](https://github.com/LuanRT/YouTube.js/compare/v3.1.0...v3.1.1) (2023-03-01)
### Bug Fixes
* **Channel:** getting community continuations ([#329](https://github.com/LuanRT/YouTube.js/issues/329)) ([4c7b8a3](https://github.com/LuanRT/YouTube.js/commit/4c7b8a34030effa26c4ea186d3e9509128aec31c))
## [3.1.0](https://github.com/LuanRT/YouTube.js/compare/v3.0.0...v3.1.0) (2023-02-26)

18
COLLABORATORS.md Normal file
View File

@@ -0,0 +1,18 @@
# Collaborators
This page lists the collaborators who have contributed to the development and success of the project.
## [LuanRT](https://github.com/LuanRT)
[![Github Sponsors](https://img.shields.io/badge/donate-30363D?style=flat-square&logo=GitHub-Sponsors&logoColor=#white)](https://github.com/sponsors/LuanRT)
[![Ko-Fi](https://img.shields.io/badge/Ko--Fi-30363D?style=flat-square&logo=ko-fi)](https://ko-fi.com/luanrt)
Owner and maintainer.
## [Wykerd](https://github.com/wykerd/)
Initial parser implementation, several bug fixes, major refactorings and general maintenance.
## [MasterOfBob777](https://github.com/MasterOfBob777)
Bug fixes and TypeScript support.
## [patrickkfkan](https://github.com/patrickkfkan)
Major refactorings, improved YouTube Music support, and bug fixes.

View File

@@ -1,71 +1,45 @@
# Contributing to YouTube.js
Welcome to YouTube.js! We're thrilled to have you interested in contributing to our project. As a community-driven project, we believe in the power of collaboration and look forward to working with you. To get started, please follow our guidelines:
Thank you for taking the time to contribute!
The following is a set of guidelines for contributing to YouTube.js.
___
- [Contributing to YouTube.js](#contributing-to-youtubejs)
- [Issues](#issues)
- [Create a new issue](#create-a-new-issue)
- [Solve an issue](#solve-an-issue)
- [Make changes](#make-changes)
- [Commit your updates](#commit-your-updates)
- [Pull Request](#pull-request)
- [Test](#test)
- [Lint](#lint)
- [Build](#build)
## Issues
<a id="issue-1"></a>
#### Create a new issue
If you find a problem, search if an issue already exists. If a related issue doesn't exist, you can open a new issue using a relevant issue form.
### Creating a new issue
Before creating a new issue, we recommend searching for similar or related issues to avoid duplication efforts. However, if you can't find one, you're more than welcome to create a new issue using a relevant issue form. Please make sure to describe the issue as clearly and concisely as possible.
<a id="issue-2"></a>
#### Solve an issue
Scan through the existing issues to find one that interests you. You can narrow down the search using labels as filters. If you find an issue to work on, you are welcome to open a PR with a fix. Documentation updates and grammar fixes are also appreciated!
### Solving an issue
If you want to lend a hand by solving an issue, it's always good to browse existing issues to find one that grabs your attention. You can narrow down the search using tags as filters. If you find an issue you'd like to help with, please feel free to open a Pull Request with a fix. We appreciate documentation updates and grammar fixes too!
<a id="changes"></a>
## Make changes
## Making Changes
1. Fork the repository
2. Install or update to **Node.js v16**
3. Create a working branch and start with your changes!
1. Fork the repository on GitHub.
2. Ensure that you have the latest Node.js v16 version installed.
3. Create a working branch and start making your changes and improvements!
<a id="changes-1"></a>
#### Commit your updates
### Committing updates
When you're done with the changes, make sure to commit them. Don't forget to write a clear, descriptive commit message. We recommend following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification.
Commit the changes once you're happy with them.
### Creating a Pull Request
Once you're happy with your updates, create a pull request on GitHub. This is the most efficient way to get your contribution reviewed and eventually merged into our codebase.
<a id="changes-2"></a>
#### Pull Request
- Use the pull request template to fill in the necessary details.
- If you're solving an issue, link the pull request to that issue.
- Enable the checkbox to allow maintainers to edit the branch and update it for merging.
- Changes may be required before we can merge your changes, and we'll let you know what needs to be done.
When you think the code is ready for review a pull request should be created on Github. Owners of the repository will watch out for new PRs and review them in regular intervals.
### Testing, Linting, and Building
We have some automated processes set up for testing, linting, and building. Please run the following commands to test, lint, and build your code before submitting it:
- Fill the template.
- Link the PR to an issue, if you are solving one.
- Enable the checkbox to allow maintainer edits so the branch can be updated for a merge.
- Changes may be requested before a PR can be merged.
- As you update your PR and apply changes, mark each conversation as resolved.
<a id="test"></a>
#### Test
```bash
Testing:
```sh
npm run test
```
<a id="lint"></a>
#### Lint
```bash
Linting:
```sh
npm run lint
npm run lint:fix
```
<a id="build"></a>
#### Build
```bash
Building:
```sh
# Build all
npm run build
@@ -87,5 +61,6 @@ npm run bundle:node
# Browser
npm run bundle:browser
npm run bundle:browser:prod
```
```
We appreciate your efforts and contributions to YouTube.js! Together, we can make this project even better.

266
README.md
View File

@@ -3,14 +3,12 @@
[versions]: https://www.npmjs.com/package/youtubei.js?activeTab=versions
[codefactor]: https://www.codefactor.io/repository/github/luanrt/youtube.js
[actions]: https://github.com/LuanRT/YouTube.js/actions
[say-thanks]: https://saythanks.io/to/LuanRT
[github-sponsors]:https://github.com/sponsors/LuanRT
[collaborators]: https://github.com/LuanRT/YouTube.js/blob/main/COLLABORATORS.md
<!-- OTHER LINKS -->
[project]: https://github.com/LuanRT/YouTube.js
[twitter]: https://twitter.com/thesciencephile
[discord]: https://discord.gg/syDu7Yks54
[nodejs]: https://nodejs.org
<h1 align=center>YouTube.js</h1>
@@ -23,68 +21,59 @@
[![Codefactor](https://www.codefactor.io/repository/github/luanrt/youtube.js/badge)][codefactor]
[![Downloads](https://img.shields.io/npm/dt/youtubei.js)][npm]
[![Discord](https://img.shields.io/badge/discord-online-brightgreen.svg)][discord]
[![Say thanks](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)][say-thanks]
<br>
[![Donate](https://img.shields.io/badge/donate-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#white)][github-sponsors]
[![Donate](https://img.shields.io/badge/donate-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#white)][collaborators]
</div>
<p align="center">
<a><sub>Special thanks to:<sub></a>
</p>
<div align="center">
<p>
<sup>Special thanks to:</sup>
<br>
<br>
<a href="https://serpapi.com" target="_blank">
<img width="80" alt="SerpApi" src="https://luanrt.is-a.dev/assets/img/serpapi.svg" />
<br>
<sub>
API to get search engine results with ease.
</sub>
</a>
</p>
</div>
<br>
<hr>
<br>
<table align="center">
<body>
<tr>
<td align="center">
<a href="https://serpapi.com/" target="_blank">
<img width="80" alt="SerpApi" src="https://luanrt.is-a.dev/assets/img/serpapi.svg" />
<br>
<b>
<sub>
Scrape Google and other search engines from a fast, easy and complete API.
</sub>
</b>
</a>
</td>
</tr>
</body>
</table>
___
<details>
<summary>Table of Contents</summary>
<ol>
<li>
<a href="#about">About</a>
</li>
<li>
## Table of Contents
<ol>
<li>
<a href="#description">Description</a>
</li>
<li>
<a href="#getting-started">Getting Started</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li>
</li>
<li>
<a href="#usage">Usage</a>
<ul>
<li><a href="#browser-usage">Browser Usage</a></li>
<li><a href="#caching">Caching</a></li>
<li><a href="#api">API</a></li>
<li><a href="#browser-usage">Browser Usage</a></li>
<li><a href="#caching">Caching</a></li>
<li><a href="#api">API</a></li>
</ul>
</li>
<li><a href="#extending-the-library">Extending the library</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#disclaimer">Disclaimer</a></li>
<li><a href="#license">License</a></li>
</ol>
</details>
</li>
<li><a href="#extending-the-library">Extending the library</a></li>
<li><a href="#contributing">Contributing</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#disclaimer">Disclaimer</a></li>
<li><a href="#license">License</a></li>
</ol>
## Description
InnerTube is an API used by all YouTube clients. It was created to simplify the deployment of new features and experiments across the platform[^1]. This library handles all the low-level communication with InnerTube, providing a simple, and efficient way to interact with YouTube programmatically. It is designed to emulate an actual client as closely as possible, including how API responses are parsed.
InnerTube is an API used by all YouTube clients. It was created to simplify the deployment of new features and experiments across the platform [^1]. This library manages all low-level communication with InnerTube, providing a simple and efficient way to interact with YouTube programmatically. Its design aims to closely emulate an actual client, including the parsing of API responses.
If you have any questions or need help, feel free to reach out to us on our [Discord server][discord] or open an issue [here](https://github.com/LuanRT/YouTube.js/issues).
@@ -95,7 +84,7 @@ YouTube.js runs on Node.js, Deno, and modern browsers.
It requires a runtime with the following features:
- [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
- On Node we use [undici]()'s fetch implementation which requires Node.js 16.8+. You may provide your fetch implementation if you need to use an older version. See [providing your own fetch implementation](#custom-fetch) for more information.
- On Node, we use [undici](https://github.com/nodejs/undici)'s fetch implementation, which requires Node.js 16.8+. If you need to use an older version, you may provide your own fetch implementation. See [providing your own fetch implementation](#custom-fetch) for more information.
- The `Response` object returned by fetch must thus be spec compliant and return a `ReadableStream` object if you want to use the `VideoInfo#download` method. (Implementations like `node-fetch` returns a non-standard `Readable` object.)
- [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) and [`CustomEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) are required.
@@ -122,16 +111,38 @@ Create an InnerTube instance:
```ts
// const { Innertube } = require('youtubei.js');
import { Innertube } from 'youtubei.js';
const youtube = await Innertube.create();
const youtube = await Innertube.create(/* options */);
```
## Browser Usage
To use YouTube.js in the browser you must proxy requests through your own server. You can see our simple reference implementation in Deno in [`examples/browser/proxy/deno.ts`](https://github.com/LuanRT/YouTube.js/tree/main/examples/browser/proxy/deno.ts).
### Initialization Options
<details>
<summary>Click to expand</summary>
You may provide your own fetch implementation to be used by YouTube.js. Which we will use here to modify and send the requests through our proxy. See [`examples/browser/web`](https://github.com/LuanRT/YouTube.js/tree/main/examples/browser/web) for a simple example using [Vite](https://vitejs.dev/).
| Option | Type | Description | Default |
| --- | --- | --- | --- |
| `lang` | `string` | Language. | `en` |
| `location` | `string` | Geolocation. | `US` |
| `account_index` | `number` | The account index to use. This is useful if you have multiple accounts logged in. **NOTE:** Only works if you are signed in with cookies. | `0` |
| `visitor_data` | `string` | Setting this to a valid and persistent visitor data string will allow YouTube to give this session tailored content even when not logged in. A good way to get a valid one is by either grabbing it from a browser or calling InnerTube's `/visitor_id` endpoint. | `undefined` |
| `retrieve_player` | `boolean` | Specifies whether to retrieve the JS player. Disabling this will make session creation faster. **NOTE:** Deciphering formats is not possible without the JS player. | `true` |
| `enable_safety_mode` | `boolean` | Specifies whether to enable safety mode. This will prevent the session from loading any potentially unsafe content. | `false` |
| `generate_session_locally` | `boolean` | Specifies whether to generate the session data locally or retrieve it from YouTube. This can be useful if you need more performance. | `false` |
| `device_category` | `DeviceCategory` | Platform to use for the session. | `DESKTOP` |
| `client_type` | `ClientType` | InnerTube client type. | `WEB` |
| `timezone` | `string` | The time zone. | `*` |
| `cache` | `ICache` | Used to cache the deciphering functions from the JS player. | `undefined` |
| `cookie` | `string` | YouTube cookies. | `undefined` |
| `fetch` | `FetchFunction` | Fetch function to use. | `fetch` |
</details>
## Browser Usage
To use YouTube.js in the browser, you must proxy requests through your own server. You can see our simple reference implementation in Deno at [`examples/browser/proxy/deno.ts`](https://github.com/LuanRT/YouTube.js/tree/main/examples/browser/proxy/deno.ts).
You may provide your own fetch implementation to be used by YouTube.js, which we will use to modify and send the requests through a proxy. See [`examples/browser/web`](https://github.com/LuanRT/YouTube.js/tree/main/examples/browser/web) for a simple example using [Vite](https://vitejs.dev/).
```ts
// We provide multiple exports for the web.
// Multiple exports are available for the web.
// Unbundled ESM version
import { Innertube } from 'youtubei.js/web';
// Bundled ESM version
@@ -166,7 +177,7 @@ const videoInfo = await youtube.getInfo('videoId');
// now convert to a dash manifest
// again - to be able to stream the video in the browser - we must proxy the requests through our own server
// to do this, we provide a method to transform the URLs before writing them to the manifest
const manifest = videoInfo.toDash(url => {
const manifest = await videoInfo.toDash(url => {
// modify the url
// and return it
return url;
@@ -202,23 +213,25 @@ const yt = await Innertube.create({
<a name="caching"></a>
## Caching
To improve performance, you may wish to cache the transformed player instance which we use to decode the streaming urls.
Caching the transformed player instance can greatly improve the performance. Our `UniversalCache` implementation uses different caching methods depending on the environment.
Our cache uses the `node:fs` module in Node-like environments, `Deno.writeFile` in Deno, and `indexedDB` in browsers.
In Node.js, we use the `node:fs` module, `Deno.writeFile()` in Deno, and `indexedDB` in browsers.
By default, the cache stores data in the operating system's temporary directory (or `indexedDB` in browsers). You can make this cache persistent by specifying the path to the cache directory, which will be created if it doesn't exist.
```ts
import { Innertube, UniversalCache } from 'youtubei.js';
// By default, cache stores files in the OS temp directory (or indexedDB in browsers).
// Create a cache that stores files in the OS temp directory (or indexedDB in browsers) by default.
const yt = await Innertube.create({
cache: new UniversalCache(false)
});
// You may wish to make the cache persistent (on Node and Deno)
// You may want to create a persistent cache instead (on Node and Deno).
const yt = await Innertube.create({
cache: new UniversalCache(
// Enables persistent caching
true,
// Path to the cache directory will create the directory if it doesn't exist
// Path to the cache directory. The directory will be created if it doesn't exist
'./.cache'
)
});
@@ -229,7 +242,7 @@ const yt = await Innertube.create({
* `Innertube`
<details>
<summary>Objects</summary>
<summary>Properties</summary>
<p>
* [.session](https://github.com/LuanRT/YouTube.js/blob/main/docs/API/session.md)
@@ -248,12 +261,13 @@ const yt = await Innertube.create({
<summary>Methods</summary>
<p>
* [.getInfo(video_id, client?)](#getinfo)
* [.getInfo(target, client?)](#getinfo)
* [.getBasicInfo(video_id, client?)](#getbasicinfo)
* [.search(query, filters?)](#search)
* [.getSearchSuggestions(query)](#getsearchsuggestions)
* [.getComments(video_id, sort_by?)](#getcomments)
* [.getHomeFeed()](#gethomefeed)
* [.getGuide()](#getguide)
* [.getLibrary()](#getlibrary)
* [.getHistory()](#gethistory)
* [.getTrending()](#gettrending)
@@ -272,15 +286,15 @@ const yt = await Innertube.create({
</details>
<a name="getinfo"></a>
### getInfo(video_id, client?)
### `getInfo(target, client?)`
Retrieves video info, including playback data and even layout elements such as menus, buttons, etc — all nicely parsed.
Retrieves video info.
**Returns**: `Promise<VideoInfo>`
| Param | Type | Description |
| --- | --- | --- |
| video_id | `string` | The id of the video |
| target | `string` \| `NavigationEndpoint` | If `string`, the id of the video. If `NavigationEndpoint`, the endpoint of watchable elements such as `Video`, `Mix` and `Playlist`. To clarify, valid endpoints have payloads containing at least `videoId` and optionally `playlistId`, `params` and `index`. |
| client? | `InnerTubeClient` | `WEB`, `ANDROID`, `YTMUSIC`, `YTMUSIC_ANDROID` or `TV_EMBEDDED` |
<details>
@@ -299,6 +313,9 @@ Retrieves video info, including playback data and even layout elements such as m
- `<info>#getLiveChat()`
- Returns a LiveChat instance.
- `<info>#getTrailerInfo()`
- Returns trailer info in a new `VideoInfo` instance, or `null` if none. Typically available for non-purchased movies or films.
- `<info>#chooseFormat(options)`
- Used to choose streaming data formats.
@@ -320,6 +337,12 @@ Retrieves video info, including playback data and even layout elements such as m
- `<info>#addToWatchHistory()`
- Adds the video to the watch history.
- `<info>#autoplay_video_endpoint`
- Returns the endpoint of the video for Autoplay.
- `<info>#has_trailer`
- Checks if trailer is available.
- `<info>#page`
- Returns original InnerTube response (sanitized).
@@ -327,7 +350,7 @@ Retrieves video info, including playback data and even layout elements such as m
</details>
<a name="getbasicinfo"></a>
### getBasicInfo(video_id, client?)
### `getBasicInfo(video_id, client?)`
Suitable for cases where you only need basic video metadata. Also, it is faster than [`getInfo()`](#getinfo).
@@ -339,7 +362,7 @@ Suitable for cases where you only need basic video metadata. Also, it is faster
| client? | `InnerTubeClient` | `WEB`, `ANDROID`, `YTMUSIC_ANDROID`, `YTMUSIC`, `TV_EMBEDDED` |
<a name="search"></a>
### search(query, filters?)
### `search(query, filters?)`
Searches the given query on YouTube.
@@ -353,6 +376,20 @@ Searches the given query on YouTube.
| query | `string` | The search query |
| filters? | `SearchFilters` | Search filters |
<details>
<summary>Search Filters</summary>
| Filter | Type | Value | Description |
| --- | --- | --- | --- |
| upload_date | `string` | `all` \| `hour` \| `today` \| `week` \| `month` \| `year` | Filter by upload date |
| type | `string` | `all` \| `video` \| `channel` \| `playlist` \| `movie` | Filter by type |
| duration | `string` | `all` \| `short` \| `medium` \| `long` | Filter by duration |
| sort_by | `string` | `relevance` \| `rating` \| `upload_date` \| `view_count` | Sort by |
| features | `string[]` | `hd` \| `subtitles` \| `creative_commons` \| `3d` \| `live` \| `purchased` \| `4k` \| `360` \| `location` \| `hdr` \| `vr180` | Filter by features |
</details>
<details>
<summary>Methods & Getters</summary>
<p>
@@ -370,7 +407,7 @@ Searches the given query on YouTube.
</details>
<a name="getsearchsuggestions"></a>
### getSearchSuggestions(query)
### `getSearchSuggestions(query)`
Retrieves search suggestions for given query.
**Returns**: `Promise<string[]>`
@@ -380,7 +417,7 @@ Retrieves search suggestions for given query.
| query | `string` | The search query |
<a name="getcomments"></a>
### getComments(video_id, sort_by?)
### `getComments(video_id, sort_by?)`
Retrieves comments for given video.
**Returns**: `Promise<Comments>`
@@ -393,7 +430,7 @@ Retrieves comments for given video.
See [`./examples/comments`](https://github.com/LuanRT/YouTube.js/blob/main/examples/comments) for examples.
<a name="gethomefeed"></a>
### getHomeFeed()
### `getHomeFeed()`
Retrieves YouTube's home feed.
**Returns**: `Promise<HomeFeed>`
@@ -426,8 +463,14 @@ Retrieves YouTube's home feed.
</p>
</details>
<a name="getguide"></a>
### `getGuide()`
Retrieves YouTube's content guide.
**Returns**: `Promise<Guide>`
<a name="getlibrary"></a>
### getLibrary()
### `getLibrary()`
Retrieves the account's library.
**Returns**: `Promise<Library>`
@@ -449,7 +492,7 @@ Retrieves the account's library.
</details>
<a name="gethistory"></a>
### getHistory()
### `getHistory()`
Retrieves watch history.
**Returns**: `Promise<History>`
@@ -468,19 +511,19 @@ Retrieves watch history.
</details>
<a name="gettrending"></a>
### getTrending()
### `getTrending()`
Retrieves trending content.
**Returns**: `Promise<TabbedFeed<IBrowseResponse>>`
<a name="getsubscriptionsfeed"></a>
### getSubscriptionsFeed()
### `getSubscriptionsFeed()`
Retrieves the subscriptions feed.
**Returns**: `Promise<Feed<IBrowseResponse>>`
<a name="getchannel"></a>
### getChannel(id)
### `getChannel(id)`
Retrieves contents for a given channel.
**Returns**: `Promise<Channel>`
@@ -520,7 +563,7 @@ Retrieves contents for a given channel.
See [`./examples/channel`](https://github.com/LuanRT/YouTube.js/blob/main/examples/channel) for examples.
<a name="getnotifications"></a>
### getNotifications()
### `getNotifications()`
Retrieves notifications.
**Returns**: `Promise<NotificationsMenu>`
@@ -536,13 +579,13 @@ Retrieves notifications.
</details>
<a name="getunseennotificationscount"></a>
### getUnseenNotificationsCount()
### `getUnseenNotificationsCount()`
Retrieves unseen notifications count.
**Returns**: `Promise<number>`
<a name="getplaylist"></a>
### getPlaylist(id)
### `getPlaylist(id)`
Retrieves playlist contents.
**Returns**: `Promise<Playlist>`
@@ -565,7 +608,7 @@ Retrieves playlist contents.
</details>
<a name="gethashtag"></a>
### getHashtag(hashtag)
### `getHashtag(hashtag)`
Retrieves a given hashtag's page.
**Returns**: `Promise<HashtagFeed>`
@@ -590,16 +633,22 @@ Retrieves a given hashtag's page.
</details>
<a name="getstreamingdata"></a>
### getStreamingData(video_id, options)
### `getStreamingData(video_id, options)`
Returns deciphered streaming data.
> **Note**
> This will be deprecated in the future. It is recommended to retrieve streaming data from a `VideoInfo`/`TrackInfo` object instead if you want to select formats manually, see the example below.
> This method will be deprecated in the future. We recommend retrieving streaming data from a `VideoInfo` or `TrackInfo` object instead if you want to select formats manually. Please refer to the following example:
```ts
const info = await yt.getBasicInfo('somevideoid');
const url = info.streaming_data?.formats[0].decipher(yt.session.player);
console.info('Playback url:', url);
// or:
const format = info.chooseFormat({ type: 'audio', quality: 'best' });
const url = format?.decipher(yt.session.player);
console.info('Playback url:', url);
```
**Returns**: `Promise<object>`
@@ -610,7 +659,7 @@ console.info('Playback url:', url);
| options | `FormatOptions` | Format options |
<a name="download"></a>
### download(video_id, options?)
### `download(video_id, options?)`
Downloads a given video.
**Returns**: `Promise<ReadableStream<Uint8Array>>`
@@ -623,7 +672,7 @@ Downloads a given video.
See [`./examples/download`](https://github.com/LuanRT/YouTube.js/blob/main/examples/download) for examples.
<a name="resolveurl"></a>
### resolveURL(url)
### `resolveURL(url)`
Resolves a given url.
**Returns**: `Promise<NavigationEndpoint>`
@@ -633,7 +682,7 @@ Resolves a given url.
| url | `string` | Url to resolve |
<a name="call"></a>
### call(endpoint, args?)
### `call(endpoint, args?)`
Utility to call navigation endpoints.
**Returns**: `Promise<T extends IParsedResponse | IParsedResponse | ApiResponse>`
@@ -645,10 +694,9 @@ Utility to call navigation endpoints.
## Extending the library
YouTube.js is completely modular and easy to extend. Almost all methods, classes, and utilities used internally are exposed and can be used to implement your own extensions without having to modify the library's source code.
For example, let's say we want to implement a method to retrieve video info manually. We can do that by using an instance of the `Actions` class:
YouTube.js is modular and easy to extend. Most of the methods, classes, and utilities used internally are exposed and can be used to implement your own extensions without having to modify the library's source code.
For example, let's say we want to implement a method to retrieve video info. We can do that by using an instance of the `Actions` class:
```ts
import { Innertube } from 'youtubei.js';
@@ -657,10 +705,10 @@ import { Innertube } from 'youtubei.js';
async function getVideoInfo(videoId: string) {
const videoInfo = await yt.actions.execute('/player', {
// anything added here will be merged with the default payload and sent to InnerTube.
// You can add any additional payloads here, and they'll merge with the default payload sent to InnerTube.
videoId,
client: 'YTMUSIC', // InnerTube client, can be ANDROID, YTMUSIC, YTMUSIC_ANDROID, WEB or TV_EMBEDDED
parse: true // tells YouTube.js to parse the response, this is not sent to InnerTube.
client: 'YTMUSIC', // InnerTube client options: ANDROID, YTMUSIC, YTMUSIC_ANDROID, WEB, or TV_EMBEDDED.
parse: true // tells YouTube.js to parse the response (not sent to InnerTube).
});
return videoInfo;
@@ -671,8 +719,7 @@ import { Innertube } from 'youtubei.js';
})();
```
Or perhaps there's a `NavigationEndpoint` in a parsed response and we want to call it to see what happens:
Alternatively, suppose we locate a `NavigationEndpoint` in a parsed response and want to see what happens when we call it:
```ts
import { Innertube, YTNodes } from 'youtubei.js';
@@ -682,11 +729,11 @@ import { Innertube, YTNodes } from 'youtubei.js';
const artist = await yt.music.getArtist('UC52ZqHVQz5OoGhvbWiRal6g');
const albums = artist.sections[1].as(YTNodes.MusicCarouselShelf);
// Say we want to click the “More” button:
// Let's imagine that we wish to click on the “More” button:
const button = albums.as(YTNodes.MusicCarouselShelf).header?.more_content;
if (button) {
// After making sure it exists, we can call its navigation endpoint:
// Having ensured that it exists, we can then call its navigation endpoint using the following code:
const page = await button.endpoint.call(yt.actions, { parse: true });
console.info(page);
}
@@ -695,16 +742,16 @@ import { Innertube, YTNodes } from 'youtubei.js';
### Parser
YouTube.js' parser allows you to parse InnerTube responses and turn their nodes into strongly typed objects that can be easily manipulated. It also provides a set of utility methods that make working with InnerTube much easier.
YouTube.js' parser enables you to parse InnerTube responses and convert their nodes into strongly-typed objects that are simple to manipulate. Additionally, it provides numerous utility methods that make working with InnerTube a breeze.
Example:
Here's an example of its usage:
```ts
// See ./examples/parser
import { Parser, YTNodes } from 'youtubei.js';
import { readFileSync } from 'fs';
// Artist page response from YouTube Music
// YouTube Music's artist page response
const data = readFileSync('./artist.json').toString();
const page = Parser.parseResponse(JSON.parse(data));
@@ -713,15 +760,9 @@ const header = page.header?.item().as(YTNodes.MusicImmersiveHeader, YTNodes.Musi
console.info('Header:', header);
/**
* The parser encapsulates all arrays in a proxy object.
* A proxy intercepts access to the actual data, allowing
* the parser to add type safety and many utility methods
* that make working with InnerTube much easier.
*/
// The parser uses a proxy object to add type safety and utility methods for working with InnerTube's data arrays:
const tab = page.contents?.item().as(YTNodes.SingleColumnBrowseResults).tabs.firstOfType(YTNodes.Tab);
if (!tab)
throw new Error('Target tab not found');
@@ -735,12 +776,10 @@ console.info('Sections:', sections);
Documentation for the parser can be found [here](https://github.com/LuanRT/YouTube.js/blob/main/src/parser).
<!-- CONTRIBUTING -->
## Contributing
Contributions, issues, and feature requests are welcome.
Feel free to check the [issues page](https://github.com/LuanRT/YouTube.js/issues) and our [guidelines](https://github.com/LuanRT/YouTube.js/blob/main/CONTRIBUTING.md) if you want to contribute.
We welcome all contributions, issues and feature requests, whether small or large. If you want to contribute, feel free to check out our [issues page](https://github.com/LuanRT/YouTube.js/issues) and our [guidelines](https://github.com/LuanRT/YouTube.js/blob/main/CONTRIBUTING.md).
Thank you to all the wonderful people who have contributed to this project:
We are immensely grateful to all the wonderful people who have contributed to this project. A special shoutout to all our contributors! 🎉
<a href="https://github.com/LuanRT/YouTube.js/graphs/contributors">
<img src="https://contrib.rocks/image?repo=LuanRT/YouTube.js" />
</a>
@@ -752,10 +791,9 @@ LuanRT - [@thesciencephile][twitter] - luan.lrt4@gmail.com
Project Link: [https://github.com/LuanRT/YouTube.js][project]
## Disclaimer
This project is not affiliated with, endorsed, or sponsored by YouTube or any of its affiliates or subsidiaries.
All trademarks, logos, and brand names are the property of their respective owners and are used only to directly describe the services being provided, as such, any usage of trademarks to refer to such services is considered nominative use.
This project is not affiliated with, endorsed, or sponsored by YouTube or any of its affiliates or subsidiaries. All trademarks, logos, and brand names used in this project are the property of their respective owners and are used solely to describe the services provided.
Should you have any questions or concerns please contact me directly via email.
As such, any usage of trademarks to refer to such services is considered nominative use. If you have any questions or concerns, please contact me directly via email.
[^1]: https://gizmodo.com/how-project-innertube-helped-pull-youtube-out-of-the-gu-1704946491

View File

@@ -77,7 +77,16 @@ Searches on YouTube Music.
| Param | Type | Description |
| --- | --- | --- |
| query | `string` | Search query |
| filters? | `object` | Search filters |
| filters? | `MusicSearchFilters` | Search filters |
<details>
<summary>Search Filters</summary>
| Filter | Type | Value | Description |
| --- | --- | --- | --- |
| type | `string` | `all`, `song`, `video`, `album`, `playlist`, `artist` | Search type |
</details>
<details>
<summary>Methods & Getters</summary>

View File

@@ -1,42 +1,47 @@
# Updating the parser
# Updating the Parser
YouTube is constantly changing, so it is not rare to see YouTube crawlers/scrapers breaking every now and then.
YouTube is constantly changing, so it is not uncommon to see YouTube crawlers/scrapers breaking every now and then.
Our parser, on the other hand, was written so that it behaves similarly to an official client, parsing and mapping renderers (also known as YTNodes) dynamically without hard-coding their path in the response. This way, whenever a new renderer pops up (e.g., when YouTube adds a new feature or makes a minor UI change), the library will print a warning similar to this:
Our parser, on the other hand, was written so that it behaves similarly to an official client, parsing and mapping renderers (a.k.a YTNodes) dynamically without hard-coding their path in the response. This way, whenever a new renderer pops up (e.g; YouTube adds a new feature / minor UI changes) the library will print a warning similar to this:
```
InnertubeError: SomeRenderer not found!
SomeRenderer not found!
This is a bug, want to help us fix it? Follow the instructions at https://github.com/LuanRT/YouTube.js/blob/main/docs/updating-the-parser.md or report it at https://github.com/LuanRT/YouTube.js/issues!
at Parser.printError (...)
at Parser.parseItem (...)
at Parser.parseArray (...) {
info: {
// renderer data, can be used as a reference to implement the renderer parser
},
date: 2022-05-22T22:16:06.831Z,
version: '2.2.3'
Introspected and JIT generated this class in the meantime:
class SomeRenderer extends YTNode {
static type = 'SomeRenderer';
// ...
constructor(data: RawNode) {
super();
// ...
}
}
```
This warning **does not** throw an error. The parser itself will continue working normally, even if a parsing error occurs in an existing renderer parser.
## Adding a new renderer parser
## Adding a New Renderer Parser
Thanks to the modularity of the parser, a renderer can be implemented by simply adding a new file anywhere in the [classes directory](../src/parser/classes)!
For example, say we found a new renderer named `verticalListRenderer`, to let the parser know it exists we would have to create a file with the following structure:
For example, suppose we have found a new renderer named `verticalListRenderer`. In that case, to let the parser know it exists at compile-time, we would have to create a file with the following structure:
> `../classes/VerticalList.ts`
```ts
import Parser from '..';
import { YTNode } from '../helpers';
import type { RawNode } from '../index.js';
class VerticalList extends YTNode {
static type = 'VerticalList';
header;
contents;
constructor(data: any) {
constructor(data: RawNode) {
// parse the data here, ex;
this.header = Parser.parseItem(data.header);
this.contents = Parser.parseArray(data.contents);
@@ -46,9 +51,12 @@ class VerticalList extends YTNode {
export default VerticalList;
```
You may use the parser's generated class for the new renderer as a starting point for your own implementation.
Then update the parser map:
```bash
npm run build:parser-map
```
And that's it!
And that's it!

View File

@@ -17,8 +17,9 @@ const { Innertube, UniversalCache } = require('youtubei.js');
});
// 'update-credentials' is fired when the access token expires, if you do not save the updated credentials any subsequent request will fail
yt.session.on('update-credentials', ({ credentials }) => {
yt.session.on('update-credentials', async ({ credentials }) => {
console.log('Credentials updated:', credentials);
await yt.session.oauth.cacheCredentials();
});
// Attempt to sign in

View File

@@ -113,7 +113,7 @@ async function main() {
showUI(true);
const dash = info.toDash((url) => {
const dash = await info.toDash((url) => {
url.searchParams.set('__host', url.host);
url.host = 'localhost:8080';
url.protocol = 'http';

91
package-lock.json generated
View File

@@ -1,19 +1,20 @@
{
"name": "youtubei.js",
"version": "3.1.0",
"version": "5.2.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "youtubei.js",
"version": "3.1.0",
"version": "5.2.0",
"funding": [
"https://github.com/sponsors/LuanRT"
],
"license": "MIT",
"dependencies": {
"jintr": "^0.4.1",
"jintr": "^1.0.0",
"linkedom": "^0.14.12",
"tslib": "^2.5.0",
"undici": "^5.19.1"
},
"devDependencies": {
@@ -30,7 +31,7 @@
"pbkit": "^0.0.59",
"replace": "^1.2.2",
"ts-jest": "^28.0.8",
"typescript": "^4.9.5"
"typescript": "^5.0.0"
}
},
"node_modules/@ampproject/remapping": {
@@ -1574,6 +1575,12 @@
"node": ">=12 <14 || 14.2 - 14.9 || >14.10.0"
}
},
"node_modules/@yarnpkg/fslib/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
},
"node_modules/@yarnpkg/libzip": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@yarnpkg/libzip/-/libzip-2.2.4.tgz",
@@ -1587,6 +1594,12 @@
"node": ">=12 <14 || 14.2 - 14.9 || >14.10.0"
}
},
"node_modules/@yarnpkg/libzip/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
},
"node_modules/acorn": {
"version": "8.8.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",
@@ -4394,9 +4407,9 @@
}
},
"node_modules/jintr": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/jintr/-/jintr-0.4.1.tgz",
"integrity": "sha512-R42VuIoTjsGbZuEmtT7WqyErd9JQuuV17Cg05wQwRWkQbmQNm2zO519Af1Ib7P7SBATqSMbhyu2/VcTnb3TcOg==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/jintr/-/jintr-1.0.0.tgz",
"integrity": "sha512-Kbyb5jiIzmTrbhbdjQGt+jjVzn9BPluvL3mZU5ihFQIEGjCHUA4+rsXE2PNDKmg1UlfdTn3947aSwWOVnc5UIw==",
"funding": [
"https://github.com/sponsors/LuanRT"
],
@@ -6193,10 +6206,9 @@
}
},
"node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg=="
},
"node_modules/tsutils": {
"version": "3.21.0",
@@ -6213,6 +6225,12 @@
"typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"
}
},
"node_modules/tsutils/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
},
"node_modules/type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
@@ -6247,16 +6265,16 @@
}
},
"node_modules/typescript": {
"version": "4.9.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=4.2.0"
"node": ">=12.20"
}
},
"node_modules/uhyphen": {
@@ -7641,6 +7659,14 @@
"requires": {
"@yarnpkg/libzip": "^2.2.4",
"tslib": "^1.13.0"
},
"dependencies": {
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
}
}
},
"@yarnpkg/libzip": {
@@ -7651,6 +7677,14 @@
"requires": {
"@types/emscripten": "^1.38.0",
"tslib": "^1.13.0"
},
"dependencies": {
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
}
}
},
"acorn": {
@@ -9619,9 +9653,9 @@
}
},
"jintr": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/jintr/-/jintr-0.4.1.tgz",
"integrity": "sha512-R42VuIoTjsGbZuEmtT7WqyErd9JQuuV17Cg05wQwRWkQbmQNm2zO519Af1Ib7P7SBATqSMbhyu2/VcTnb3TcOg==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/jintr/-/jintr-1.0.0.tgz",
"integrity": "sha512-Kbyb5jiIzmTrbhbdjQGt+jjVzn9BPluvL3mZU5ihFQIEGjCHUA4+rsXE2PNDKmg1UlfdTn3947aSwWOVnc5UIw==",
"requires": {
"acorn": "^8.8.0"
}
@@ -10930,10 +10964,9 @@
}
},
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz",
"integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg=="
},
"tsutils": {
"version": "3.21.0",
@@ -10942,6 +10975,14 @@
"dev": true,
"requires": {
"tslib": "^1.8.1"
},
"dependencies": {
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
}
}
},
"type-check": {
@@ -10966,9 +11007,9 @@
"dev": true
},
"typescript": {
"version": "4.9.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz",
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
"dev": true
},
"uhyphen": {

View File

@@ -1,6 +1,6 @@
{
"name": "youtubei.js",
"version": "3.1.0",
"version": "5.2.0",
"description": "A wrapper around YouTube's private API. Supports YouTube, YouTube Music, YouTube Kids and YouTube Studio (WIP).",
"type": "module",
"types": "./dist/src/platform/lib.d.ts",
@@ -72,8 +72,8 @@
"build:proto": "npx pb-gen-ts --entry-path=\"src/proto\" --out-dir=\"src/proto/generated\" --ext-in-import=\".js\"",
"build:esm": "npx tsc",
"build:deno": "npx cpy ./src ./deno && npx cpy ./package.json ./deno && npx replace \".js';\" \".ts';\" ./deno -r && npx replace '.js\";' '.ts\";' ./deno -r && npx replace \"'linkedom';\" \"'https://esm.sh/linkedom';\" ./deno -r && npx replace \"'jintr';\" \"'https://esm.sh/jintr';\" ./deno -r && npx replace \"new Jinter.default\" \"new Jinter\" ./deno -r",
"bundle:node": "npx esbuild ./dist/src/platform/node.js --bundle --target=node10 --keep-names --format=cjs --platform=node --outfile=./bundle/node.cjs --external:jintr --external:undici --external:linkedom --sourcemap --banner:js=\"/* eslint-disable */\"",
"bundle:browser": "npx esbuild ./dist/src/platform/web.js --banner:js=\"/* eslint-disable */\" --bundle --target=chrome58 --keep-names --format=esm --sourcemap --define:global=globalThis --outfile=./bundle/browser.js --platform=browser",
"bundle:node": "npx esbuild ./dist/src/platform/node.js --bundle --target=node10 --keep-names --format=cjs --platform=node --outfile=./bundle/node.cjs --external:jintr --external:undici --external:linkedom --external:tslib --sourcemap --banner:js=\"/* eslint-disable */\"",
"bundle:browser": "npx esbuild ./dist/src/platform/web.js --banner:js=\"/* eslint-disable */\" --bundle --target=chrome58 --keep-names --format=esm --sourcemap --define:global=globalThis --conditions=module --outfile=./bundle/browser.js --platform=browser",
"bundle:browser:prod": "npm run bundle:browser -- --outfile=./bundle/browser.min.js --minify",
"prepare": "npm run build",
"watch": "npx tsc --watch"
@@ -84,8 +84,9 @@
},
"license": "MIT",
"dependencies": {
"jintr": "^0.4.1",
"jintr": "^1.0.0",
"linkedom": "^0.14.12",
"tslib": "^2.5.0",
"undici": "^5.19.1"
},
"devDependencies": {
@@ -102,7 +103,7 @@
"pbkit": "^0.0.59",
"replace": "^1.2.2",
"ts-jest": "^28.0.8",
"typescript": "^4.9.5"
"typescript": "^5.0.0"
},
"bugs": {
"url": "https://github.com/LuanRT/YouTube.js/issues"

View File

@@ -3,9 +3,7 @@ const fs = require('fs');
const path = require('path');
const import_list = [];
const json = [];
const misc_exports = [];
const misc_imports = [];
glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname })
.forEach((file) => {
@@ -16,44 +14,26 @@ glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname })
if (is_misc) {
const class_name = file.split('/').pop().replace('.js', '').replace('.ts', '');
import_list.push(`import { default as ${class_name} } from './classes/${file}.js';`);
misc_exports.push(class_name);
misc_imports.push(`export { default as ${class_name} } from './classes/${file}.js';`);
} else {
import_list.push(`import { default as ${import_name} } from './classes/${file}.js';
export { ${import_name} };`);
json.push(import_name);
import_list.push(`export { default as ${import_name} } from './classes/${file}.js';`);
}
});
fs.writeFileSync(
path.resolve(__dirname, '../src/parser/map.ts'),
path.resolve(__dirname, '../src/parser/nodes.ts'),
`// This file was auto generated, do not edit.
// See ./scripts/build-parser-map.js
import { YTNodeConstructor } from './helpers.js';
${import_list.join('\n')}
`
);
const map: Record<string, YTNodeConstructor> = {
${json.join(',\n ')}
};
fs.writeFileSync(
path.resolve(__dirname, '../src/parser/misc.ts'),
`// This file was auto generated, do not edit.
// See ./scripts/build-parser-map.js
export const Misc = {
${misc_exports.join(',\n ')}
};
/**
* @param name - Name of the node to be parsed
*/
export default function GetParserByName(name: string) {
const ParserConstructor = map[name];
if (!ParserConstructor) {
const error = new Error(\`Module not found: \${name}\`);
(error as any).code = 'MODULE_NOT_FOUND';
throw error;
}
return ParserConstructor;
}
${misc_imports.join('\n')}
`
);

View File

@@ -1,68 +1,65 @@
import Session, { SessionOptions } from './core/Session.js';
import type { SessionOptions } from './core/Session.js';
import Session from './core/Session.js';
import NavigationEndpoint from './parser/classes/NavigationEndpoint.js';
import type Format from './parser/classes/misc/Format.js';
import Channel from './parser/youtube/Channel.js';
import Comments from './parser/youtube/Comments.js';
import Guide from './parser/youtube/Guide.js';
import HashtagFeed from './parser/youtube/HashtagFeed.js';
import History from './parser/youtube/History.js';
import HomeFeed from './parser/youtube/HomeFeed.js';
import Library from './parser/youtube/Library.js';
import NotificationsMenu from './parser/youtube/NotificationsMenu.js';
import Playlist from './parser/youtube/Playlist.js';
import Search from './parser/youtube/Search.js';
import VideoInfo from './parser/youtube/VideoInfo.js';
import HashtagFeed from './parser/youtube/HashtagFeed.js';
import AccountManager from './core/AccountManager.js';
import Feed from './core/Feed.js';
import InteractionManager from './core/InteractionManager.js';
import YTKids from './core/Kids.js';
import YTMusic from './core/Music.js';
import PlaylistManager from './core/PlaylistManager.js';
import YTStudio from './core/Studio.js';
import TabbedFeed from './core/TabbedFeed.js';
import HomeFeed from './parser/youtube/HomeFeed.js';
import { Kids, Music, Studio } from './core/clients/index.js';
import { AccountManager, InteractionManager, PlaylistManager } from './core/managers/index.js';
import { Feed, TabbedFeed } from './core/mixins/index.js';
import Proto from './proto/index.js';
import Constants from './utils/Constants.js';
import * as Constants from './utils/Constants.js';
import { InnertubeError, generateRandomString, throwIfMissing } from './utils/Utils.js';
import type Actions from './core/Actions.js';
import type Format from './parser/classes/misc/Format.js';
import {
BrowseEndpoint,
GetNotificationMenuEndpoint,
GuideEndpoint,
NextEndpoint,
PlayerEndpoint,
ResolveURLEndpoint,
SearchEndpoint
} from './core/endpoints/index.js';
import { GetUnseenCountEndpoint } from './core/endpoints/notification/index.js';
import type { ApiResponse } from './core/Actions.js';
import type { IBrowseResponse, IParsedResponse } from './parser/types/index.js';
import type { INextRequest } from './types/index.js';
import type { DownloadOptions, FormatOptions } from './utils/FormatUtils.js';
import { generateRandomString, throwIfMissing } from './utils/Utils.js';
export type InnertubeConfig = SessionOptions;
export interface SearchFilters {
upload_date?: 'all' | 'hour' | 'today' | 'week' | 'month' | 'year';
type?: 'all' | 'video' | 'channel' | 'playlist' | 'movie';
duration?: 'all' | 'short' | 'medium' | 'long';
sort_by?: 'relevance' | 'rating' | 'upload_date' | 'view_count';
features?: ('hd' | 'subtitles' | 'creative_commons' | '3d' | 'live' | 'purchased' | '4k' | '360' | 'location' | 'hdr' | 'vr180')[];
}
export type InnerTubeClient = 'WEB' | 'ANDROID' | 'YTMUSIC_ANDROID' | 'YTMUSIC' | 'YTSTUDIO_ANDROID' | 'TV_EMBEDDED' | 'YTKIDS'
class Innertube {
session: Session;
account: AccountManager;
playlist: PlaylistManager;
interact: InteractionManager;
music: YTMusic;
studio: YTStudio;
kids: YTKids;
actions: Actions;
export type SearchFilters = Partial<{
upload_date: 'all' | 'hour' | 'today' | 'week' | 'month' | 'year';
type: 'all' | 'video' | 'channel' | 'playlist' | 'movie';
duration: 'all' | 'short' | 'medium' | 'long';
sort_by: 'relevance' | 'rating' | 'upload_date' | 'view_count';
features: ('hd' | 'subtitles' | 'creative_commons' | '3d' | 'live' | 'purchased' | '4k' | '360' | 'location' | 'hdr' | 'vr180')[];
}>;
/**
* Provides access to various services and modules in the YouTube API.
*/
export default class Innertube {
#session: Session;
constructor(session: Session) {
this.session = session;
this.account = new AccountManager(this.session.actions);
this.playlist = new PlaylistManager(this.session.actions);
this.interact = new InteractionManager(this.session.actions);
this.music = new YTMusic(this.session);
this.studio = new YTStudio(this.session);
this.kids = new YTKids(this.session);
this.actions = this.session.actions;
this.#session = session;
}
static async create(config: InnertubeConfig = {}): Promise<Innertube> {
@@ -71,19 +68,46 @@ class Innertube {
/**
* Retrieves video info.
* @param video_id - The video id.
* @param target - The video id or `NavigationEndpoint`.
* @param client - The client to use.
*/
async getInfo(video_id: string, client?: InnerTubeClient): Promise<VideoInfo> {
throwIfMissing({ video_id });
async getInfo(target: string | NavigationEndpoint, client?: InnerTubeClient): Promise<VideoInfo> {
throwIfMissing({ target });
let next_payload: INextRequest;
if (target instanceof NavigationEndpoint) {
next_payload = NextEndpoint.build({
video_id: target.payload?.videoId,
playlist_id: target.payload?.playlistId,
params: target.payload?.params,
playlist_index: target.payload?.index
});
} else if (typeof target === 'string') {
next_payload = NextEndpoint.build({
video_id: target
});
} else {
throw new InnertubeError('Invalid target, expected either a video id or a valid NavigationEndpoint', target);
}
if (!next_payload.videoId)
throw new InnertubeError('Video id cannot be empty', next_payload);
const player_payload = PlayerEndpoint.build({
video_id: next_payload.videoId,
playlist_id: next_payload?.playlistId,
client: client,
sts: this.#session.player?.sts
});
const player_response = this.actions.execute(PlayerEndpoint.PATH, player_payload);
const next_response = this.actions.execute(NextEndpoint.PATH, next_payload);
const response = await Promise.all([ player_response, next_response ]);
const cpn = generateRandomString(16);
const initial_info = this.actions.getVideoInfo(video_id, cpn, client);
const continuation = this.actions.execute('/next', { videoId: video_id });
const response = await Promise.all([ initial_info, continuation ]);
return new VideoInfo(response, this.actions, this.session.player, cpn);
return new VideoInfo(response, this.actions, cpn);
}
/**
@@ -94,10 +118,17 @@ class Innertube {
async getBasicInfo(video_id: string, client?: InnerTubeClient): Promise<VideoInfo> {
throwIfMissing({ video_id });
const cpn = generateRandomString(16);
const response = await this.actions.getVideoInfo(video_id, cpn, client);
const response = await this.actions.execute(
PlayerEndpoint.PATH, PlayerEndpoint.build({
video_id: video_id,
client: client,
sts: this.#session.player?.sts
})
);
return new VideoInfo([ response ], this.actions, this.session.player, cpn);
const cpn = generateRandomString(16);
return new VideoInfo([ response ], this.actions, cpn);
}
/**
@@ -108,14 +139,11 @@ class Innertube {
async search(query: string, filters: SearchFilters = {}): Promise<Search> {
throwIfMissing({ query });
const args = {
query,
...{
params: filters ? Proto.encodeSearchFilters(filters) : undefined
}
};
const response = await this.actions.execute('/search', args);
const response = await this.actions.execute(
SearchEndpoint.PATH, SearchEndpoint.build({
query, params: filters ? Proto.encodeSearchFilters(filters) : undefined
})
);
return new Search(this.actions, response);
}
@@ -129,14 +157,14 @@ class Innertube {
const url = new URL(`${Constants.URLS.YT_SUGGESTIONS}search`);
url.searchParams.set('q', query);
url.searchParams.set('hl', this.session.context.client.hl);
url.searchParams.set('gl', this.session.context.client.gl);
url.searchParams.set('hl', this.#session.context.client.hl);
url.searchParams.set('gl', this.#session.context.client.gl);
url.searchParams.set('ds', 'yt');
url.searchParams.set('client', 'youtube');
url.searchParams.set('xssi', 't');
url.searchParams.set('oe', 'UTF');
const response = await this.session.http.fetch(url);
const response = await this.#session.http.fetch(url);
const response_data = await response.text();
const data = JSON.parse(response_data.replace(')]}\'', ''));
@@ -153,11 +181,13 @@ class Innertube {
async getComments(video_id: string, sort_by?: 'TOP_COMMENTS' | 'NEWEST_FIRST'): Promise<Comments> {
throwIfMissing({ video_id });
const payload = Proto.encodeCommentsSectionParams(video_id, {
sort_by: sort_by || 'TOP_COMMENTS'
});
const response = await this.actions.execute('/next', { continuation: payload });
const response = await this.actions.execute(
NextEndpoint.PATH, NextEndpoint.build({
continuation: Proto.encodeCommentsSectionParams(video_id, {
sort_by: sort_by || 'TOP_COMMENTS'
})
})
);
return new Comments(this.actions, response.data);
}
@@ -166,15 +196,27 @@ class Innertube {
* Retrieves YouTube's home feed (aka recommendations).
*/
async getHomeFeed(): Promise<HomeFeed> {
const response = await this.actions.execute('/browse', { browseId: 'FEwhat_to_watch' });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({ browse_id: 'FEwhat_to_watch' })
);
return new HomeFeed(this.actions, response);
}
/**
* Retrieves YouTube's content guide.
*/
async getGuide(): Promise<Guide> {
const response = await this.actions.execute(GuideEndpoint.PATH);
return new Guide(response.data);
}
/**
* Returns the account's library.
*/
async getLibrary(): Promise<Library> {
const response = await this.actions.execute('/browse', { browseId: 'FElibrary' });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({ browse_id: 'FElibrary' })
);
return new Library(this.actions, response);
}
@@ -183,7 +225,9 @@ class Innertube {
* Which can also be achieved with {@link getLibrary}.
*/
async getHistory(): Promise<History> {
const response = await this.actions.execute('/browse', { browseId: 'FEhistory' });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({ browse_id: 'FEhistory' })
);
return new History(this.actions, response);
}
@@ -191,7 +235,9 @@ class Innertube {
* Retrieves trending content.
*/
async getTrending(): Promise<TabbedFeed<IBrowseResponse>> {
const response = await this.actions.execute('/browse', { browseId: 'FEtrending', parse: true });
const response = await this.actions.execute(
BrowseEndpoint.PATH, { ...BrowseEndpoint.build({ browse_id: 'FEtrending' }), parse: true }
);
return new TabbedFeed(this.actions, response);
}
@@ -199,7 +245,9 @@ class Innertube {
* Retrieves subscriptions feed.
*/
async getSubscriptionsFeed(): Promise<Feed<IBrowseResponse>> {
const response = await this.actions.execute('/browse', { browseId: 'FEsubscriptions', parse: true });
const response = await this.actions.execute(
BrowseEndpoint.PATH, { ...BrowseEndpoint.build({ browse_id: 'FEsubscriptions' }), parse: true }
);
return new Feed(this.actions, response);
}
@@ -209,7 +257,9 @@ class Innertube {
*/
async getChannel(id: string): Promise<Channel> {
throwIfMissing({ id });
const response = await this.actions.execute('/browse', { browseId: id });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({ browse_id: id })
);
return new Channel(this.actions, response);
}
@@ -217,7 +267,11 @@ class Innertube {
* Retrieves notifications.
*/
async getNotifications(): Promise<NotificationsMenu> {
const response = await this.actions.execute('/notification/get_notification_menu', { notificationsMenuRequestType: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX' });
const response = await this.actions.execute(
GetNotificationMenuEndpoint.PATH, GetNotificationMenuEndpoint.build({
notifications_menu_request_type: 'NOTIFICATIONS_MENU_REQUEST_TYPE_INBOX'
})
);
return new NotificationsMenu(this.actions, response);
}
@@ -225,7 +279,7 @@ class Innertube {
* Retrieves unseen notifications count.
*/
async getUnseenNotificationsCount(): Promise<number> {
const response = await this.actions.execute('/notification/get_unseen_count');
const response = await this.actions.execute(GetUnseenCountEndpoint.PATH);
// TODO: properly parse this
return response.data?.unseenCount || response.data?.actions?.[0].updateNotificationsUnseenCountAction?.unseenCount || 0;
}
@@ -241,7 +295,9 @@ class Innertube {
id = `VL${id}`;
}
const response = await this.actions.execute('/browse', { browseId: id });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({ browse_id: id })
);
return new Playlist(this.actions, response);
}
@@ -253,8 +309,12 @@ class Innertube {
async getHashtag(hashtag: string): Promise<HashtagFeed> {
throwIfMissing({ hashtag });
const params = Proto.encodeHashtag(hashtag);
const response = await this.actions.execute('/browse', { browseId: 'FEhashtag', params });
const response = await this.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'FEhashtag',
params: Proto.encodeHashtag(hashtag)
})
);
return new HashtagFeed(this.actions, response);
}
@@ -288,7 +348,9 @@ class Innertube {
* @param url - The URL.
*/
async resolveURL(url: string): Promise<NavigationEndpoint> {
const response = await this.actions.execute('/navigation/resolve_url', { url, parse: true });
const response = await this.actions.execute(
ResolveURLEndpoint.PATH, { ...ResolveURLEndpoint.build({ url }), parse: true }
);
return response.endpoint;
}
@@ -302,6 +364,60 @@ class Innertube {
call(endpoint: NavigationEndpoint, args?: object): Promise<IParsedResponse | ApiResponse> {
return endpoint.call(this.actions, args);
}
}
export default Innertube;
/**
* An interface for interacting with YouTube Music.
*/
get music() {
return new Music(this.#session);
}
/**
* An interface for interacting with YouTube Studio.
*/
get studio() {
return new Studio(this.#session);
}
/**
* An interface for interacting with YouTube Kids.
*/
get kids() {
return new Kids(this.#session);
}
/**
* An interface for managing and retrieving account information.
*/
get account() {
return new AccountManager(this.#session.actions);
}
/**
* An interface for managing playlists.
*/
get playlist() {
return new PlaylistManager(this.#session.actions);
}
/**
* An interface for directly interacting with certain YouTube features.
*/
get interact() {
return new InteractionManager(this.#session.actions);
}
/**
* An internal class used to dispatch requests.
*/
get actions() {
return this.#session.actions;
}
/**
* The session used by this instance.
*/
get session() {
return this.#session;
}
}

View File

@@ -28,7 +28,7 @@ export type ParsedResponse<T> =
T extends '/notification/get_notification_menu' ? IGetNotificationsMenuResponse :
IParsedResponse;
class Actions {
export default class Actions {
#session: Session;
constructor(session: Session) {
@@ -51,57 +51,6 @@ class Actions {
};
}
/**
* Used to retrieve video info.
* @param id - The video ID.
* @param cpn - Content Playback Nonce.
* @param client - The client to use.
* @param playlist_id - The playlist ID.
*/
async getVideoInfo(id: string, cpn?: string, client?: string, playlist_id?: string): Promise<ApiResponse> {
const data: Record<string, any> = {
playbackContext: {
contentPlaybackContext: {
vis: 0,
splay: false,
referer: 'https://www.youtube.com',
currentUrl: `/watch?v=${id}`,
autonavState: 'STATE_NONE',
signatureTimestamp: this.#session.player?.sts || 0,
autoCaptionsDefaultOn: false,
html5Preference: 'HTML5_PREF_WANTS',
lactMilliseconds: '-1'
}
},
attestationRequest: {
omitBotguardData: true
},
videoId: id
};
if (client) {
data.client = client;
}
if (cpn) {
data.cpn = cpn;
}
if (playlist_id) {
data.playlistId = playlist_id;
}
const response = await this.#session.http.fetch('/player', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
});
return this.#wrap(response);
}
/**
* Makes calls to the playback tracking API.
* @param url - The URL to call.
@@ -226,6 +175,4 @@ class Actions {
'SPtime_watched'
].includes(id);
}
}
export default Actions;
}

View File

@@ -1,68 +0,0 @@
import Search from '../parser/ytkids/Search.js';
import HomeFeed from '../parser/ytkids/HomeFeed.js';
import VideoInfo from '../parser/ytkids/VideoInfo.js';
import Channel from '../parser/ytkids/Channel.js';
import type Session from './Session.js';
import { generateRandomString } from '../utils/Utils.js';
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);
}
/**
* 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 contents of the given channel.
* @param channel_id - The channel id.
*/
async getChannel(channel_id: string): Promise<Channel> {
const response = await this.#session.actions.execute('/browse', { browseId: channel_id, client: 'YTKIDS' });
return new Channel(this.#session.actions, response);
}
/**
* 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);
}
}
export default Kids;

View File

@@ -1,4 +1,4 @@
import Constants from '../utils/Constants.js';
import * as Constants from '../utils/Constants.js';
import { OAuthError, Platform } from '../utils/Utils.js';
import type Session from './Session.js';
@@ -28,7 +28,7 @@ export type OAuthAuthEventHandler = (data: {
export type OAuthAuthPendingEventHandler = (data: OAuthAuthPendingData) => any;
export type OAuthAuthErrorEventHandler = (err: OAuthError) => any;
class OAuth {
export default class OAuth {
#identity?: Record<string, string>;
#session: Session;
#credentials?: Credentials;
@@ -96,7 +96,7 @@ class OAuth {
client_id: this.#identity.client_id,
scope: Constants.OAUTH.SCOPE,
device_id: Platform.shim.uuidv4(),
model_name: Constants.OAUTH.MODEL_NAME
device_model: Constants.OAUTH.MODEL_NAME
};
const response = await this.#session.http.fetch_function(new URL('/o/oauth2/device/code', Constants.URLS.YT_BASE), {
@@ -264,6 +264,4 @@ class OAuth {
Reflect.has(this.#credentials, 'refresh_token') &&
Reflect.has(this.#credentials, 'expires') || false;
}
}
export default OAuth;
}

View File

@@ -1,10 +1,13 @@
import { Platform, getRandomUserAgent, getStringBetweenStrings, PlayerError } from '../utils/Utils.js';
import Constants from '../utils/Constants.js';
import * as Constants from '../utils/Constants.js';
import { ICache } from '../types/Cache.js';
import { FetchFunction } from '../types/PlatformShim.js';
import type { ICache } from '../types/Cache.js';
import type { FetchFunction } from '../types/PlatformShim.js';
/**
* Represents YouTube's player script. This is required to decipher signatures.
*/
export default class Player {
#nsig_sc;
#sig_sc;
@@ -104,6 +107,29 @@ export default class Player {
url_components.searchParams.set('n', nsig);
}
const client = url_components.searchParams.get('c');
switch (client) {
case 'WEB':
url_components.searchParams.set('cver', Constants.CLIENTS.WEB.VERSION);
break;
case 'WEB_REMIX':
url_components.searchParams.set('cver', Constants.CLIENTS.YTMUSIC.VERSION);
break;
case 'WEB_KIDS':
url_components.searchParams.set('cver', Constants.CLIENTS.WEB_KIDS.VERSION);
break;
case 'ANDROID':
url_components.searchParams.set('cver', Constants.CLIENTS.ANDROID.VERSION);
break;
case 'ANDROID_MUSIC':
url_components.searchParams.set('cver', Constants.CLIENTS.YTMUSIC_ANDROID.VERSION);
break;
case 'TVHTML5_SIMPLY_EMBEDDED_PLAYER':
url_components.searchParams.set('cver', Constants.CLIENTS.TV_EMBEDDED.VERSION);
break;
}
return url_components.toString();
}

View File

@@ -1,14 +1,16 @@
import Constants, { CLIENTS } from '../utils/Constants.js';
import * as Constants from '../utils/Constants.js';
import EventEmitterLike from '../utils/EventEmitterLike.js';
import Actions from './Actions.js';
import Player from './Player.js';
import HTTPClient from '../utils/HTTPClient.js';
import { Platform, DeviceCategory, generateRandomString, getRandomUserAgent, InnertubeError, SessionError } from '../utils/Utils.js';
import OAuth, { Credentials, OAuthAuthErrorEventHandler, OAuthAuthEventHandler, OAuthAuthPendingEventHandler } from './OAuth.js';
import Proto from '../proto/index.js';
import { ICache } from '../types/Cache.js';
import { FetchFunction } from '../types/PlatformShim.js';
import type { ICache } from '../types/Cache.js';
import type { FetchFunction } from '../types/PlatformShim.js';
import HTTPClient from '../utils/HTTPClient.js';
import type { DeviceCategory } from '../utils/Utils.js';
import { generateRandomString, getRandomUserAgent, InnertubeError, Platform, SessionError } from '../utils/Utils.js';
import type { Credentials, OAuthAuthErrorEventHandler, OAuthAuthEventHandler, OAuthAuthPendingEventHandler } from './OAuth.js';
import OAuth from './OAuth.js';
export enum ClientType {
WEB = 'WEB',
@@ -30,7 +32,6 @@ export interface Context {
screenPixelDensity: number;
screenWidthPoints: number;
visitorData: string;
userAgent: string;
clientName: string;
clientVersion: string;
clientScreen?: string,
@@ -41,6 +42,7 @@ export interface Context {
clientFormFactor: string;
userInterfaceTheme: string;
timeZone: string;
userAgent?: string;
browserName?: string;
browserVersion?: string;
originalUrl: string;
@@ -64,9 +66,6 @@ export interface Context {
thirdParty?: {
embedUrl: string;
};
request: {
useSsl: true;
};
}
export interface SessionOptions {
@@ -118,6 +117,11 @@ export interface SessionOptions {
* YouTube cookies.
*/
cookie?: string;
/**
* Setting this to a valid and persistent visitor data string will allow YouTube to give this session tailored content even when not logged in.
* A good way to get a valid one is by either grabbing it from a browser or calling InnerTube's `/visitor_id` endpoint.
*/
visitor_data?: string;
/**
* Fetch function to use.
*/
@@ -130,6 +134,9 @@ export interface SessionData {
api_version: string;
}
/**
* Represents an InnerTube session. This holds all the data needed to make requests to YouTube.
*/
export default class Session extends EventEmitterLike {
#api_version: string;
#key: string;
@@ -179,6 +186,7 @@ export default class Session extends EventEmitterLike {
options.lang,
options.location,
options.account_index,
options.visitor_data,
options.enable_safety_mode,
options.generate_session_locally,
options.device_category,
@@ -198,6 +206,7 @@ export default class Session extends EventEmitterLike {
lang = '',
location = '',
account_index = 0,
visitor_data = '',
enable_safety_mode = false,
generate_session_locally = false,
device_category: DeviceCategory = 'desktop',
@@ -208,9 +217,9 @@ export default class Session extends EventEmitterLike {
let session_data: SessionData;
if (generate_session_locally) {
session_data = this.#generateSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode });
session_data = this.#generateSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data });
} else {
session_data = await this.#retrieveSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode }, fetch);
session_data = await this.#retrieveSessionData({ lang, location, time_zone: tz, device_category, client_name, enable_safety_mode, visitor_data }, fetch);
}
return { ...session_data, account_index };
@@ -223,16 +232,24 @@ export default class Session extends EventEmitterLike {
device_category: string;
client_name: string;
enable_safety_mode: boolean;
visitor_data: string;
}, fetch: FetchFunction = Platform.shim.fetch): Promise<SessionData> {
const url = new URL('/sw.js_data', Constants.URLS.YT_BASE);
let visitor_id = generateRandomString(11);
if (options.visitor_data) {
const decoded_visitor_data = Proto.decodeVisitorData(options.visitor_data);
visitor_id = decoded_visitor_data.id;
}
const res = await fetch(url, {
headers: {
'accept-language': options.lang || 'en-US',
'user-agent': getRandomUserAgent('desktop'),
'accept': '*/*',
'referer': 'https://www.youtube.com/sw.js',
'cookie': `PREF=tz=${options.time_zone.replace('/', '.')}`
'cookie': `PREF=tz=${options.time_zone.replace('/', '.')};VISITOR_INFO1_LIVE=${visitor_id};`
}
});
@@ -258,7 +275,6 @@ export default class Session extends EventEmitterLike {
screenPixelDensity: 1,
screenWidthPoints: 1920,
visitorData: device_info[13],
userAgent: device_info[14],
clientName: options.client_name,
clientVersion: device_info[16],
osName: device_info[17],
@@ -272,14 +288,11 @@ export default class Session extends EventEmitterLike {
originalUrl: Constants.URLS.YT_BASE,
deviceMake: device_info[11],
deviceModel: device_info[12],
utcOffsetMinutes: new Date().getTimezoneOffset()
utcOffsetMinutes: -new Date().getTimezoneOffset()
},
user: {
enableSafetyMode: options.enable_safety_mode,
lockedSafetyMode: false
},
request: {
useSsl: true
}
};
@@ -292,10 +305,15 @@ export default class Session extends EventEmitterLike {
time_zone: string;
device_category: DeviceCategory;
client_name: string;
enable_safety_mode: boolean
enable_safety_mode: boolean;
visitor_data: string;
}): SessionData {
const id = generateRandomString(11);
const timestamp = Math.floor(Date.now() / 1000);
let visitor_id = generateRandomString(11);
if (options.visitor_data) {
const decoded_visitor_data = Proto.decodeVisitorData(options.visitor_data);
visitor_id = decoded_visitor_data.id;
}
const context: Context = {
client: {
@@ -305,10 +323,9 @@ export default class Session extends EventEmitterLike {
screenHeightPoints: 1080,
screenPixelDensity: 1,
screenWidthPoints: 1920,
visitorData: Proto.encodeVisitorData(id, timestamp),
userAgent: getRandomUserAgent('desktop'),
visitorData: Proto.encodeVisitorData(visitor_id, Math.floor(Date.now() / 1000)),
clientName: options.client_name,
clientVersion: CLIENTS.WEB.VERSION,
clientVersion: Constants.CLIENTS.WEB.VERSION,
osName: 'Windows',
osVersion: '10.0',
platform: options.device_category.toUpperCase(),
@@ -318,18 +335,15 @@ export default class Session extends EventEmitterLike {
originalUrl: Constants.URLS.YT_BASE,
deviceMake: '',
deviceModel: '',
utcOffsetMinutes: new Date().getTimezoneOffset()
utcOffsetMinutes: -new Date().getTimezoneOffset()
},
user: {
enableSafetyMode: options.enable_safety_mode,
lockedSafetyMode: false
},
request: {
useSsl: true
}
};
return { context, api_key: CLIENTS.WEB.API_KEY, api_version: CLIENTS.WEB.API_VERSION };
return { context, api_key: Constants.CLIENTS.WEB.API_KEY, api_version: Constants.CLIENTS.WEB.API_VERSION };
}
async signIn(credentials?: Credentials): Promise<void> {

83
src/core/clients/Kids.ts Normal file
View File

@@ -0,0 +1,83 @@
import Channel from '../../parser/ytkids/Channel.js';
import HomeFeed from '../../parser/ytkids/HomeFeed.js';
import Search from '../../parser/ytkids/Search.js';
import VideoInfo from '../../parser/ytkids/VideoInfo.js';
import type Session from '../Session.js';
import { generateRandomString } from '../../utils/Utils.js';
import {
BrowseEndpoint, NextEndpoint,
PlayerEndpoint, SearchEndpoint
} from '../endpoints/index.js';
export default 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(
SearchEndpoint.PATH, SearchEndpoint.build({ client: 'YTKIDS', query })
);
return new Search(this.#session.actions, response);
}
/**
* Retrieves video info.
* @param video_id - The video id.
*/
async getInfo(video_id: string): Promise<VideoInfo> {
const player_payload = PlayerEndpoint.build({
sts: this.#session.player?.sts,
client: 'YTKIDS',
video_id
});
const next_payload = NextEndpoint.build({
video_id,
client: 'YTKIDS'
});
const player_response = this.#session.actions.execute(PlayerEndpoint.PATH, player_payload);
const next_response = this.#session.actions.execute(NextEndpoint.PATH, next_payload);
const response = await Promise.all([ player_response, next_response ]);
const cpn = generateRandomString(16);
return new VideoInfo(response, this.#session.actions, cpn);
}
/**
* Retrieves the contents of the given channel.
* @param channel_id - The channel id.
*/
async getChannel(channel_id: string): Promise<Channel> {
const response = await this.#session.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: channel_id,
client: 'YTKIDS'
})
);
return new Channel(this.#session.actions, response);
}
/**
* Retrieves the home feed.
*/
async getHomeFeed(): Promise<HomeFeed> {
const response = await this.#session.actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'FEkids_home',
client: 'YTKIDS'
})
);
return new HomeFeed(this.#session.actions, response);
}
}

View File

@@ -1,34 +1,41 @@
import Album from '../../parser/ytmusic/Album.js';
import Artist from '../../parser/ytmusic/Artist.js';
import Explore from '../../parser/ytmusic/Explore.js';
import HomeFeed from '../../parser/ytmusic/HomeFeed.js';
import Library from '../../parser/ytmusic/Library.js';
import Playlist from '../../parser/ytmusic/Playlist.js';
import Recap from '../../parser/ytmusic/Recap.js';
import Search from '../../parser/ytmusic/Search.js';
import TrackInfo from '../../parser/ytmusic/TrackInfo.js';
import Album from '../parser/ytmusic/Album.js';
import Artist from '../parser/ytmusic/Artist.js';
import Explore from '../parser/ytmusic/Explore.js';
import HomeFeed from '../parser/ytmusic/HomeFeed.js';
import Library from '../parser/ytmusic/Library.js';
import Playlist from '../parser/ytmusic/Playlist.js';
import Recap from '../parser/ytmusic/Recap.js';
import Search from '../parser/ytmusic/Search.js';
import TrackInfo from '../parser/ytmusic/TrackInfo.js';
import AutomixPreviewVideo from '../../parser/classes/AutomixPreviewVideo.js';
import Message from '../../parser/classes/Message.js';
import MusicCarouselShelf from '../../parser/classes/MusicCarouselShelf.js';
import MusicDescriptionShelf from '../../parser/classes/MusicDescriptionShelf.js';
import MusicQueue from '../../parser/classes/MusicQueue.js';
import MusicTwoRowItem from '../../parser/classes/MusicTwoRowItem.js';
import PlaylistPanel from '../../parser/classes/PlaylistPanel.js';
import SearchSuggestionsSection from '../../parser/classes/SearchSuggestionsSection.js';
import SectionList from '../../parser/classes/SectionList.js';
import Tab from '../../parser/classes/Tab.js';
import Proto from '../../proto/index.js';
import AutomixPreviewVideo from '../parser/classes/AutomixPreviewVideo.js';
import Message from '../parser/classes/Message.js';
import MusicCarouselShelf from '../parser/classes/MusicCarouselShelf.js';
import MusicDescriptionShelf from '../parser/classes/MusicDescriptionShelf.js';
import MusicQueue from '../parser/classes/MusicQueue.js';
import MusicTwoRowItem from '../parser/classes/MusicTwoRowItem.js';
import PlaylistPanel from '../parser/classes/PlaylistPanel.js';
import SearchSuggestionsSection from '../parser/classes/SearchSuggestionsSection.js';
import SectionList from '../parser/classes/SectionList.js';
import Tab from '../parser/classes/Tab.js';
import type { ObservedArray, YTNode } from '../../parser/helpers.js';
import type { MusicSearchFilters } from '../../types/index.js';
import { InnertubeError, generateRandomString, throwIfMissing } from '../../utils/Utils.js';
import type Actions from '../Actions.js';
import type Session from '../Session.js';
import { observe } from '../parser/helpers.js';
import Proto from '../proto/index.js';
import { generateRandomString, InnertubeError, throwIfMissing } from '../utils/Utils.js';
import {
BrowseEndpoint,
NextEndpoint,
PlayerEndpoint,
SearchEndpoint
} from '../endpoints/index.js';
import type { ObservedArray, YTNode } from '../parser/helpers.js';
import type Actions from './Actions.js';
import type Session from './Session.js';
import { GetSearchSuggestionsEndpoint } from '../endpoints/music/index.js';
class Music {
export default class Music {
#session: Session;
#actions: Actions;
@@ -52,25 +59,23 @@ class Music {
}
async #fetchInfoFromVideoId(video_id: string): Promise<TrackInfo> {
const player_payload = PlayerEndpoint.build({
video_id,
sts: this.#session.player?.sts,
client: 'YTMUSIC'
});
const next_payload = NextEndpoint.build({
video_id,
client: 'YTMUSIC'
});
const player_response = this.#actions.execute(PlayerEndpoint.PATH, player_payload);
const next_response = this.#actions.execute(NextEndpoint.PATH, next_payload);
const response = await Promise.all([ player_response, next_response ]);
const cpn = generateRandomString(16);
const initial_info = this.#actions.execute('/player', {
cpn,
client: 'YTMUSIC',
videoId: video_id,
playbackContext: {
contentPlaybackContext: {
signatureTimestamp: this.#session.player?.sts || 0
}
}
});
const continuation = this.#actions.execute('/next', {
client: 'YTMUSIC',
videoId: video_id
});
const response = await Promise.all([ initial_info, continuation ]);
return new TrackInfo(response, this.#actions, cpn);
}
@@ -81,25 +86,26 @@ class Music {
if (!list_item.endpoint)
throw new Error('This item does not have an endpoint.');
const cpn = generateRandomString(16);
const initial_info = list_item.endpoint.call(this.#actions, {
cpn,
const player_response = list_item.endpoint.call(this.#actions, {
client: 'YTMUSIC',
playbackContext: {
contentPlaybackContext: {
signatureTimestamp: this.#session.player?.sts || 0
...{
signatureTimestamp: this.#session.player?.sts
}
}
}
});
const continuation = list_item.endpoint.call(this.#actions, {
const next_response = list_item.endpoint.call(this.#actions, {
client: 'YTMUSIC',
enablePersistentPlaylistPanel: true,
override_endpoint: '/next'
});
const response = await Promise.all([ initial_info, continuation ]);
const cpn = generateRandomString(16);
const response = await Promise.all([ player_response, next_response ]);
return new TrackInfo(response, this.#actions, cpn);
}
@@ -108,22 +114,15 @@ class Music {
* @param query - Search query.
* @param filters - Search filters.
*/
async search(query: string, filters: {
type?: 'all' | 'song' | 'video' | 'album' | 'playlist' | 'artist';
} = {}): Promise<Search> {
async search(query: string, filters: MusicSearchFilters = {}): Promise<Search> {
throwIfMissing({ query });
const payload: {
query: string;
client: string;
params?: string;
} = { query, client: 'YTMUSIC' };
if (filters.type && filters.type !== 'all') {
payload.params = Proto.encodeMusicSearchFilters(filters);
}
const response = await this.#actions.execute('/search', payload);
const response = await this.#actions.execute(
SearchEndpoint.PATH, SearchEndpoint.build({
query, client: 'YTMUSIC',
params: filters.type && filters.type !== 'all' ? Proto.encodeMusicSearchFilters(filters) : undefined
})
);
return new Search(response, this.#actions, Reflect.has(filters, 'type') && filters.type !== 'all');
}
@@ -132,10 +131,12 @@ class Music {
* Retrieves the home feed.
*/
async getHomeFeed(): Promise<HomeFeed> {
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: 'FEmusic_home'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'FEmusic_home',
client: 'YTMUSIC'
})
);
return new HomeFeed(response, this.#actions);
}
@@ -144,10 +145,12 @@ class Music {
* Retrieves the Explore feed.
*/
async getExplore(): Promise<Explore> {
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: 'FEmusic_explore'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC',
browse_id: 'FEmusic_explore'
})
);
return new Explore(response);
// TODO: return new Explore(response, this.#actions);
@@ -157,10 +160,12 @@ class Music {
* Retrieves the library.
*/
async getLibrary(): Promise<Library> {
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: 'FEmusic_library_landing'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC',
browse_id: 'FEmusic_library_landing'
})
);
return new Library(response, this.#actions);
}
@@ -175,10 +180,12 @@ class Music {
if (!artist_id.startsWith('UC') && !artist_id.startsWith('FEmusic_library_privately_owned_artist'))
throw new InnertubeError('Invalid artist id', artist_id);
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: artist_id
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC',
browse_id: artist_id
})
);
return new Artist(response, this.#actions);
}
@@ -193,10 +200,12 @@ class Music {
if (!album_id.startsWith('MPR') && !album_id.startsWith('FEmusic_library_privately_owned_release'))
throw new InnertubeError('Invalid album id', album_id);
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: album_id
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC',
browse_id: album_id
})
);
return new Album(response);
}
@@ -212,10 +221,12 @@ class Music {
playlist_id = `VL${playlist_id}`;
}
const response = await this.#actions.execute('/browse', {
client: 'YTMUSIC',
browseId: playlist_id
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC',
browse_id: playlist_id
})
);
return new Playlist(response, this.#actions);
}
@@ -228,13 +239,11 @@ class Music {
async getUpNext(video_id: string, automix = true): Promise<PlaylistPanel> {
throwIfMissing({ video_id });
const data = await this.#actions.execute('/next', {
videoId: video_id,
client: 'YTMUSIC',
parse: true
});
const response = await this.#actions.execute(
NextEndpoint.PATH, { ...NextEndpoint.build({ video_id, client: 'YTMUSIC' }), parse: true }
);
const tabs = data.contents_memo?.getType(Tab);
const tabs = response.contents_memo?.getType(Tab);
const tab = tabs?.first();
@@ -276,13 +285,11 @@ class Music {
async getRelated(video_id: string): Promise<ObservedArray<MusicCarouselShelf | MusicDescriptionShelf>> {
throwIfMissing({ video_id });
const data = await this.#actions.execute('/next', {
videoId: video_id,
client: 'YTMUSIC',
parse: true
});
const response = await this.#actions.execute(
NextEndpoint.PATH, { ...NextEndpoint.build({ video_id, client: 'YTMUSIC' }), parse: true }
);
const tabs = data.contents_memo?.getType(Tab);
const tabs = response.contents_memo?.getType(Tab);
const tab = tabs?.matchCondition((tab) => tab.endpoint.payload.browseEndpointContextSupportedConfigs?.browseEndpointContextMusicConfig?.pageType === 'MUSIC_PAGE_TYPE_TRACK_RELATED');
@@ -306,13 +313,11 @@ class Music {
async getLyrics(video_id: string): Promise<MusicDescriptionShelf | undefined> {
throwIfMissing({ video_id });
const data = await this.#actions.execute('/next', {
videoId: video_id,
client: 'YTMUSIC',
parse: true
});
const response = await this.#actions.execute(
NextEndpoint.PATH, { ...NextEndpoint.build({ video_id, client: 'YTMUSIC' }), parse: true }
);
const tabs = data.contents_memo?.getType(Tab);
const tabs = response.contents_memo?.getType(Tab);
const tab = tabs?.matchCondition((tab) => tab.endpoint.payload.browseEndpointContextSupportedConfigs?.browseEndpointContextMusicConfig?.pageType === 'MUSIC_PAGE_TYPE_TRACK_LYRICS');
@@ -325,7 +330,7 @@ class Music {
throw new InnertubeError('Unexpected response', page);
if (page.contents.item().key('type').string() === 'Message')
throw new InnertubeError(page.contents.item().as(Message).text, video_id);
throw new InnertubeError(page.contents.item().as(Message).text.toString(), video_id);
const section_list = page.contents.item().as(SectionList).contents;
@@ -336,10 +341,12 @@ class Music {
* Retrieves recap.
*/
async getRecap(): Promise<Recap> {
const response = await this.#actions.execute('/browse', {
browseId: 'FEmusic_listening_review',
client: 'YTMUSIC_ANDROID'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
client: 'YTMUSIC_ANDROID',
browse_id: 'FEmusic_listening_review'
})
);
return new Recap(response, this.#actions);
}
@@ -349,19 +356,16 @@ class Music {
* @param query - The query.
*/
async getSearchSuggestions(query: string): Promise<ObservedArray<YTNode>> {
const response = await this.#actions.execute('/music/get_search_suggestions', {
parse: true,
input: query,
client: 'YTMUSIC'
});
const response = await this.#actions.execute(
GetSearchSuggestionsEndpoint.PATH,
{ ...GetSearchSuggestionsEndpoint.build({ input: query }), parse: true }
);
const search_suggestions_section = response.contents_memo?.getType(SearchSuggestionsSection)?.[0];
if (!response.contents_memo)
throw new InnertubeError('Unexpected response', response);
if (!search_suggestions_section?.contents.is_array)
return observe([] as YTNode[]);
const search_suggestions_section = response.contents_memo.getType(SearchSuggestionsSection).first();
return search_suggestions_section?.contents.array();
return search_suggestions_section.contents;
}
}
export default Music;
}

View File

@@ -1,9 +1,12 @@
import Proto from '../proto/index.js';
import { Constants } from '../utils/index.js';
import { InnertubeError, MissingParamError, Platform } from '../utils/Utils.js';
import Proto from '../../proto/index.js';
import * as Constants from '../../utils/Constants.js';
import { InnertubeError, MissingParamError, Platform } from '../../utils/Utils.js';
import type { ApiResponse } from './Actions.js';
import type Session from './Session.js';
import type { UpdateVideoMetadataOptions, UploadedVideoMetadataOptions } from '../../types/Clients.js';
import type { ApiResponse } from '../Actions.js';
import type Session from '../Session.js';
import { CreateVideoEndpoint } from '../endpoints/upload/index.js';
interface UploadResult {
status: string;
@@ -18,25 +21,7 @@ interface InitialUploadData {
chunk_granularity: string;
}
export interface VideoMetadata {
title?: string;
description?: string;
tags?: string[];
category?: number;
license?: string;
age_restricted?: boolean;
made_for_kids?: boolean;
privacy?: 'PUBLIC' | 'PRIVATE' | 'UNLISTED';
}
export interface UploadedVideoMetadata {
title?: string;
description?: string;
privacy?: 'PUBLIC' | 'PRIVATE' | 'UNLISTED';
is_draft?: boolean;
}
class Studio {
export default class Studio {
#session: Session;
constructor(session: Session) {
@@ -69,7 +54,7 @@ class Studio {
}
/**
* Updates given video's metadata.
* Updates a given video's metadata.
* @example
* ```ts
* const response = await yt.studio.updateVideoMetadata('videoid', {
@@ -82,7 +67,7 @@ class Studio {
* });
* ```
*/
async updateVideoMetadata(video_id: string, metadata: VideoMetadata): Promise<ApiResponse> {
async updateVideoMetadata(video_id: string, metadata: UpdateVideoMetadataOptions): Promise<ApiResponse> {
if (!this.#session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
@@ -104,7 +89,7 @@ class Studio {
* const response = await yt.studio.upload(file.buffer, { title: 'Wow!' });
* ```
*/
async upload(file: BodyInit, metadata: UploadedVideoMetadata = {}): Promise<ApiResponse> {
async upload(file: BodyInit, metadata: UploadedVideoMetadataOptions = {}): Promise<ApiResponse> {
if (!this.#session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
@@ -174,38 +159,34 @@ class Studio {
return data;
}
async #setVideoMetadata(initial_data: InitialUploadData, upload_result: UploadResult, metadata: UploadedVideoMetadata) {
const metadata_payload = {
resourceId: {
scottyResourceId: {
id: upload_result.scottyResourceId
}
},
frontendUploadId: initial_data.frontend_upload_id,
initialMetadata: {
title: {
newTitle: metadata.title || new Date().toDateString()
async #setVideoMetadata(initial_data: InitialUploadData, upload_result: UploadResult, metadata: UploadedVideoMetadataOptions) {
const response = await this.#session.actions.execute(
CreateVideoEndpoint.PATH, CreateVideoEndpoint.build({
resource_id: {
scotty_resource_id: {
id: upload_result.scottyResourceId
}
},
description: {
newDescription: metadata.description || '',
shouldSegment: true
frontend_upload_id: initial_data.frontend_upload_id,
initial_metadata: {
title: {
new_title: metadata.title || new Date().toDateString()
},
description: {
new_description: metadata.description || '',
should_segment: true
},
privacy: {
new_privacy: metadata.privacy || 'PRIVATE'
},
draft_state: {
is_draft: metadata.is_draft
}
},
privacy: {
newPrivacy: metadata.privacy || 'PRIVATE'
},
draftState: {
isDraft: metadata.is_draft || false
}
}
};
const response = await this.#session.actions.execute('/upload/createvideo', {
client: 'ANDROID',
...metadata_payload
});
client: 'ANDROID'
})
);
return response;
}
}
export default Studio;
}

View File

@@ -0,0 +1,3 @@
export { default as Kids } from './Kids.js';
export { default as Music } from './Music.js';
export { default as Studio } from './Studio.js';

View File

@@ -0,0 +1,19 @@
import type { IBrowseRequest, BrowseEndpointOptions } from '../../types/index.js';
export const PATH = '/browse';
/**
* Builds a `/browse` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: BrowseEndpointOptions): IBrowseRequest {
return {
...{
browseId: opts.browse_id,
params: opts.params,
continuation: opts.continuation,
client: opts.client
}
};
}

View File

@@ -0,0 +1,16 @@
import type { IGetNotificationMenuRequest, GetNotificationMenuEndpointOptions } from '../../types/index.js';
export const PATH = '/notification/get_notification_menu';
/**
* Builds a `/get_notification_menu` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: GetNotificationMenuEndpointOptions): IGetNotificationMenuRequest {
return {
...{
notificationsMenuRequestType: opts.notifications_menu_request_type
}
};
}

View File

@@ -0,0 +1 @@
export const PATH = '/guide';

View File

@@ -0,0 +1,21 @@
import type { INextRequest, NextEndpointOptions } from '../../types/index.js';
export const PATH = '/next';
/**
* Builds a `/next` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: NextEndpointOptions): INextRequest {
return {
...{
videoId: opts.video_id,
playlistId: opts.playlist_id,
params: opts.params,
playlistIndex: opts.playlist_index,
client: opts.client,
continuation: opts.continuation
}
};
}

View File

@@ -0,0 +1,44 @@
import type { IPlayerRequest, PlayerEndpointOptions } from '../../types/index.js';
export const PATH = '/player';
/**
* Builds a `/player` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: PlayerEndpointOptions): IPlayerRequest {
return {
playbackContext: {
contentPlaybackContext: {
vis: 0,
splay: false,
referer: opts.playlist_id ?
`https://www.youtube.com/watch?v=${opts.video_id}&list=${opts.playlist_id}` :
`https://www.youtube.com/watch?v=${opts.video_id}`,
currentUrl: opts.playlist_id ?
`/watch?v=${opts.video_id}&list=${opts.playlist_id}` :
`/watch?v=${opts.video_id}`,
autonavState: 'STATE_ON',
autoCaptionsDefaultOn: false,
html5Preference: 'HTML5_PREF_WANTS',
lactMilliseconds: '-1',
...{
signatureTimestamp: opts.sts
}
}
},
attestationRequest: {
omitBotguardData: true
},
racyCheckOk: true,
contentCheckOk: true,
videoId: opts.video_id,
...{
client: opts.client,
playlistId: opts.playlist_id,
// Workaround streaming URLs returning 403 when using Android clients and throttling in web clients.
params: '2AMBCgIQBg'
}
};
}

View File

@@ -0,0 +1,16 @@
import type { IResolveURLRequest, ResolveURLEndpointOptions } from '../../types/index.js';
export const PATH = '/navigation/resolve_url';
/**
* Builds a `/resolve_url` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: ResolveURLEndpointOptions): IResolveURLRequest {
return {
...{
url: opts.url
}
};
}

View File

@@ -0,0 +1,19 @@
import type { ISearchRequest, SearchEndpointOptions } from '../../types/index.js';
export const PATH = '/search';
/**
* Builds a `/search` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: SearchEndpointOptions): ISearchRequest {
return {
...{
query: opts.query,
params: opts.params,
continuation: opts.continuation,
client: opts.client
}
};
}

View File

@@ -0,0 +1,13 @@
import type { IAccountListRequest } from '../../../types/index.js';
export const PATH = '/account/accounts_list';
/**
* Builds a `/account/accounts_list` request payload.
* @returns The payload.
*/
export function build(): IAccountListRequest {
return {
client: 'ANDROID'
};
}

View File

@@ -0,0 +1 @@
export * as AccountListEndpoint from './AccountListEndpoint.js';

View File

@@ -0,0 +1,22 @@
import type { IEditPlaylistRequest, EditPlaylistEndpointOptions } from '../../../types/index.js';
export const PATH = '/browse/edit_playlist';
/**
* Builds a `/browse/edit_playlist` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: EditPlaylistEndpointOptions): IEditPlaylistRequest {
return {
playlistId: opts.playlist_id,
actions: opts.actions.map((action) => ({
action: action.action,
...{
addedVideoId: action.added_video_id,
setVideoId: action.set_video_id,
movedSetVideoIdPredecessor: action.moved_set_video_id_predecessor
}
}))
};
}

View File

@@ -0,0 +1 @@
export * as EditPlaylistEndpoint from './EditPlaylistEndpoint.js';

View File

@@ -0,0 +1,15 @@
import type { IChannelEditDescriptionRequest, ChannelEditDescriptionEndpointOptions } from '../../../types/Endpoints.js';
export const PATH = '/channel/edit_description';
/**
* Builds a `/channel/edit_description` request payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: ChannelEditDescriptionEndpointOptions): IChannelEditDescriptionRequest {
return {
givenDescription: options.given_description,
client: 'ANDROID'
};
}

View File

@@ -0,0 +1,15 @@
import type { IChannelEditNameRequest, ChannelEditNameEndpointOptions } from '../../../types/index.js';
export const PATH = '/channel/edit_name';
/**
* Builds a `/channel/edit_name` request payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: ChannelEditNameEndpointOptions): IChannelEditNameRequest {
return {
givenName: options.given_name,
client: 'ANDROID'
};
}

View File

@@ -0,0 +1,2 @@
export * as EditNameEndpoint from './EditNameEndpoint.js';
export * as EditDescriptionEndpoint from './EditDescriptionEndpoint.js';

View File

@@ -0,0 +1,18 @@
import type { ICreateCommentRequest, CreateCommentEndpointOptions } from '../../../types/index.js';
export const PATH = '/comment/create_comment';
/**
* Builds a `/comment/create_comment` request payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: CreateCommentEndpointOptions): ICreateCommentRequest {
return {
commentText: options.comment_text,
createCommentParams: options.create_comment_params,
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,17 @@
import type { IPerformCommentActionRequest, PerformCommentActionEndpointOptions } from '../../../types/index.js';
export const PATH = '/comment/perform_comment_action';
/**
* Builds a `/comment/perform_comment_action` request payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: PerformCommentActionEndpointOptions): IPerformCommentActionRequest {
return {
actions: options.actions,
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,2 @@
export * as PerformCommentActionEndpoint from './PerformCommentActionEndpoint.js';
export * as CreateCommentEndpoint from './CreateCommentEndpoint.js';

View File

@@ -0,0 +1,18 @@
export * as BrowseEndpoint from './BrowseEndpoint.js';
export * as GetNotificationMenuEndpoint from './GetNotificationMenuEndpoint.js';
export * as GuideEndpoint from './GuideEndpoint.js';
export * as NextEndpoint from './NextEndpoint.js';
export * as PlayerEndpoint from './PlayerEndpoint.js';
export * as ResolveURLEndpoint from './ResolveURLEndpoint.js';
export * as SearchEndpoint from './SearchEndpoint.js';
export * as Account from './account/index.js';
export * as Browse from './browse/index.js';
export * as Channel from './channel/index.js';
export * as Comment from './comment/index.js';
export * as Like from './like/index.js';
export * as Music from './music/index.js';
export * as Notification from './notification/index.js';
export * as Playlist from './playlist/index.js';
export * as Subscription from './subscription/index.js';
export * as Upload from './upload/index.js';

View File

@@ -0,0 +1,19 @@
import type { IDislikeRequest, DislikeEndpointOptions } from '../../../types/index.js';
export const PATH = '/like/dislike';
/**
* Builds a `/like/dislike` endpoint payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: DislikeEndpointOptions): IDislikeRequest {
return {
target: {
videoId: options.target.video_id
},
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,19 @@
import type { ILikeRequest, LikeEndpointOptions } from '../../../types/index.js';
export const PATH = '/like/like';
/**
* Builds a `/like/like` endpoint payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: LikeEndpointOptions): ILikeRequest {
return {
target: {
videoId: options.target.video_id
},
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,19 @@
import type { IRemoveLikeRequest, RemoveLikeEndpointOptions } from '../../../types/index.js';
export const PATH = '/like/removelike';
/**
* Builds a `/like/removelike` endpoint payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: RemoveLikeEndpointOptions): IRemoveLikeRequest {
return {
target: {
videoId: options.target.video_id
},
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,3 @@
export * as LikeEndpoint from './LikeEndpoint.js';
export * as DislikeEndpoint from './DislikeEndpoint.js';
export * as RemoveLikeEndpoint from './RemoveLikeEndpoint.js';

View File

@@ -0,0 +1,16 @@
import type { IMusicGetSearchSuggestionsRequest, MusicGetSearchSuggestionsEndpointOptions } from '../../../types/index.js';
export const PATH = '/music/get_search_suggestions';
/**
* Builds a `/music/get_search_suggestions` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: MusicGetSearchSuggestionsEndpointOptions): IMusicGetSearchSuggestionsRequest {
return {
input: opts.input,
client: 'YTMUSIC'
};
}

View File

@@ -0,0 +1 @@
export * as GetSearchSuggestionsEndpoint from './GetSearchSuggestionsEndpoint.js';

View File

@@ -0,0 +1 @@
export const PATH = '/notification/get_unseen_count';

View File

@@ -0,0 +1,17 @@
import type { IModifyChannelPreferenceRequest, ModifyChannelPreferenceEndpointOptions } from '../../../types/index.js';
export const PATH = '/notification/modify_channel_preference';
/**
* Builds a `/notification/modify_channel_preference` request payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: ModifyChannelPreferenceEndpointOptions): IModifyChannelPreferenceRequest {
return {
params: options.params,
...{
client: options.client
}
};
}

View File

@@ -0,0 +1,2 @@
export * as GetUnseenCountEndpoint from './GetUnseenCountEndpoint.js';
export * as ModifyChannelPreferenceEndpoint from './ModifyChannelPreferenceEndpoint.js';

View File

@@ -0,0 +1,15 @@
import type { ICreatePlaylistRequest, CreatePlaylistEndpointOptions } from '../../../types/index.js';
export const PATH = '/playlist/create';
/**
* Builds a `/playlist/create` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: CreatePlaylistEndpointOptions): ICreatePlaylistRequest {
return {
title: opts.title,
ids: opts.ids
};
}

View File

@@ -0,0 +1,14 @@
import type { IDeletePlaylistRequest, DeletePlaylistEndpointOptions } from '../../../types/index.js';
export const PATH = '/playlist/delete';
/**
* Builds a `/playlist/delete` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: DeletePlaylistEndpointOptions): IDeletePlaylistRequest {
return {
playlistId: opts.playlist_id
};
}

View File

@@ -0,0 +1,2 @@
export * as CreateEndpoint from './CreateEndpoint.js';
export * as DeleteEndpoint from './DeleteEndpoint.js';

View File

@@ -0,0 +1,18 @@
import type { ISubscribeRequest, SubscribeEndpointOptions } from '../../../types/index.js';
export const PATH = '/subscription/subscribe';
/**
* Builds a `/subscription/subscribe` endpoint payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: SubscribeEndpointOptions): ISubscribeRequest {
return {
channelIds: options.channel_ids,
...{
client: options.client,
params: options.params
}
};
}

View File

@@ -0,0 +1,18 @@
import type { IUnsubscribeRequest, UnsubscribeEndpointOptions } from '../../../types/index.js';
export const PATH = '/subscription/unsubscribe';
/**
* Builds a `/subscription/unsubscribe` endpoint payload.
* @param options - The options to use.
* @returns The payload.
*/
export function build(options: UnsubscribeEndpointOptions): IUnsubscribeRequest {
return {
channelIds: options.channel_ids,
...{
client: options.client,
params: options.params
}
};
}

View File

@@ -0,0 +1,2 @@
export * as SubscribeEndpoint from './SubscribeEndpoint.js';
export * as UnsubscribeEndpoint from './UnsubscribeEndpoint.js';

View File

@@ -0,0 +1,37 @@
import type { ICreateVideoRequest, CreateVideoEndpointOptions } from '../../../types/index.js';
export const PATH = '/upload/createvideo';
/**
* Builds a `/upload/createvideo` request payload.
* @param opts - The options to use.
* @returns The payload.
*/
export function build(opts: CreateVideoEndpointOptions): ICreateVideoRequest {
return {
resourceId: {
scottyResourceId: {
id: opts.resource_id.scotty_resource_id.id
}
},
frontendUploadId: opts.frontend_upload_id,
initialMetadata: {
title: {
newTitle: opts.initial_metadata.title.new_title
},
description: {
newDescription: opts.initial_metadata.description.new_description,
shouldSegment: opts.initial_metadata.description.should_segment
},
privacy: {
newPrivacy: opts.initial_metadata.privacy.new_privacy
},
draftState: {
isDraft: !!opts.initial_metadata.draft_state.is_draft
}
},
...{
client: opts.client
}
};
}

View File

@@ -0,0 +1 @@
export * as CreateVideoEndpoint from './CreateVideoEndpoint.js';

View File

@@ -1,38 +1,16 @@
export { default as AccountManager } from './AccountManager.js';
export * from './AccountManager.js';
export { default as Session } from './Session.js';
export * from './Session.js';
export { default as Actions } from './Actions.js';
export * from './Actions.js';
export { default as Feed } from './Feed.js';
export * from './Feed.js';
export { default as FilterableFeed } from './FilterableFeed.js';
export * from './FilterableFeed.js';
export { default as InteractionManager } from './InteractionManager.js';
export * from './InteractionManager.js';
export { default as Kids } from './Kids.js';
export * from './Kids.js';
export { default as Music } from './Music.js';
export * from './Music.js';
export { default as Player } from './Player.js';
export * from './Player.js';
export { default as OAuth } from './OAuth.js';
export * from './OAuth.js';
export { default as Player } from './Player.js';
export * from './Player.js';
export { default as PlaylistManager } from './PlaylistManager.js';
export * from './PlaylistManager.js';
export { default as Session } from './Session.js';
export * from './Session.js';
export { default as Studio } from './Studio.js';
export * from './Studio.js';
export { default as TabbedFeed } from './TabbedFeed.js';
export * from './TabbedFeed.js';
export * as Clients from './clients/index.js';
export * as Endpoints from './endpoints/index.js';
export * as Managers from './managers/index.js';
export * as Mixins from './mixins/index.js';

View File

@@ -1,15 +1,16 @@
import Proto from '../proto/index.js';
import type Actions from './Actions.js';
import type { ApiResponse } from './Actions.js';
import AccountInfo from '../../parser/youtube/AccountInfo.js';
import Analytics from '../../parser/youtube/Analytics.js';
import Settings from '../../parser/youtube/Settings.js';
import TimeWatched from '../../parser/youtube/TimeWatched.js';
import Analytics from '../parser/youtube/Analytics.js';
import TimeWatched from '../parser/youtube/TimeWatched.js';
import AccountInfo from '../parser/youtube/AccountInfo.js';
import Settings from '../parser/youtube/Settings.js';
import Proto from '../../proto/index.js';
import { InnertubeError } from '../../utils/Utils.js';
import { Account, BrowseEndpoint, Channel } from '../endpoints/index.js';
import { InnertubeError } from '../utils/Utils.js';
import type Actions from '../Actions.js';
import type { ApiResponse } from '../Actions.js';
class AccountManager {
export default class AccountManager {
#actions: Actions;
channel: {
@@ -30,10 +31,12 @@ class AccountManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
return this.#actions.execute('/channel/edit_name', {
givenName: new_name,
client: 'ANDROID'
});
return this.#actions.execute(
Channel.EditNameEndpoint.PATH,
Channel.EditNameEndpoint.build({
given_name: new_name
})
);
},
/**
* Edits channel description.
@@ -43,10 +46,12 @@ class AccountManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
return this.#actions.execute('/channel/edit_description', {
givenDescription: new_description,
client: 'ANDROID'
});
return this.#actions.execute(
Channel.EditDescriptionEndpoint.PATH,
Channel.EditDescriptionEndpoint.build({
given_description: new_description
})
);
},
/**
* Retrieves basic channel analytics.
@@ -62,7 +67,11 @@ class AccountManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const response = await this.#actions.execute('/account/accounts_list', { client: 'ANDROID' });
const response = await this.#actions.execute(
Account.AccountListEndpoint.PATH,
Account.AccountListEndpoint.build()
);
return new AccountInfo(response);
}
@@ -70,10 +79,12 @@ class AccountManager {
* Retrieves time watched statistics.
*/
async getTimeWatched(): Promise<TimeWatched> {
const response = await this.#actions.execute('/browse', {
browseId: 'SPtime_watched',
client: 'ANDROID'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'SPtime_watched',
client: 'ANDROID'
})
);
return new TimeWatched(response);
}
@@ -82,10 +93,11 @@ class AccountManager {
* Opens YouTube settings.
*/
async getSettings(): Promise<Settings> {
const response = await this.#actions.execute('/browse', {
browseId: 'SPaccount_overview'
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'SPaccount_overview'
})
);
return new Settings(this.#actions, response);
}
@@ -95,16 +107,14 @@ class AccountManager {
async getAnalytics(): Promise<Analytics> {
const info = await this.getInfo();
const params = Proto.encodeChannelAnalyticsParams(info.footers?.endpoint.payload.browseId);
const response = await this.#actions.execute('/browse', {
browseId: 'FEanalytics_screen',
client: 'ANDROID',
params
});
const response = await this.#actions.execute(
BrowseEndpoint.PATH, BrowseEndpoint.build({
browse_id: 'FEanalytics_screen',
params: Proto.encodeChannelAnalyticsParams(info.footers?.endpoint.payload.browseId),
client: 'ANDROID'
})
);
return new Analytics(response);
}
}
export default AccountManager;
}

View File

@@ -1,9 +1,14 @@
import Proto from '../proto/index.js';
import type Actions from './Actions.js';
import type { ApiResponse } from './Actions.js';
import { throwIfMissing } from '../utils/Utils.js';
import Proto from '../../proto/index.js';
import type Actions from '../Actions.js';
import type { ApiResponse } from '../Actions.js';
class InteractionManager {
import { throwIfMissing } from '../../utils/Utils.js';
import { LikeEndpoint, DislikeEndpoint, RemoveLikeEndpoint } from '../endpoints/like/index.js';
import { SubscribeEndpoint, UnsubscribeEndpoint } from '../endpoints/subscription/index.js';
import { CreateCommentEndpoint, PerformCommentActionEndpoint } from '../endpoints/comment/index.js';
import { ModifyChannelPreferenceEndpoint } from '../endpoints/notification/index.js';
export default class InteractionManager {
#actions: Actions;
constructor(actions: Actions) {
@@ -20,12 +25,12 @@ class InteractionManager {
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/like/like', {
client: 'ANDROID',
target: {
videoId: video_id
}
});
const action = await this.#actions.execute(
LikeEndpoint.PATH, LikeEndpoint.build({
client: 'ANDROID',
target: { video_id }
})
);
return action;
}
@@ -40,12 +45,12 @@ class InteractionManager {
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/like/dislike', {
client: 'ANDROID',
target: {
videoId: video_id
}
});
const action = await this.#actions.execute(
DislikeEndpoint.PATH, DislikeEndpoint.build({
client: 'ANDROID',
target: { video_id }
})
);
return action;
}
@@ -60,12 +65,12 @@ class InteractionManager {
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/like/removelike', {
client: 'ANDROID',
target: {
videoId: video_id
}
});
const action = await this.#actions.execute(
RemoveLikeEndpoint.PATH, RemoveLikeEndpoint.build({
client: 'ANDROID',
target: { video_id }
})
);
return action;
}
@@ -80,11 +85,13 @@ class InteractionManager {
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/subscription/subscribe', {
client: 'ANDROID',
channelIds: [ channel_id ],
params: 'EgIIAhgA'
});
const action = await this.#actions.execute(
SubscribeEndpoint.PATH, SubscribeEndpoint.build({
client: 'ANDROID',
channel_ids: [ channel_id ],
params: 'EgIIAhgA'
})
);
return action;
}
@@ -93,17 +100,19 @@ class InteractionManager {
* Unsubscribes from a given channel.
* @param channel_id - The channel ID
*/
async unsubscribe(channel_id: string): Promise<ApiResponse>{
async unsubscribe(channel_id: string): Promise<ApiResponse> {
throwIfMissing({ channel_id });
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/subscription/unsubscribe', {
client: 'ANDROID',
channelIds: [ channel_id ],
params: 'CgIIAhgA'
});
const action = await this.#actions.execute(
UnsubscribeEndpoint.PATH, UnsubscribeEndpoint.build({
client: 'ANDROID',
channel_ids: [ channel_id ],
params: 'CgIIAhgA'
})
);
return action;
}
@@ -119,11 +128,13 @@ class InteractionManager {
if (!this.#actions.session.logged_in)
throw new Error('You must be signed in to perform this operation.');
const action = await this.#actions.execute('/comment/create_comment', {
client: 'ANDROID',
commentText: text,
createCommentParams: Proto.encodeCommentParams(video_id)
});
const action = await this.#actions.execute(
CreateCommentEndpoint.PATH, CreateCommentEndpoint.build({
comment_text: text,
create_comment_params: Proto.encodeCommentParams(video_id),
client: 'ANDROID'
})
);
return action;
}
@@ -139,10 +150,12 @@ class InteractionManager {
const target_action = Proto.encodeCommentActionParams(22, { text, target_language, ...args });
const response = await this.#actions.execute('/comment/perform_comment_action', {
client: 'ANDROID',
actions: [ target_action ]
});
const response = await this.#actions.execute(
PerformCommentActionEndpoint.PATH, PerformCommentActionEndpoint.build({
client: 'ANDROID',
actions: [ target_action ]
})
);
const mutation = response.data.frameworkUpdates.entityBatchUpdate.mutations[0].payload.commentEntityPayload;
@@ -175,13 +188,13 @@ class InteractionManager {
if (!Object.keys(pref_types).includes(type.toUpperCase()))
throw new Error(`Invalid notification preference type: ${type}`);
const action = await this.#actions.execute('/notification/modify_channel_preference', {
client: 'WEB',
params: Proto.encodeNotificationPref(channel_id, pref_types[type.toUpperCase() as keyof typeof pref_types])
});
const action = await this.#actions.execute(
ModifyChannelPreferenceEndpoint.PATH, ModifyChannelPreferenceEndpoint.build({
client: 'WEB',
params: Proto.encodeNotificationPref(channel_id, pref_types[type.toUpperCase() as keyof typeof pref_types])
})
);
return action;
}
}
export default InteractionManager;
}

View File

@@ -1,10 +1,14 @@
import type Feed from './Feed.js';
import type Actions from './Actions.js';
import Playlist from '../parser/youtube/Playlist.js';
import Playlist from '../../parser/youtube/Playlist.js';
import type Actions from '../Actions.js';
import type Feed from '../mixins/Feed.js';
import { InnertubeError, throwIfMissing } from '../utils/Utils.js';
import type { EditPlaylistEndpointOptions } from '../../types/index.js';
import { InnertubeError, throwIfMissing } from '../../utils/Utils.js';
import { EditPlaylistEndpoint } from '../endpoints/browse/index.js';
import { BrowseEndpoint } from '../endpoints/index.js';
import { CreateEndpoint, DeleteEndpoint } from '../endpoints/playlist/index.js';
class PlaylistManager {
export default class PlaylistManager {
#actions: Actions;
constructor(actions: Actions) {
@@ -22,11 +26,12 @@ class PlaylistManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const response = await this.#actions.execute('/playlist/create', {
title,
ids: video_ids,
parse: false
});
const response = await this.#actions.execute(
CreateEndpoint.PATH, CreateEndpoint.build({
ids: video_ids,
title
})
);
return {
success: response.success,
@@ -46,7 +51,11 @@ class PlaylistManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const response = await this.#actions.execute('playlist/delete', { playlistId: playlist_id });
const response = await this.#actions.execute(
DeleteEndpoint.PATH, DeleteEndpoint.build({
playlist_id
})
);
return {
playlist_id,
@@ -67,14 +76,15 @@ class PlaylistManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const response = await this.#actions.execute('/browse/edit_playlist', {
playlistId: playlist_id,
actions: video_ids.map((id) => ({
action: 'ACTION_ADD_VIDEO',
addedVideoId: id
})),
parse: false
});
const response = await this.#actions.execute(
EditPlaylistEndpoint.PATH, EditPlaylistEndpoint.build({
actions: video_ids.map((id) => ({
action: 'ACTION_ADD_VIDEO',
added_video_id: id
})),
playlist_id
})
);
return {
playlist_id,
@@ -93,23 +103,16 @@ class PlaylistManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const info = await this.#actions.execute('/browse', {
browseId: `VL${playlist_id}`,
parse: true
});
const info = await this.#actions.execute(
BrowseEndpoint.PATH, { ...BrowseEndpoint.build({ browse_id: `VL${playlist_id}` }), parse: true }
);
const playlist = new Playlist(this.#actions, info, true);
if (!playlist.info.is_editable)
throw new InnertubeError('This playlist cannot be edited.', playlist_id);
const payload = {
playlistId: playlist_id,
actions: [] as {
action: string;
setVideoId: string;
}[]
};
const payload: EditPlaylistEndpointOptions = { playlist_id, actions: [] };
const getSetVideoIds = async (pl: Feed): Promise<void> => {
const videos = pl.videos.filter((video) => video_ids.includes(video.key('id').string()));
@@ -117,7 +120,7 @@ class PlaylistManager {
videos.forEach((video) =>
payload.actions.push({
action: 'ACTION_REMOVE_VIDEO',
setVideoId: video.key('set_video_id').string()
set_video_id: video.key('set_video_id').string()
})
);
@@ -132,7 +135,9 @@ class PlaylistManager {
if (!payload.actions.length)
throw new InnertubeError('Given video ids were not found in this playlist.', video_ids);
const response = await this.#actions.execute('/browse/edit_playlist', { ...payload, parse: false });
const response = await this.#actions.execute(
EditPlaylistEndpoint.PATH, EditPlaylistEndpoint.build(payload)
);
return {
playlist_id,
@@ -152,24 +157,16 @@ class PlaylistManager {
if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');
const info = await this.#actions.execute('/browse', {
browseId: `VL${playlist_id}`,
parse: true
});
const info = await this.#actions.execute(
BrowseEndpoint.PATH, { ...BrowseEndpoint.build({ browse_id: `VL${playlist_id}` }), parse: true }
);
const playlist = new Playlist(this.#actions, info, true);
if (!playlist.info.is_editable)
throw new InnertubeError('This playlist cannot be edited.', playlist_id);
const payload = {
playlistId: playlist_id,
actions: [] as {
action: string,
setVideoId?: string,
movedSetVideoIdPredecessor?: string
}[]
};
const payload: EditPlaylistEndpointOptions = { playlist_id, actions: [] };
let set_video_id_0: string | undefined, set_video_id_1: string | undefined;
@@ -190,20 +187,17 @@ class PlaylistManager {
payload.actions.push({
action: 'ACTION_MOVE_VIDEO_AFTER',
setVideoId: set_video_id_0,
movedSetVideoIdPredecessor: set_video_id_1
set_video_id: set_video_id_0,
moved_set_video_id_predecessor: set_video_id_1
});
const response = await this.#actions.execute('/browse/edit_playlist', {
...payload,
parse: false
});
const response = await this.#actions.execute(
EditPlaylistEndpoint.PATH, EditPlaylistEndpoint.build(payload)
);
return {
playlist_id,
action_result: response.data.actions // TODO: implement actions in the parser
};
}
}
export default PlaylistManager;
}

View File

@@ -0,0 +1,3 @@
export { default as AccountManager } from './AccountManager.js';
export { default as PlaylistManager } from './PlaylistManager.js';
export { default as InteractionManager } from './InteractionManager.js';

View File

@@ -1,39 +1,40 @@
import type { Memo, ObservedArray, SuperParsedResult, YTNode } from '../parser/helpers.js';
import Parser, { ReloadContinuationItemsCommand } from '../parser/index.js';
import { concatMemos, InnertubeError } from '../utils/Utils.js';
import type Actions from './Actions.js';
import type { Memo, ObservedArray, SuperParsedResult, YTNode } from '../../parser/helpers.js';
import Parser, { ReloadContinuationItemsCommand } from '../../parser/index.js';
import { concatMemos, InnertubeError } from '../../utils/Utils.js';
import type Actions from '../Actions.js';
import BackstagePost from '../parser/classes/BackstagePost.js';
import Channel from '../parser/classes/Channel.js';
import CompactVideo from '../parser/classes/CompactVideo.js';
import GridChannel from '../parser/classes/GridChannel.js';
import GridPlaylist from '../parser/classes/GridPlaylist.js';
import GridVideo from '../parser/classes/GridVideo.js';
import Playlist from '../parser/classes/Playlist.js';
import PlaylistPanelVideo from '../parser/classes/PlaylistPanelVideo.js';
import PlaylistVideo from '../parser/classes/PlaylistVideo.js';
import Post from '../parser/classes/Post.js';
import ReelItem from '../parser/classes/ReelItem.js';
import ReelShelf from '../parser/classes/ReelShelf.js';
import RichShelf from '../parser/classes/RichShelf.js';
import Shelf from '../parser/classes/Shelf.js';
import Tab from '../parser/classes/Tab.js';
import Video from '../parser/classes/Video.js';
import BackstagePost from '../../parser/classes/BackstagePost.js';
import SharedPost from '../../parser/classes/SharedPost.js';
import Channel from '../../parser/classes/Channel.js';
import CompactVideo from '../../parser/classes/CompactVideo.js';
import GridChannel from '../../parser/classes/GridChannel.js';
import GridPlaylist from '../../parser/classes/GridPlaylist.js';
import GridVideo from '../../parser/classes/GridVideo.js';
import Playlist from '../../parser/classes/Playlist.js';
import PlaylistPanelVideo from '../../parser/classes/PlaylistPanelVideo.js';
import PlaylistVideo from '../../parser/classes/PlaylistVideo.js';
import Post from '../../parser/classes/Post.js';
import ReelItem from '../../parser/classes/ReelItem.js';
import ReelShelf from '../../parser/classes/ReelShelf.js';
import RichShelf from '../../parser/classes/RichShelf.js';
import Shelf from '../../parser/classes/Shelf.js';
import Tab from '../../parser/classes/Tab.js';
import Video from '../../parser/classes/Video.js';
import AppendContinuationItemsAction from '../parser/classes/actions/AppendContinuationItemsAction.js';
import ContinuationItem from '../parser/classes/ContinuationItem.js';
import TwoColumnBrowseResults from '../parser/classes/TwoColumnBrowseResults.js';
import TwoColumnSearchResults from '../parser/classes/TwoColumnSearchResults.js';
import WatchCardCompactVideo from '../parser/classes/WatchCardCompactVideo.js';
import AppendContinuationItemsAction from '../../parser/classes/actions/AppendContinuationItemsAction.js';
import ContinuationItem from '../../parser/classes/ContinuationItem.js';
import TwoColumnBrowseResults from '../../parser/classes/TwoColumnBrowseResults.js';
import TwoColumnSearchResults from '../../parser/classes/TwoColumnSearchResults.js';
import WatchCardCompactVideo from '../../parser/classes/WatchCardCompactVideo.js';
import type MusicQueue from '../parser/classes/MusicQueue.js';
import type RichGrid from '../parser/classes/RichGrid.js';
import type SectionList from '../parser/classes/SectionList.js';
import type MusicQueue from '../../parser/classes/MusicQueue.js';
import type RichGrid from '../../parser/classes/RichGrid.js';
import type SectionList from '../../parser/classes/SectionList.js';
import type { IParsedResponse } from '../parser/types/index.js';
import type { ApiResponse } from './Actions.js';
import type { IParsedResponse } from '../../parser/types/index.js';
import type { ApiResponse } from '../Actions.js';
class Feed<T extends IParsedResponse = IParsedResponse> {
export default class Feed<T extends IParsedResponse = IParsedResponse> {
#page: T;
#continuation?: ObservedArray<ContinuationItem>;
#actions: Actions;
@@ -71,7 +72,7 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
* Get all videos on a given page via memo
*/
static getVideosFromMemo(memo: Memo) {
return memo.getType<Video | GridVideo | ReelItem | CompactVideo | PlaylistVideo | PlaylistPanelVideo | WatchCardCompactVideo>([
return memo.getType(
Video,
GridVideo,
ReelItem,
@@ -79,14 +80,14 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
PlaylistVideo,
PlaylistPanelVideo,
WatchCardCompactVideo
]);
);
}
/**
* Get all playlists on a given page via memo
*/
static getPlaylistsFromMemo(memo: Memo) {
return memo.getType<Playlist | GridPlaylist>([ Playlist, GridPlaylist ]);
return memo.getType(Playlist, GridPlaylist);
}
/**
@@ -100,14 +101,14 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
* Get all the community posts in the feed
*/
get posts() {
return this.#memo.getType<Post | BackstagePost>([ BackstagePost, Post ]);
return this.#memo.getType(BackstagePost, Post, SharedPost);
}
/**
* Get all the channels in the feed
*/
get channels() {
return this.#memo.getType<Channel | GridChannel>([ Channel, GridChannel ]);
return this.#memo.getType(Channel, GridChannel);
}
/**
@@ -136,7 +137,7 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
* Returns all segments/sections from the page.
*/
get shelves() {
return this.#memo.getType<Shelf | RichShelf | ReelShelf>([ Shelf, RichShelf, ReelShelf ]);
return this.#memo.getType(Shelf, RichShelf, ReelShelf);
}
/**
@@ -209,6 +210,4 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
throw new InnertubeError('Could not get continuation data');
return new Feed<T>(this.actions, continuation_data, true);
}
}
export default Feed;
}

View File

@@ -1,14 +1,14 @@
import ChipCloudChip from '../parser/classes/ChipCloudChip.js';
import FeedFilterChipBar from '../parser/classes/FeedFilterChipBar.js';
import { InnertubeError } from '../utils/Utils.js';
import ChipCloudChip from '../../parser/classes/ChipCloudChip.js';
import FeedFilterChipBar from '../../parser/classes/FeedFilterChipBar.js';
import { InnertubeError } from '../../utils/Utils.js';
import Feed from './Feed.js';
import type { ObservedArray } from '../parser/helpers.js';
import type { IParsedResponse } from '../parser/types/ParsedResponse.js';
import type Actions from './Actions.js';
import type { ApiResponse } from './Actions.js';
import type { ObservedArray } from '../../parser/helpers.js';
import type { IParsedResponse } from '../../parser/types/ParsedResponse.js';
import type Actions from '../Actions.js';
import type { ApiResponse } from '../Actions.js';
class FilterableFeed<T extends IParsedResponse> extends Feed<T> {
export default class FilterableFeed<T extends IParsedResponse> extends Feed<T> {
#chips?: ObservedArray<ChipCloudChip>;
constructor(actions: Actions, data: ApiResponse | T, already_parsed = false) {
@@ -69,6 +69,4 @@ class FilterableFeed<T extends IParsedResponse> extends Feed<T> {
return new Feed(this.actions, response, true);
}
}
export default FilterableFeed;
}

View File

@@ -0,0 +1,106 @@
import type { ApiResponse } from '../Actions.js';
import type Actions from '../Actions.js';
import * as Constants from '../../utils/Constants.js';
import type { DownloadOptions, FormatFilter, FormatOptions, URLTransformer } from '../../utils/FormatUtils.js';
import FormatUtils from '../../utils/FormatUtils.js';
import { InnertubeError } from '../../utils/Utils.js';
import type Format from '../../parser/classes/misc/Format.js';
import type { INextResponse, IPlayerResponse } from '../../parser/index.js';
import Parser from '../../parser/index.js';
export default class MediaInfo {
#page: [IPlayerResponse, INextResponse?];
#actions: Actions;
#cpn: string;
#playback_tracking;
streaming_data;
playability_status;
constructor(data: [ApiResponse, ApiResponse?], actions: Actions, cpn: string) {
this.#actions = actions;
const info = Parser.parseResponse<IPlayerResponse>(data[0].data);
const next = data?.[1]?.data ? Parser.parseResponse<INextResponse>(data[1].data) : undefined;
this.#page = [ info, next ];
this.#cpn = cpn;
if (info.playability_status?.status === 'ERROR')
throw new InnertubeError('This video is unavailable', info.playability_status);
this.streaming_data = info.streaming_data;
this.playability_status = info.playability_status;
this.#playback_tracking = info.playback_tracking;
}
/**
* Generates a DASH manifest from the streaming data.
* @param url_transformer - Function to transform the URLs.
* @param format_filter - Function to filter the formats.
* @returns DASH manifest
*/
async toDash(url_transformer?: URLTransformer, format_filter?: FormatFilter): Promise<string> {
return FormatUtils.toDash(this.streaming_data, url_transformer, format_filter, this.#cpn, this.#actions.session.player, this.#actions);
}
/**
* Selects the format that best matches the given options.
* @param options - Options
*/
chooseFormat(options: FormatOptions): Format {
return FormatUtils.chooseFormat(options, this.streaming_data);
}
/**
* Downloads the video.
* @param options - Download options.
*/
async download(options: DownloadOptions = {}): Promise<ReadableStream<Uint8Array>> {
return FormatUtils.download(options, this.#actions, this.playability_status, this.streaming_data, this.#actions.session.player, this.cpn);
}
/**
* Adds video to the watch history.
*/
async addToWatchHistory(client_name = Constants.CLIENTS.WEB.NAME, client_version = Constants.CLIENTS.WEB.VERSION, replacement = 'https://www.'): Promise<Response> {
if (!this.#playback_tracking)
throw new InnertubeError('Playback tracking not available');
const url_params = {
cpn: this.#cpn,
fmt: 251,
rtn: 0,
rt: 0
};
const url = this.#playback_tracking.videostats_playback_url.replace('https://s.', replacement);
const response = await this.#actions.stats(url, {
client_name,
client_version
}, url_params);
return response;
}
/**
* Actions instance.
*/
get actions(): Actions {
return this.#actions;
}
/**
* Content Playback Nonce.
*/
get cpn(): string {
return this.#cpn;
}
/**
* Original parsed InnerTube response.
*/
get page(): [IPlayerResponse, INextResponse?] {
return this.#page;
}
}

View File

@@ -1,13 +1,13 @@
import Tab from '../parser/classes/Tab.js';
import Tab from '../../parser/classes/Tab.js';
import Feed from './Feed.js';
import { InnertubeError } from '../utils/Utils.js';
import { InnertubeError } from '../../utils/Utils.js';
import type Actions from './Actions.js';
import type { ObservedArray } from '../parser/helpers.js';
import type { IParsedResponse } from '../parser/types/ParsedResponse.js';
import type { ApiResponse } from './Actions.js';
import type Actions from '../Actions.js';
import type { ObservedArray } from '../../parser/helpers.js';
import type { IParsedResponse } from '../../parser/types/ParsedResponse.js';
import type { ApiResponse } from '../Actions.js';
class TabbedFeed<T extends IParsedResponse> extends Feed<T> {
export default class TabbedFeed<T extends IParsedResponse> extends Feed<T> {
#tabs?: ObservedArray<Tab>;
#actions: Actions;
@@ -56,6 +56,4 @@ class TabbedFeed<T extends IParsedResponse> extends Feed<T> {
get title(): string | undefined {
return this.page.contents_memo?.getType(Tab)?.find((tab) => tab.selected)?.title.toString();
}
}
export default TabbedFeed;
}

4
src/core/mixins/index.ts Normal file
View File

@@ -0,0 +1,4 @@
export { default as Feed } from './Feed.js';
export { default as FilterableFeed } from './FilterableFeed.js';
export { default as TabbedFeed } from './TabbedFeed.js';
export { default as MediaInfo } from './MediaInfo.js';

View File

@@ -1,38 +1,46 @@
# Parser
Sanitizes and standardizes InnerTube responses while maintaining the integrity of the data.
Structure:
* [`/classes`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/classes) - InnerTube nodes.
* [`/types`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/types) - General response types.
* [`/youtube`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/youtube) - Contains the logic for parsing YouTube responses.
* [`/ytmusic`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/ytmusic) - Contains the logic for parsing YouTube Music responses.
* [`/ytkids`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/ytkids) - Contains the logic for parsing YouTube Kids responses.
* [`helpers.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/helpers.ts) - Helper functions/classes for the parser.
* [`parser.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/parser.ts) - The core of the parser.
* [`map.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/map.ts) - A list of all InnerTube nodes, it is used to determine which node to use for a given renderer. Note that this file is auto-generated and should not be edited manually.
The parser is responsible for sanitizing and standardizing InnerTube responses while preserving the integrity of the data.
## Table of Contents
<ol>
<li>
<a href="#api">API</a>
</li>
<li>
<a href="#usage">Usage</a>
<ul>
<li><a href="#observedarray">ObservedArray</a></li>
<li><a href="#superparsedresponse">SuperParsedResponse</a></li>
<li><a href="#ytnode">YTNode</a></li>
<li><a href="#memo">Memo</a></li>
</ul>
</li>
<li><a href="#adding-new-nodes">Adding new nodes</a></li>
<li><a href="#how-it-works">How it works</a></li>
</ol>
- [Parser](#parser)
- [Table of Contents](#table-of-contents)
- [Structure](#structure)
- [Core](#core)
- [Clients](#clients)
- [API](#api)
- [`parse(data?: RawData, requireArray?: boolean, validTypes?: YTNodeConstructor<T> | YTNodeConstructor<T>[])`](#parsedata-rawdata-requirearray-boolean-validtypes-ytnodeconstructort--ytnodeconstructort)
- [`parseResponse(data: IRawResponse): T`](#parseresponsedata-irawresponse-t)
- [Usage](#usage)
- [ObservedArray](#observedarray)
- [SuperParsedResponse](#superparsedresponse)
- [YTNode](#ytnode)
- [Type Casting](#type-casting)
- [Accessing properties without casting](#accessing-properties-without-casting)
- [Memo](#memo)
- [Adding new nodes](#adding-new-nodes)
- [Generating nodes at runtime](#generating-nodes-at-runtime)
- [How it works](#how-it-works)
___
## Structure
### Core
* [`/types`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/types) - General response types.
* [`/classes`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/classes) - InnerTube nodes.
* [`generator.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/generator.ts) - Used to generate missing nodes at runtime.
* [`helpers.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/helpers.ts) - Helper functions/classes for the parser.
* [`parser.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/parser.ts) - The core of the parser.
* [`nodes.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/nodes.ts) - Contains a list of all the InnerTube nodes, which is used to determine the appropriate node for a given renderer. It's important to note that this file is automatically generated and should not be edited manually.
* [`misc.ts`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/misc.ts) - Miscellaneous classes. Also automatically generated.
### Clients
The parser itself is not tied to any specific client. Therefore, we have a separate folder for each client that the library supports. These folders are responsible for arranging the parsed data into a format that can be easily consumed and understood. Additionally, the underlying data is also exposed for those who wish to access it.
* [`/youtube`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/youtube)
* [`/ytmusic`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/ytmusic)
* [`/ytkids`](https://github.com/LuanRT/YouTube.js/blob/main/src/parser/ytkids)
## API
@@ -44,86 +52,82 @@ ___
<a name="parse"></a>
#### parse(data, requireArray, validTypes)
### `parse(data?: RawData, requireArray?: boolean, validTypes?: YTNodeConstructor<T> | YTNodeConstructor<T>[])`
Responsible for parsing individual nodes.
| Param | Type | Description |
| --- | --- | --- |
| data | `any` | The data |
| data | `RawData` | The data to parse |
| requireArray | `?boolean` | Whether the response should be an array |
| validTypes | `YTNodeConstructor<T> \| YTNodeConstructor<T>[] \| undefined` | Types of `YTNode` allowed |
When `requireArray` is `true`, the response will be an `ObservedArray<YTNodes>`.
- If `requireArray` is `true`, the response will be an `ObservedArray<YTNodes>`.
- If `validTypes` is `undefined`, the response will be an array of YTNodes.
- If `validTypes` is an array, the response will be an array of YTNodes that are of the types specified in the array.
- If `validTypes` is a single type, the response will be an array of YTNodes that are of the type specified.
When `validTypes` is `undefined`, the response will be an array of YTNodes.
When `validTypes` is an array, the response will be an array of YTNodes that are of the types specified in the array.
When `validTypes` is a single type, the response will be an array of YTNodes that are of the type specified.
If you do not specify `requireArray`, the return type of the function will not be known at runtime, and therefore we return the response wrapped in a helper, `SuperParsedResponse`, to gain access to the response.
If you do not specify `requireArray`, the return type of the function will not be known at runtime. Therefore, to gain access to the response, we return it wrapped in a helper, `SuperParsedResponse`.
You may use the `Parser#parseArray` and `Parser#parseItem` methods to parse the response in a deterministic way.
<a name="parseresponse"></a>
#### parseResponse(data)
### `parseResponse(data: IRawResponse): T`
Unlike `parse`, this can be used to parse the entire response object.
| Param | Type | Description |
| --- | --- | --- |
| data | `object` | Raw InnerTube response |
| data | `IRawResponse` | Raw InnerTube response |
## Usage
## ObservedArray
You may use `ObservedArray<T extends YTNode>` as a normal array, but it provides additional methods for typesafe access and casting.
### ObservedArray
You can utilize an `ObservedArray<T extends YTNode>` as a regular array, but it also offers further methods for accessing and casting values in a type-safe manner.
```ts
// For example, we have a feed, and want all the videos:
const feed = new ObservedArray<YTNode>([...feed.contents]);
const videos = feed.filterType(GridVideo);
// This is now a GridVideo[]
// Or we want only the first video:
// Here, we use the filterType method to retrieve only GridVideo items from the feed.
const videos = feed.filterType(GridVideo);
// `videos` is now a GridVideo[] array.
// Alternatively, we can use firstOfType to retrieve the first GridVideo item from the feed.
const firstVideo = feed.firstOfType(GridVideo);
// We may cast the whole array to a GridVideo[] and throw if we have any non-GridVideo elements:
// If we want to make sure that all elements in the `feed` array are of the `GridVideo` type, we can use the `as` method to cast the entire array to a `GridVideo[]` type. If the cast fails because of non-GridVideo items, an exception is thrown.
const allVideos = feed.as(GridVideo);
// There are some extra methods for ObservedArray<T extends YTNode>
// which we use internally but not documented here (yet).
// see the source code for more details.
// Note that ObservedArray provides additional methods beyond what's shown here, which we use internally. For more information, see the source code or documentation.
```
## SuperParsedResponse
Represents a parsed response in an unknown state. Either a `YTNode` or an `ObservedArray<YTNode>` or `null`.
You will need to assert the type and unwrap the response to get the actual value.
### SuperParsedResponse
Represents a parsed response in an unknown state. Either a `YTNode`, an `ObservedArray<YTNode>`, or `null`. To extract the actual value, you must first assert the type and unwrap the response.
```ts
// We can assert we have a YTNode:
// First, parse the data and store it in `response`.
const response = Parser.parse(data);
// Check whether `response` is a YTNode.
if (response.is_item) {
// If so, we can assert that it is a YTNode and retrieve it.
const node = response.item();
}
// We can assert we have an ObservedArray<YTNode>:
const response = Parser.parse(data);
// Check whether `response` is an ObservedArray<YTNode>.
if (response.is_array) {
// If so, we can assert that it is an ObservedArray<YTNode> and retrieve its contents as an array of YTNode objects.
const nodes = response.array();
}
// Or lastly a null response:
const response = Parser.parse(data);
// Finally, to check if `response` is a null value, use the `is_null` getter.
const is_null = response.is_null;
```
## YTNode
All renderers returned by InnerTube are converted to this generic class and then extended for the specific renderers.
This class is what allows us a typesafe way to use data returned by the InnerTube API.
### YTNode
All renderers returned by InnerTube are converted to this generic class and then extended for the specific renderers. This class is what allows us a type-safe way to use data returned by the InnerTube API.
Here's how to use this class to access returned data:
@@ -131,10 +135,10 @@ Here's how to use this class to access returned data:
```ts
// We can cast a YTNode to a child class of YTNode
const results = node.as(TwoColumnSearchResults);
// This will throw if the node is not a TwoColumnSearchResults
// We thus may want to check for the type of the node before casting
// This will throw an error if the node is not a TwoColumnSearchResults.
// Therefore, we may want to check for the type of the node before casting.
if (node.is(TwoColumnSearchResults)) {
// We do not need to recast the node, it is already a TwoColumnSearchResults after calling is() and using it in the branch where is() returns true
// We do not need to recast the node; it is already a TwoColumnSearchResults after calling is() and using it in the branch where is() returns true.
const results = node;
}
@@ -144,21 +148,20 @@ const results = node.as(TwoColumnSearchResults, VideoList);
// Similarly, we can check if the node is of a certain type.
if (node.is(TwoColumnSearchResults, VideoList)) {
// Again no casting is needed, the node is already of the correct type.
// // Again, no casting is needed; the node is already of the correct type.
const results = node;
}
```
### Accessing properties without casting
Sometimes multiple nodes have the same properties and we don't want to check the type of the node before accessing the property, for example, the property "contents" is used by many node types, and we may add more in the future, as such we want to only assert the property instead of casting to a specific type.
Sometimes multiple nodes have the same properties, and we don't want to check the type of the node before accessing the property. For example, the property 'contents' is used by many node types, and we may add more in the future. As such, we want to only assert the property instead of casting to a specific type.
```ts
// Accessing a property on a node which you aren't sure if it exists.
// Accessing a property on a node when you aren't sure if it exists.
const prop = node.key("contents");
// This returns the value wrapped into a `Maybe` type
// which you can use to find the type of the value
// note, however, this throws an error if the key doesn't exist
// we may want to check for the key before accessing it.
// This returns the value wrapped into a `Maybe` type, which you can use to determine the type of the value.
// However, this throws an error if the key doesn't exist, so we may want to check for the key before accessing it.
if (node.hasKey("contents")) {
const prop = node.key("contents");
}
@@ -169,19 +172,18 @@ if (prop.isString()) {
const value = prop.string();
}
// We can do more complex assertions too,
// like checking for instanceof.
// We can do more complex assertions, like checking for instanceof.
const prop = node.key("contents");
if (prop.isInstanceof(Text)) {
const text = prop.instanceof(Text);
// and then use the value as the given type
if (prop.isInstanceOf(Text)) {
const text = prop.instanceOf(Text);
// Then use the value as the given type.
text.runs.forEach(run => {
console.log(run.text);
});
}
// There are some special methods for using with the parser
// such as getting the value as a YTNode.
// There are special methods for use with the parser, such as getting the value as a YTNode.
const prop = node.key("contents");
if (prop.isNode()) {
const node = prop.node();
@@ -200,13 +202,12 @@ if (prop.isNodeOfType([TwoColumnSearchResults, VideoList])) {
}
// Sometimes an ObservedArray is returned when working with parsed data.
// We've got a helper for that too;
// We also have a helper for this.
const prop = node.key("contents");
if (prop.isObserved()) {
const array = prop.observed();
// Now we may use all the ObservedArray methods as normal,
// like finding nodes of a certain type for example.
// Now we can use all the ObservedArray methods as normal, such as finding nodes of a certain type.
const results = array.filterType(GridVideo);
}
@@ -215,8 +216,8 @@ const prop = node.key("contents");
if (prop.isParsed()) {
const result = prop.parsed();
// SuperParsedResult is another helper for typesafe access to the parsed data,
// it is explained above with the `Parser#parse` method.
// SuperParsedResult is another helper for type-safe access to the parsed data.
// It is explained above with the `Parser#parse` method.
const results = results.array();
const videos = results.filterType(Video);
}
@@ -226,51 +227,106 @@ if (prop.isParsed()) {
const prop = node.key("contents");
const value = prop.any();
// Arrays are also a special case as every element may be of a different type,
// the `arrayOfMaybe` method will return an array of `Maybe`s.
// Arrays are a special case, as every element may be of a different type.
// The `arrayOfMaybe` method will return an array of `Maybe`s.
const prop = node.key("contents");
if (prop.isArray()) {
const array = prop.arrayOfMaybe();
// This will return Maybe[]
// This will return `Maybe[]`.
}
// Or if you want zero type safety you can use the `array` method.
// Or, if you don't need type safety, you can use the `array` method.
const prop = node.key("contents");
if (prop.isArray()) {
const array = prop.array();
// This will return any[]
// This will return any[].
}
```
## Memo
The `Memo` class is a helper class for memoizing values in the `Parser#parseResponse` method. It is useful for finding nodes after parsing the response.
### Memo
The `Memo` class is a helper class for memoizing values in the `Parser#parseResponse` method. It can be used to conveniently access nodes after parsing the response.
Say we want all of the videos in a search result. We can use the `Memo` to find all of them quickly without recursing through the response.
For example, if we'd like to obtain all of the videos from a search result, we can use the `Memo#getType` method to find them quickly without needing to traverse the entire response.
```ts
const response = Parser.parseResponse(data);
const videos = response.contents_memo.getType(Video);
// This returns the nodes as a ObservedArray<Video>.
// This returns the nodes as an `ObservedArray<Video>`.
```
`Memo` extends `Map<string, YTNode[]>` and can be used as a normal `Map` too if you want.
`Memo` extends `Map<string, YTNode[]>` and can be used as a regular `Map` if desired.
## Adding new nodes
Instructions can be found [here](https://github.com/LuanRT/YouTube.js/blob/main/docs/updating-the-parser.md).
## Generating nodes at runtime
YouTube constantly updates their client, and sometimes they add new nodes to the response. The parser needs to know about these new nodes in order to parse them correctly. Once a new node is dicovered by the parser, it will attempt to generate a new node class for it.
Using the existing `YTNode` class, you may interact with these new nodes in a type-safe way. However, you will not be able to cast them to the node's specific type, as this requires the node to be defined at compile-time.
The current implementation recognises the following values:
- Renderers
- Renderer arrays
- Text
- Navigation endpoints
- Author (does not currently detect the author thumbnails)
- Thumbnails
- Objects (key-value pairs)
- Primatives (string, number, boolean, etc.)
This may be expanded in the future.
At runtime, these JIT-generated nodes will revalidate themselves when constructed so that when the types change, the node will be re-generated.
To access these nodes that have been generated at runtime, you may use the `Parser.getParserByName(name: string)` method. You may also check if a parser has been generated for a node by using the `Parser.hasParser(name: string)` method.
```ts
import { Parser } from "youtubei.js";
// We may check if we have a parser for a node.
if (Parser.hasParser('Example')) {
// Then retrieve it.
const Example = Parser.getParserByName('Example');
// We may then use the parser as normal.
const example = new Example(data);
}
```
You may also generate your own nodes ahead of time, given you have an example of one of the nodes.
```ts
import { Generator } from "youtubei.js";
// Provided you have an example of the node `Example`
const example_data = {
"title": {
"runs": [
{
"text": "Example"
}
]
}
}
// The first argument is the name of the class, the second is the data you have for the node.
// It will return a class that extends YTNode.
const Example = Generator.YTNodeGenerator.generateRuntimeClass('Example', example_data);
// You may now use this class as you would any other node.
const example = new Example(example_data);
const title = example.key('title').instanceof(Text).toString();
```
## How it works
If you decompile a YouTube client and analyze it for a while you will notice that it has classes named `protos/youtube/api/innertube/MusicItemRenderer`, `protos/youtube/api/innertube/SectionListRenderer`, etc.
If you decompile a YouTube client and analyze it, it becomes apparent that it uses classes such as `../youtube/api/innertube/MusicItemRenderer` and `../youtube/api/innertube/SectionListRenderer` to parse objects from the response, map them into models, and generate the UI. The website operates similarly, but instead uses plain JSON. You can think of renderers as components in a web framework.
These classes are used to parse objects from the response, map them into models and generate the UI. The website works similarly, the difference is that it uses plain JSON (likely converted from protobuf server-side, hence the weird structure of the response).
Our approach is similar to YouTube's: our parser goes through all the renderers and parses their inner element(s). The final result is a nicely structured JSON, it even parses navigation endpoints, which allow us to make an API call with all required parameters in one line and emulate client actions, such as clicking a button.
Here we're taking a similar approach, the parser goes through all the renderers and parses their inner element(s). The final result is a nicely structured JSON, and on top of that, it also parses navigation endpoints which allow us to make an API call with all required parameters in one line and even emulate client actions (eg; clicking a button).
Here is your average, arguably ugly InnerTube response:
<details>
<summary>Click to see</summary>
<p>
To illustrate the transformation we make, let's take an unstructured InnerTube response and parse it into a cleaner format:
Raw InnerTube Response:
```js
{
sidebar: {
@@ -309,14 +365,7 @@ Here is your average, arguably ugly InnerTube response:
}
```
</p>
</details>
And what we get after parsing it:
<details>
<summary>Click to see</summary>
<p>
Clean Parsed Response:
```js
{
sidebar: {
@@ -324,21 +373,28 @@ And what we get after parsing it:
contents: [
{
type: 'PlaylistSidebarPrimaryInfo',
title: { text: '..' },
description: { text: '..' },
title: { text: '..', runs: [ { text: '..' } ] },
description: { text: '..', runs: [ { text: '..' } ] },
stats: [
{
text: '..'
text: '..',
runs: [
{
text: '..'
}
]
},
{
text: '..'
text: '..',
runs: [
{
text: '..'
}
]
}
]
}
]
}
}
```
</p>
</details>
```

View File

@@ -1,18 +1,17 @@
import Text from './misc/Text.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class AccountChannel extends YTNode {
export default class AccountChannel extends YTNode {
static type = 'AccountChannel';
title: Text;
endpoint: NavigationEndpoint;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
}
}
export default AccountChannel;
}

View File

@@ -1,13 +1,16 @@
import Parser from '../index.js';
import AccountItemSectionHeader from './AccountItemSectionHeader.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import AccountItemSectionHeader from './AccountItemSectionHeader.js';
import { YTNode } from '../helpers.js';
import { YTNode, observe, type ObservedArray } from '../helpers.js';
import type { RawNode } from '../index.js';
class AccountItem {
/**
* Not a real renderer but we treat it as one to keep things organized.
*/
export class AccountItem extends YTNode {
static type = 'AccountItem';
account_name: Text;
@@ -18,28 +21,27 @@ class AccountItem {
endpoint: NavigationEndpoint;
account_byline: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.account_name = new Text(data.accountName);
this.account_photo = Thumbnail.fromResponse(data.accountPhoto);
this.is_selected = data.isSelected;
this.is_disabled = data.isDisabled;
this.has_channel = data.hasChannel;
this.is_selected = !!data.isSelected;
this.is_disabled = !!data.isDisabled;
this.has_channel = !!data.hasChannel;
this.endpoint = new NavigationEndpoint(data.serviceEndpoint);
this.account_byline = new Text(data.accountByline);
}
}
class AccountItemSection extends YTNode {
export default class AccountItemSection extends YTNode {
static type = 'AccountItemSection';
contents;
header;
contents: ObservedArray<AccountItem>;
header: AccountItemSectionHeader | null;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.contents = data.contents.map((ac: any) => new AccountItem(ac.accountItem));
this.header = Parser.parseItem<AccountItemSectionHeader>(data.header, AccountItemSectionHeader);
this.contents = observe<AccountItem>(data.contents.map((ac: RawNode) => new AccountItem(ac.accountItem)));
this.header = Parser.parseItem(data.header, AccountItemSectionHeader);
}
}
export default AccountItemSection;
}

View File

@@ -1,15 +1,14 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class AccountItemSectionHeader extends YTNode {
export default class AccountItemSectionHeader extends YTNode {
static type = 'AccountItemSectionHeader';
title: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
}
}
export default AccountItemSectionHeader;
}

View File

@@ -3,18 +3,17 @@ import AccountChannel from './AccountChannel.js';
import AccountItemSection from './AccountItemSection.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class AccountSectionList extends YTNode {
export default class AccountSectionList extends YTNode {
static type = 'AccountSectionList';
contents;
footers;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.contents = Parser.parseItem<AccountItemSection>(data.contents[0], AccountItemSection);
this.footers = Parser.parseItem<AccountChannel>(data.footers[0], AccountChannel);
this.contents = Parser.parseItem(data.contents[0], AccountItemSection);
this.footers = Parser.parseItem(data.footers[0], AccountChannel);
}
}
export default AccountSectionList;
}

View File

@@ -1,17 +1,16 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class Alert extends YTNode {
export default class Alert extends YTNode {
static type = 'Alert';
text: Text;
alert_type: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.text = new Text(data.text);
this.alert_type = data.type;
}
}
export default Alert;
}

View File

@@ -1,14 +1,13 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class AudioOnlyPlayability extends YTNode {
export default class AudioOnlyPlayability extends YTNode {
static type = 'AudioOnlyPlayability';
audio_only_availability: string;
constructor (data: any) {
constructor (data: RawNode) {
super();
this.audio_only_availability = data.audioOnlyAvailability;
}
}
export default AudioOnlyPlayability;
}

View File

@@ -1,12 +1,13 @@
import { YTNode } from '../helpers.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type { RawNode } from '../index.js';
class AutomixPreviewVideo extends YTNode {
export default class AutomixPreviewVideo extends YTNode {
static type = 'AutomixPreviewVideo';
playlist_video?: { endpoint: NavigationEndpoint };
constructor(data: any) {
constructor(data: RawNode) {
super();
if (data?.content?.automixPlaylistVideoRenderer?.navigationEndpoint) {
this.playlist_video = {
@@ -14,6 +15,4 @@ class AutomixPreviewVideo extends YTNode {
};
}
}
}
export default AutomixPreviewVideo;
}

View File

@@ -1,18 +1,17 @@
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class BackstageImage extends YTNode {
export default class BackstageImage extends YTNode {
static type = 'BackstageImage';
image: Thumbnail[];
endpoint: NavigationEndpoint;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.image = Thumbnail.fromResponse(data.image);
this.endpoint = new NavigationEndpoint(data.command);
}
}
export default BackstageImage;
}

View File

@@ -1,13 +1,12 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import CommentActionButtons from './comments/CommentActionButtons.js';
import Menu from './menus/Menu.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type CommentActionButtons from './comments/CommentActionButtons.js';
import type Menu from './menus/Menu.js';
import { YTNode } from '../helpers.js';
class BackstagePost extends YTNode {
export default class BackstagePost extends YTNode {
static type = 'BackstagePost';
id: string;
@@ -18,13 +17,13 @@ class BackstagePost extends YTNode {
vote_status?: string;
vote_count?: Text;
menu?: Menu | null;
action_buttons;
vote_button;
action_buttons?: CommentActionButtons | null;
vote_button?: CommentActionButtons | null;
surface: string;
endpoint?: NavigationEndpoint;
attachment;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.postId;
@@ -36,40 +35,38 @@ class BackstagePost extends YTNode {
this.content = new Text(data.contentText);
this.published = new Text(data.publishedTimeText);
if (data.pollStatus) {
if (Reflect.has(data, 'pollStatus')) {
this.poll_status = data.pollStatus;
}
if (data.voteStatus) {
if (Reflect.has(data, 'voteStatus')) {
this.vote_status = data.voteStatus;
}
if (data.voteCount) {
if (Reflect.has(data, 'voteCount')) {
this.vote_count = new Text(data.voteCount);
}
if (data.actionMenu) {
this.menu = Parser.parseItem<Menu>(data.actionMenu);
if (Reflect.has(data, 'actionMenu')) {
this.menu = Parser.parseItem(data.actionMenu, Menu);
}
if (data.actionButtons) {
this.action_buttons = Parser.parseItem<CommentActionButtons>(data.actionButtons);
if (Reflect.has(data, 'actionButtons')) {
this.action_buttons = Parser.parseItem(data.actionButtons, CommentActionButtons);
}
if (data.voteButton) {
this.vote_button = Parser.parseItem(data.voteButton);
if (Reflect.has(data, 'voteButton')) {
this.vote_button = Parser.parseItem(data.voteButton, CommentActionButtons);
}
if (data.navigationEndpoint) {
if (Reflect.has(data, 'navigationEndpoint')) {
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
}
if (data.backstageAttachment) {
if (Reflect.has(data, 'backstageAttachment')) {
this.attachment = Parser.parseItem(data.backstageAttachment);
}
this.surface = data.surface;
}
}
export default BackstagePost;
}

View File

@@ -1,15 +1,13 @@
import Parser from '../index.js';
import Parser, { type RawNode } from '../index.js';
import { YTNode } from '../helpers.js';
class BackstagePostThread extends YTNode {
export default class BackstagePostThread extends YTNode {
static type = 'BackstagePostThread';
post;
post: YTNode;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.post = Parser.parseItem(data.post);
}
}
export default BackstagePostThread;
}

View File

@@ -1,15 +1,13 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import { type ObservedArray, YTNode } from '../helpers.js';
class BrowseFeedActions extends YTNode {
export default class BrowseFeedActions extends YTNode {
static type = 'BrowseFeedActions';
contents;
contents: ObservedArray<YTNode>;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.contents = Parser.parseArray(data.contents);
}
}
export default BrowseFeedActions;
}

View File

@@ -1,18 +1,17 @@
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class BrowserMediaSession extends YTNode {
export default class BrowserMediaSession extends YTNode {
static type = 'BrowserMediaSession';
album;
thumbnails;
album: Text;
thumbnails: Thumbnail[];
constructor (data: any) {
constructor (data: RawNode) {
super();
this.album = new Text(data.album);
this.thumbnails = Thumbnail.fromResponse(data.thumbnailDetails);
}
}
export default BrowserMediaSession;
}

View File

@@ -1,37 +1,35 @@
import Text from './misc/Text.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class Button extends YTNode {
export default class Button extends YTNode {
static type = 'Button';
text?: string;
label?: string;
tooltip?: string;
icon_type?: string;
is_disabled?: boolean;
endpoint: NavigationEndpoint;
constructor(data: any) {
constructor(data: RawNode) {
super();
if (data.text) {
if (Reflect.has(data, 'text')) {
this.text = new Text(data.text).toString();
}
if (data.accessibility?.label) {
this.label = data.accessibility?.label;
if (Reflect.has(data, 'accessibility') && Reflect.has(data.accessibility, 'label')) {
this.label = data.accessibility.label;
}
if (data.tooltip) {
if (Reflect.has(data, 'tooltip')) {
this.tooltip = data.tooltip;
}
if (data.icon?.iconType) {
this.icon_type = data.icon?.iconType;
if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) {
this.icon_type = data.icon.iconType;
}
if (Reflect.has(data, 'isDisabled')) {
@@ -40,6 +38,4 @@ class Button extends YTNode {
this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint || data.command);
}
}
export default Button;
}

View File

@@ -1,15 +1,13 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Button from './Button.js';
import ChannelHeaderLinks from './ChannelHeaderLinks.js';
import SubscribeButton from './SubscribeButton.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import type Button from './Button.js';
import type ChannelHeaderLinks from './ChannelHeaderLinks.js';
import type SubscribeButton from './SubscribeButton.js';
import { YTNode } from '../helpers.js';
class C4TabbedHeader extends YTNode {
export default class C4TabbedHeader extends YTNode {
static type = 'C4TabbedHeader';
author: Author;
@@ -19,58 +17,56 @@ class C4TabbedHeader extends YTNode {
subscribers?: Text;
videos_count?: Text;
sponsor_button?: Button | null;
subscribe_button?: SubscribeButton | null;
subscribe_button?: SubscribeButton | Button | null;
header_links?: ChannelHeaderLinks | null;
channel_handle?: Text;
channel_id?: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.author = new Author({
simpleText: data.title,
navigationEndpoint: data.navigationEndpoint
}, data.badges, data.avatar);
if (data.banner) {
if (Reflect.has(data, 'banner')) {
this.banner = Thumbnail.fromResponse(data.banner);
}
if (data.tv_banner) {
if (Reflect.has(data, 'tv_banner')) {
this.tv_banner = Thumbnail.fromResponse(data.tvBanner);
}
if (data.mobile_banner) {
if (Reflect.has(data, 'mobile_banner')) {
this.mobile_banner = Thumbnail.fromResponse(data.mobileBanner);
}
if (data.subscriberCountText) {
if (Reflect.has(data, 'subscriberCountText')) {
this.subscribers = new Text(data.subscriberCountText);
}
if (data.videosCountText) {
if (Reflect.has(data, 'videosCountText')) {
this.videos_count = new Text(data.videosCountText);
}
if (data.sponsorButton) {
this.sponsor_button = Parser.parseItem<Button>(data.sponsorButton);
if (Reflect.has(data, 'sponsorButton')) {
this.sponsor_button = Parser.parseItem(data.sponsorButton, Button);
}
if (data.subscribeButton) {
this.subscribe_button = Parser.parseItem<SubscribeButton>(data.subscribeButton);
if (Reflect.has(data, 'subscribeButton')) {
this.subscribe_button = Parser.parseItem(data.subscribeButton, [ SubscribeButton, Button ]);
}
if (data.headerLinks) {
this.header_links = Parser.parseItem<ChannelHeaderLinks>(data.headerLinks);
if (Reflect.has(data, 'headerLinks')) {
this.header_links = Parser.parseItem(data.headerLinks, ChannelHeaderLinks);
}
if (data.channelHandleText) {
if (Reflect.has(data, 'channelHandleText')) {
this.channel_handle = new Text(data.channelHandleText);
}
if (data.channelId) {
if (Reflect.has(data, 'channelId')) {
this.channel_id = data.channelId;
}
}
}
export default C4TabbedHeader;
}

View File

@@ -1,19 +1,18 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class CallToActionButton extends YTNode {
export default class CallToActionButton extends YTNode {
static type = 'CallToActionButton';
label: Text;
icon_type: string;
style: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.label = new Text(data.label);
this.icon_type = data.icon.iconType;
this.style = data.style;
}
}
export default CallToActionButton;
}

View File

@@ -1,13 +1,13 @@
import Parser from '../index.js';
import Parser, { type RawNode } from '../index.js';
import { YTNode } from '../helpers.js';
class Card extends YTNode {
export default class Card extends YTNode {
static type = 'Card';
teaser;
content;
card_id: string | null;
feature: string | null;
teaser: YTNode;
content: YTNode;
card_id?: string;
feature?: string;
cue_ranges: {
start_card_active_ms: string;
@@ -16,12 +16,18 @@ class Card extends YTNode {
icon_after_teaser_ms: string;
}[];
constructor(data: any) {
constructor(data: RawNode) {
super();
this.teaser = Parser.parseItem(data.teaser);
this.content = Parser.parseItem(data.content);
this.card_id = data.cardId || null;
this.feature = data.feature || null;
if (Reflect.has(data, 'cardId')) {
this.card_id = data.cardId;
}
if (Reflect.has(data, 'feature')) {
this.feature = data.feature;
}
this.cue_ranges = data.cueRanges.map((cr: any) => ({
start_card_active_ms: cr.startCardActiveMs,
@@ -30,6 +36,4 @@ class Card extends YTNode {
icon_after_teaser_ms: cr.iconAfterTeaserMs
}));
}
}
export default Card;
}

View File

@@ -1,20 +1,18 @@
import Parser from '../index.js';
import { YTNode, type ObservedArray } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
class CardCollection extends YTNode {
export default class CardCollection extends YTNode {
static type = 'CardCollection';
cards;
cards: ObservedArray<YTNode>;
header: Text;
allow_teaser_dismiss: boolean;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.cards = Parser.parseArray(data.cards);
this.header = new Text(data.headerText);
this.allow_teaser_dismiss = data.allowTeaserDismiss;
}
}
export default CardCollection;
}

View File

@@ -1,15 +1,13 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import { type ObservedArray, YTNode } from '../helpers.js';
class CarouselHeader extends YTNode {
export default class CarouselHeader extends YTNode {
static type = 'CarouselHeader';
contents: YTNode[];
contents: ObservedArray<YTNode>;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.contents = Parser.parseArray(data.contents);
}
}
export default CarouselHeader;
}

View File

@@ -1,18 +1,17 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import { type ObservedArray, YTNode } from '../helpers.js';
import Thumbnail from './misc/Thumbnail.js';
class CarouselItem extends YTNode {
export default class CarouselItem extends YTNode {
static type = 'CarouselItem';
items: YTNode[];
items: ObservedArray<YTNode>;
background_color: string;
layout_style: string;
pagination_thumbnails: Thumbnail[];
paginator_alignment: string;
constructor (data: any) {
constructor (data: RawNode) {
super();
this.items = Parser.parseArray(data.carouselItems);
this.background_color = data.backgroundColor;
@@ -20,6 +19,9 @@ class CarouselItem extends YTNode {
this.pagination_thumbnails = Thumbnail.fromResponse(data.paginationThumbnails);
this.paginator_alignment = data.paginatorAlignment;
}
}
export default CarouselItem;
// XXX: For consistency.
get contents() {
return this.items;
}
}

View File

@@ -0,0 +1,20 @@
import { type ObservedArray, YTNode } from '../helpers.js';
import InfoRow from './InfoRow.js';
import Parser, { type RawNode } from '../index.js';
import CompactVideo from './CompactVideo.js';
export default class CarouselLockup extends YTNode {
static type = 'CarouselLockup';
info_rows: ObservedArray<InfoRow>;
video_lockup?: CompactVideo;
constructor(data: RawNode) {
super();
this.info_rows = Parser.parseArray(data.infoRows, InfoRow);
const video_lockup = Parser.parseItem(data.videoLockup, CompactVideo);
if (video_lockup != null) {
this.video_lockup = video_lockup;
}
}
}

View File

@@ -1,27 +1,25 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import Author from './misc/Author.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type SubscribeButton from './SubscribeButton.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Button from './Button.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import SubscribeButton from './SubscribeButton.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
class Channel extends YTNode {
export default class Channel extends YTNode {
static type = 'Channel';
id: string;
author: Author;
subscribers: Text;
videos: Text;
subscriber_count: Text;
video_count: Text;
long_byline: Text;
short_byline: Text;
endpoint: NavigationEndpoint;
subscribe_button: SubscribeButton | null;
subscribe_button: SubscribeButton | Button | null;
description_snippet: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.channelId;
@@ -30,15 +28,31 @@ class Channel extends YTNode {
navigationEndpoint: data.navigationEndpoint
}, data.ownerBadges, data.thumbnail);
// TODO: subscriberCountText is now the channel's handle and videoCountText is the subscriber count. Why haven't they renamed the properties?
this.subscribers = new Text(data.subscriberCountText);
this.videos = new Text(data.videoCountText);
// XXX: `subscriberCountText` is now the channel's handle and `videoCountText` is the subscriber count.
this.subscriber_count = new Text(data.subscriberCountText);
this.video_count = new Text(data.videoCountText);
this.long_byline = new Text(data.longBylineText);
this.short_byline = new Text(data.shortBylineText);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.subscribe_button = Parser.parseItem<SubscribeButton>(data.subscribeButton);
this.subscribe_button = Parser.parseItem(data.subscribeButton, [ SubscribeButton, Button ]);
this.description_snippet = new Text(data.descriptionSnippet);
}
}
export default Channel;
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link Channel.subscriber_count} instead.
*/
get subscribers(): Text {
return this.subscriber_count;
}
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link Channel.video_count} instead.
*/
get videos(): Text {
return this.video_count;
}
}

View File

@@ -1,14 +1,11 @@
import Parser from '../index.js';
import { YTNode, type ObservedArray } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Button from './Button.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type Button from './Button.js';
import { YTNode } from '../helpers.js';
class ChannelAboutFullMetadata extends YTNode {
export default class ChannelAboutFullMetadata extends YTNode {
static type = 'ChannelAboutFullMetadata';
id: string;
@@ -22,15 +19,15 @@ class ChannelAboutFullMetadata extends YTNode {
title: Text;
}[];
views: Text;
joined: Text;
view_count: Text;
joined_date: Text;
description: Text;
email_reveal: NavigationEndpoint;
can_reveal_email: boolean;
country: Text;
buttons: Button[];
buttons: ObservedArray<Button>;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.channelId;
this.name = new Text(data.title);
@@ -43,14 +40,30 @@ class ChannelAboutFullMetadata extends YTNode {
title: new Text(link.title)
})) ?? [];
this.views = new Text(data.viewCountText);
this.joined = new Text(data.joinedDateText);
this.view_count = new Text(data.viewCountText);
this.joined_date = new Text(data.joinedDateText);
this.description = new Text(data.description);
this.email_reveal = new NavigationEndpoint(data.onBusinessEmailRevealClickCommand);
this.can_reveal_email = !data.signInForBusinessEmail;
this.country = new Text(data.country);
this.buttons = Parser.parseArray<Button>(data.actionButtons);
this.buttons = Parser.parseArray(data.actionButtons, Button);
}
}
export default ChannelAboutFullMetadata;
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link Channel.view_count} instead.
*/
get views() {
return this.view_count;
}
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link Channel.joined_date} instead.
*/
get joined(): Text {
return this.joined_date;
}
}

View File

@@ -1,12 +1,11 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { Parser } from '../index.js';
import Button from './Button.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelAgeGate extends YTNode {
export default class ChannelAgeGate extends YTNode {
static type = 'ChannelAgeGate';
channel_title: string;
@@ -22,9 +21,7 @@ class ChannelAgeGate extends YTNode {
this.avatar = Thumbnail.fromResponse(data.avatar);
this.header = new Text(data.header);
this.main_text = new Text(data.mainText);
this.sign_in_button = Parser.parseItem<Button>(data.signInButton, Button);
this.sign_in_button = Parser.parseItem(data.signInButton, Button);
this.secondary_text = new Text(data.secondaryText);
}
}
export default ChannelAgeGate;
}

View File

@@ -1,18 +1,16 @@
import Parser from '../index.js';
import { type ObservedArray, YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
class ChannelFeaturedContent extends YTNode {
export default class ChannelFeaturedContent extends YTNode {
static type = 'ChannelFeaturedContent';
title: Text;
items;
items: ObservedArray<YTNode>;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.items = Parser.parse(data.items);
this.items = Parser.parseArray(data.items);
}
}
export default ChannelFeaturedContent;
}

View File

@@ -1,31 +1,34 @@
import { YTNode, observe, type ObservedArray } from '../helpers.js';
import type { RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import { YTNode } from '../helpers.js';
class HeaderLink {
// XXX (LuanRT): This is not a real YTNode, but we treat it as one to keep things clean.
export class HeaderLink extends YTNode {
static type = 'HeaderLink';
endpoint: NavigationEndpoint;
icon: Thumbnail[];
title: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.icon = Thumbnail.fromResponse(data.icon);
this.title = new Text(data.title);
}
}
class ChannelHeaderLinks extends YTNode {
export default class ChannelHeaderLinks extends YTNode {
static type = 'ChannelHeaderLinks';
primary: HeaderLink[];
secondary: HeaderLink[];
primary: ObservedArray<HeaderLink>;
secondary: ObservedArray<HeaderLink>;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.primary = data.primaryLinks?.map((link: any) => new HeaderLink(link)) || [];
this.secondary = data.secondaryLinks?.map((link: any) => new HeaderLink(link)) || [];
this.primary = observe(data.primaryLinks?.map((link: RawNode) => new HeaderLink(link)) || []);
this.secondary = observe(data.secondaryLinks?.map((link: RawNode) => new HeaderLink(link)) || []);
}
}
export default ChannelHeaderLinks;
}

View File

@@ -1,13 +1,14 @@
import Thumbnail from './misc/Thumbnail.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelMetadata extends YTNode {
export default class ChannelMetadata extends YTNode {
static type = 'ChannelMetadata';
title: string;
description: string;
url: string;
rss_urls: any; // Array?
rss_url: string;
vanity_channel_url: string;
external_id: string;
is_family_safe: boolean;
@@ -18,12 +19,12 @@ class ChannelMetadata extends YTNode {
android_appindexing_link: string;
ios_appindexing_link: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = data.title;
this.description = data.description;
this.url = data.channelUrl;
this.rss_urls = data.rssUrl;
this.rss_url = data.rssUrl;
this.vanity_channel_url = data.vanityChannelUrl;
this.external_id = data.externalId;
this.is_family_safe = data.isFamilySafe;
@@ -34,6 +35,4 @@ class ChannelMetadata extends YTNode {
this.android_appindexing_link = data.androidAppindexingLink;
this.ios_appindexing_link = data.iosAppindexingLink;
}
}
export default ChannelMetadata;
}

View File

@@ -1,15 +1,14 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelMobileHeader extends YTNode {
export default class ChannelMobileHeader extends YTNode {
static type = 'ChannelMobileHeader';
title: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
}
}
export default ChannelMobileHeader;
}

View File

@@ -1,10 +1,10 @@
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelOptions extends YTNode {
export default class ChannelOptions extends YTNode {
static type = 'ChannelOptions';
avatar: Thumbnail[];
@@ -12,13 +12,11 @@ class ChannelOptions extends YTNode {
name: string;
links: Text[];
constructor(data: any) {
constructor(data: RawNode) {
super();
this.avatar = Thumbnail.fromResponse(data.avatar);
this.endpoint = new NavigationEndpoint(data.avatarEndpoint);
this.name = data.name;
this.links = data.links.map((link: any) => new Text(link));
this.links = data.links.map((link: RawNode) => new Text(link));
}
}
export default ChannelOptions;
}

View File

@@ -1,8 +1,8 @@
import Parser from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import Parser, { type RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
class ChannelSubMenu extends YTNode {
export default class ChannelSubMenu extends YTNode {
static type = 'ChannelSubMenu';
content_type_sub_menu_items: {
@@ -13,15 +13,13 @@ class ChannelSubMenu extends YTNode {
sort_setting;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.content_type_sub_menu_items = data.contentTypeSubMenuItems.map((item: any) => ({
this.content_type_sub_menu_items = data.contentTypeSubMenuItems.map((item: RawNode) => ({
endpoint: new NavigationEndpoint(item.navigationEndpoint || item.endpoint),
selected: item.selected,
title: item.title
}));
this.sort_setting = Parser.parseItem(data.sortSetting);
}
}
export default ChannelSubMenu;
}

View File

@@ -1,20 +1,19 @@
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelThumbnailWithLink extends YTNode {
export default class ChannelThumbnailWithLink extends YTNode {
static type = 'ChannelThumbnailWithLink';
thumbnails: Thumbnail[];
endpoint: NavigationEndpoint;
label: string;
label?: string;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.label = data.accessibility.accessibilityData.label;
this.label = data.accessibility?.accessibilityData?.label;
}
}
export default ChannelThumbnailWithLink;
}

View File

@@ -1,23 +1,40 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
class ChannelVideoPlayer extends YTNode {
export default class ChannelVideoPlayer extends YTNode {
static type = 'ChannelVideoPlayer';
id: string;
title: Text;
description: Text;
views: Text;
published: Text;
view_count: Text;
published_time: Text;
constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.videoId;
this.title = new Text(data.title);
this.description = new Text(data.description);
this.views = new Text(data.viewCountText);
this.published = new Text(data.publishedTimeText);
this.view_count = new Text(data.viewCountText);
this.published_time = new Text(data.publishedTimeText);
}
}
export default ChannelVideoPlayer;
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link ChannelVideoPlayer.view_count} instead.
*/
get views(): Text {
return this.view_count;
}
/**
* @deprecated
* This will be removed in a future release.
* Please use {@link ChannelVideoPlayer.published_time} instead.
*/
get published(): Text {
return this.published_time;
}
}

Some files were not shown because too many files have changed in this diff Show More