-
-
Notifications
You must be signed in to change notification settings - Fork 255
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
feat: add TV client endpoints and nodes to get content with default OAuth2 Login #872
base: main
Are you sure you want to change the base?
Changes from all commits
edabbde
384e743
f071940
42aa918
23432eb
403fd40
4a674ff
af290a2
de981cc
80212ed
4247d62
168126a
cbce45f
cb8979f
656576c
0750fbe
9e45bdd
ad08278
e4a71b4
1b28052
f3c06a9
29680b9
65c61b6
b4e01d3
6cda166
a9e4ab3
b1970ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import { HorizontalListContinuation, type IBrowseResponse, Parser } from '../../parser/index.js'; | ||
import type { Actions, Session } from '../index.js'; | ||
import type { InnerTubeClient } from '../../types/index.js'; | ||
import NavigationEndpoint from '../../parser/classes/NavigationEndpoint.js'; | ||
import { HomeFeed, VideoInfo, MyYoutubeFeed } from '../../parser/yttv/index.js'; | ||
import { generateRandomString, InnertubeError, throwIfMissing } from '../../utils/Utils.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'; | ||
|
||
export default class TV { | ||
#session: Session; | ||
readonly #actions: Actions; | ||
|
||
constructor(session: Session) { | ||
this.#session = session; | ||
this.#actions = session.actions; | ||
} | ||
|
||
async getInfo(target: string | NavigationEndpoint, client?: InnerTubeClient): 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 watch_response = watch_endpoint.call(this.#actions, { | ||
playbackContext: { | ||
contentPlaybackContext: { | ||
vis: 0, | ||
splay: false, | ||
lactMilliseconds: '-1', | ||
signatureTimestamp: this.#session.player?.sts | ||
} | ||
}, | ||
serviceIntegrityDimensions: { | ||
poToken: this.#session.po_token | ||
}, | ||
client | ||
}); | ||
|
||
const watch_next_response = await watch_next_endpoint.call(this.#actions, { | ||
client | ||
}); | ||
|
||
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> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the library? If yes, maybe we should just name it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seemed to be an extra browseId "FEmy_youtube", which differed from the normal Library as it contained a left tab bar with a grid on the right, based on the tab selection. |
||
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?.first()?.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; | ||
} | ||
} |
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'; |
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; | ||
} | ||
} |
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); | ||
} | ||
} |
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> | null; | ||
bylines: ObservedArray<Line> | null; | ||
|
||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { YTNode, type ObservedArray } from '../helpers.js'; | ||
import { type RawNode, Parser } from '../index.js'; | ||
import Button from './Button.js'; | ||
|
||
export default class HorizontalButtonList extends YTNode { | ||
static type = 'HorizontalButtonList'; | ||
|
||
items: ObservedArray<Button> | null; | ||
|
||
constructor(data: RawNode) { | ||
super(); | ||
this.items = Parser.parse(data.items, true, Button); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are saving the session and the actions instances in their on variables but then in various places you still access the actions instance through
this#session.actions
. Could you please pick one and use it consistently throughout the class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced to use #action property.