-
Notifications
You must be signed in to change notification settings - Fork 363
feat: add TV client endpoints and nodes to get content with default OAuth2 Login #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Duell10111
wants to merge
15
commits into
LuanRT:main
Choose a base branch
from
Duell10111:tv-endpoints-adaption
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3564b95
feat: add tv client with classes
Duell10111 bb85e44
chore: add missing tv nodes
Duell10111 2fc8af8
chore: disable getInfo test for TV client as local session does not work
Duell10111 e9eeffc
chore: remove tracking params
Duell10111 5d08301
chore: remove client parameter on tv client class
Duell10111 4d67c82
refactor: move tv classes to tv folder
Duell10111 602a727
chore: adapt imports of TV client
Duell10111 8018826
chore: remove null from parseArray attributes
Duell10111 1e56763
chore: replace first with index selection
Duell10111 4c8c51a
chore: add semi
Duell10111 6ac7a58
fix: fix data change in SubscriptionsFeed.ts of TV variant
Duell10111 7ea287a
fix: adapt TV getInfo to use TV client again and adapt like other get…
Duell10111 dabef27
fix: fix timestamp and nodes.ts
Duell10111 6ad8592
chore: adapt tv playlist id to be the same as the normal getPlaylist …
Duell10111 512e7b2
fix: fix thumbnails in ShortsLockupView to use thumbnailViewModel.image
Duell10111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import { HorizontalListContinuation, type IBrowseResponse, Parser } from '../../parser/index.js'; | ||
| import type { Actions, Session } from '../index.js'; | ||
| import type { GetVideoInfoOptions, InnerTubeClient } from '../../types/index.js'; | ||
| import { generateRandomString, InnertubeError, throwIfMissing } from '../../utils/Utils.js'; | ||
| import NavigationEndpoint from '../../parser/classes/NavigationEndpoint.js'; | ||
| import HorizontalList from '../../parser/classes/HorizontalList.js'; | ||
| import type { YTNode } from '../../parser/helpers.js'; | ||
| import Playlist from '../../parser/yttv/Playlist.js'; | ||
| import Library from '../../parser/yttv/Library.js'; | ||
| import SubscriptionsFeed from '../../parser/yttv/SubscriptionsFeed.js'; | ||
| import PlaylistsFeed from '../../parser/yttv/PlaylistsFeed.js'; | ||
| import HomeFeed from '../../parser/yttv/HomeFeed.js'; | ||
| import VideoInfo from '../../parser/yttv/VideoInfo.js'; | ||
| import MyYoutubeFeed from '../../parser/yttv/MyYoutubeFeed.js'; | ||
|
|
||
| export default class TV { | ||
| #session: Session; | ||
| readonly #actions: Actions; | ||
|
|
||
| constructor(session: Session) { | ||
| this.#session = session; | ||
| this.#actions = session.actions; | ||
| } | ||
|
|
||
| async getInfo(target: string | NavigationEndpoint, options?: Omit<GetVideoInfoOptions, 'client'>): Promise<VideoInfo> { | ||
| throwIfMissing({ target }); | ||
|
|
||
| const payload = { | ||
| videoId: target instanceof NavigationEndpoint ? target.payload?.videoId : target, | ||
| playlistId: target instanceof NavigationEndpoint ? target.payload?.playlistId : undefined, | ||
| playlistIndex: target instanceof NavigationEndpoint ? target.payload?.playlistIndex : undefined, | ||
| params: target instanceof NavigationEndpoint ? target.payload?.params : undefined, | ||
| racyCheckOk: true, | ||
| contentCheckOk: true | ||
| }; | ||
|
|
||
| const watch_endpoint = new NavigationEndpoint({ watchEndpoint: payload }); | ||
| const watch_next_endpoint = new NavigationEndpoint({ watchNextEndpoint: payload }); | ||
|
|
||
| const extra_payload: Record<string, any> = { | ||
| playbackContext: { | ||
| contentPlaybackContext: { | ||
| vis: 0, | ||
| splay: false, | ||
| lactMilliseconds: '-1', | ||
| signatureTimestamp: this.#session.player?.signature_timestamp | ||
| } | ||
| }, | ||
| client: 'TV' | ||
| }; | ||
|
|
||
| if (options?.po_token) { | ||
| extra_payload.serviceIntegrityDimensions = { | ||
| poToken: options.po_token | ||
| }; | ||
| } else if (this.#session.po_token) { | ||
| extra_payload.serviceIntegrityDimensions = { | ||
| poToken: this.#session.po_token | ||
| }; | ||
| } | ||
|
|
||
| const watch_response = watch_endpoint.call(this.#actions, extra_payload); | ||
|
|
||
| const watch_next_response = await watch_next_endpoint.call(this.#actions, { client: 'TV' }); | ||
|
|
||
| const response = await Promise.all([ watch_response, watch_next_response ]); | ||
|
|
||
| const cpn = generateRandomString(16); | ||
|
|
||
| return new VideoInfo(response, this.#actions, cpn); | ||
| } | ||
|
|
||
| async getHomeFeed(): Promise<HomeFeed> { | ||
| const client : InnerTubeClient = 'TV'; | ||
| const home_feed = new NavigationEndpoint({ browseEndpoint: { | ||
| browseId: 'default' | ||
| } }); | ||
| const response = await home_feed.call(this.#actions, { | ||
| client | ||
| }); | ||
| return new HomeFeed(response, this.#actions); | ||
| } | ||
|
|
||
| async getLibrary(): Promise<Library> { | ||
| const browse_endpoint = new NavigationEndpoint({ browseEndpoint: { browseId: 'FElibrary' } }); | ||
| const response = await browse_endpoint.call(this.#actions, { | ||
| client: 'TV' | ||
| }); | ||
| return new Library(response, this.#actions); | ||
| } | ||
|
|
||
| async getSubscriptionsFeed(): Promise<SubscriptionsFeed> { | ||
| const browse_endpoint = new NavigationEndpoint({ browseEndpoint: { browseId: 'FEsubscriptions' } }); | ||
| const response = await browse_endpoint.call(this.#actions, { client: 'TV' }); | ||
| return new SubscriptionsFeed(response, this.#actions); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the user's playlists. | ||
| */ | ||
| async getPlaylists(): Promise<PlaylistsFeed> { | ||
| const browse_endpoint = new NavigationEndpoint({ browseEndpoint: { browseId: 'FEplaylist_aggregation' } }); | ||
| const response = await browse_endpoint.call(this.#actions, { client: 'TV' }); | ||
| return new PlaylistsFeed(response, this.#actions); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the user's My YouTube page. | ||
| */ | ||
| async getMyYoutubeFeed(): Promise<MyYoutubeFeed> { | ||
Duell10111 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const browse_endpoint = new NavigationEndpoint({ browseEndpoint: { browseId: 'FEmy_youtube' } }); | ||
| const response = await browse_endpoint.call(this.#actions, { client: 'TV' }); | ||
| return new MyYoutubeFeed(response, this.#actions); | ||
| } | ||
|
|
||
| async getPlaylist(id: string): Promise<Playlist> { | ||
| throwIfMissing({ id }); | ||
|
|
||
| if (!id.startsWith('VL')) { | ||
| id = `VL${id}`; | ||
| } | ||
|
|
||
| const browse_endpoint = new NavigationEndpoint({ browseEndpoint: { browseId: id } }); | ||
| const response = await browse_endpoint.call(this.#actions, { | ||
| client: 'TV' | ||
| }); | ||
|
|
||
| return new Playlist(response, this.#actions); | ||
| } | ||
|
|
||
| // Utils | ||
|
|
||
| async fetchContinuationData(item: YTNode, client?: InnerTubeClient) { | ||
| let continuation: string | undefined; | ||
|
|
||
| if (item.is(HorizontalList)) { | ||
| continuation = item.continuations?.[0]?.continuation; | ||
| } else if (item.is(HorizontalListContinuation)) { | ||
| continuation = item.continuation; | ||
| } else { | ||
| throw new InnertubeError(`No supported YTNode supplied. Type: ${item.type}`); | ||
| } | ||
|
|
||
| if (!continuation) { | ||
| throw new InnertubeError('No continuation data available.'); | ||
| } | ||
|
|
||
| const data = await this.#actions.execute('/browse', { | ||
| client: client ?? 'TV', | ||
| continuation: continuation | ||
| }); | ||
|
|
||
| const parser = Parser.parseResponse<IBrowseResponse>(data.data); | ||
| return parser.continuation_contents; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { default as Kids } from './Kids.js'; | ||
| export { default as Music } from './Music.js'; | ||
| export { default as TV } from './TV.js'; | ||
| export { default as Studio } from './Studio.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import Text from './misc/Text.js'; | ||
| import { type RawNode } from '../index.js'; | ||
| import { YTNode } from '../helpers.js'; | ||
|
|
||
| export default class AvatarLockup extends YTNode { | ||
| static type = 'AvatarLockup'; | ||
|
|
||
| title: Text; | ||
| size: string; | ||
|
|
||
| constructor(data: RawNode) { | ||
| super(); | ||
| this.title = new Text(data.title); | ||
| this.size = data.size; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { YTNode } from '../helpers.js'; | ||
| import { type RawNode } from '../index.js'; | ||
| import Text from './misc/Text.js'; | ||
| import Thumbnail from './misc/Thumbnail.js'; | ||
| import NavigationEndpoint from './NavigationEndpoint.js'; | ||
|
|
||
| export default class CommentsEntryPoint extends YTNode { | ||
| static type = 'CommentsEntryPoint'; | ||
|
|
||
| author_thumbnail: Thumbnail[]; | ||
| author_text: Text; | ||
| content_text: Text; | ||
| header_text: Text; | ||
| comment_count: Text; | ||
| endpoint: NavigationEndpoint; | ||
|
|
||
| constructor(data: RawNode) { | ||
| super(); | ||
| this.author_thumbnail = Thumbnail.fromResponse(data.authorThumbnail); | ||
| this.author_text = new Text(data.authorText); | ||
| this.content_text = new Text(data.contentText); | ||
| this.header_text = new Text(data.headerText); | ||
| this.comment_count = new Text(data.commentCount); | ||
| this.endpoint = new NavigationEndpoint(data.onSelectCommand); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { YTNode, type ObservedArray } from '../helpers.js'; | ||
| import { Parser, type RawNode } from '../index.js'; | ||
| import Button from './Button.js'; | ||
| import ToggleButton from './ToggleButton.js'; | ||
| import Line from './Line.js'; | ||
| import Text from './misc/Text.js'; | ||
|
|
||
| export default class EntityMetadata extends YTNode { | ||
| static type = 'EntityMetadata'; | ||
|
|
||
| title: Text; | ||
| description: Text; | ||
| buttons: ObservedArray<Button | ToggleButton>; | ||
| bylines: ObservedArray<Line>; | ||
|
|
||
| constructor(data: RawNode) { | ||
| super(); | ||
| this.title = new Text(data.title); | ||
| this.description = new Text(data.description); | ||
| this.buttons = Parser.parseArray(data.buttons, [ Button, ToggleButton ]); | ||
| this.bylines = Parser.parseArray(data.bylines, Line); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.