mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
feat!: better cross runtime support (#97)
* refactor: remove dependancies removes node-forge and uuid in favor of Web APIs * refactor!: commonjs to es6 To aid with #93 I will make all my changes in TypeScript instead. This is the first step into making that happen. Used: https://github.com/wessberg/cjstoesm * refactor!: NToken and Signature TS files Bring this PR up to speed with #93 * feat: cross platform cache (WIP) this is untested! should remove idb as dependecy. * feat: EventEmitter polyfill * refactor: remove events * feat: HTTPClient based on Fetch API (WIP) * refactor!: parsers refactor (WIP) Initial TS support for parsers as per #93 This adds several type safety checks to the parser which'll help to ensure valid data is returned by the parser. * refactor!: parsers refactor (WIP) Bring more in line with the existing implementations & make less verbose * refactor!: parser refactor I was overcomplicating things, this is much simpler and compatible with the existing JS API * fix: some missed parsers while refactoring * fix: better type inferance for parseResponse * feat(TS): typesafe YTNode casts * feat: more type safety in YTNode and Parser * refactor: VideoInfo download with fetch & TS (WIP) Again, this also does some work for #93 * fix: LiveChat in VideoInfo * refactor!: more typesafety in parser * refactor!: VideoInfo almost completed * refactor!: player and session refactors - Remove the Player class' dependance on Session. - Add additional context to the Session. * refactor!: move auth logic to Session (WIP) * refactor: TS port for Actions and Innertube My fingers hurt from typing out all those types :-P * refactor: NavigationEndpoint TS this is still a WIP and should be improved. NavigationEndpoint should probably be refactored further. * refactor!: VideoInfo compiles without errors * chore: delete old player * fix: import errors It compiles and runs!! * fix: Utils import fixes * fix: several runtime errors * fix: video streaming * chore: remove console.log debugging Whoops, forgot to remove these before I pushed the previous commit * chore: remove old unused dependencies * fix: typescript errors Now emitting declarations and source maps * refactor: TS feed * chore: delete old Feed * refactor: move streamToIterable into Utils * refactor: AccountManager TS * refactor: FilterableFeed to TS * refactor: InteractionManager to TS * refactor: PlaylistManager to TS * refactor: TabbedFeed to TS * refactor: Music to TS (WIP) more work to be done, see TODO comments * fix: getting the tests to pass (6/12) YouTube.js Tests Search ✓ Should search on YouTube (1152 ms) ✕ Should search on YouTube Music (705 ms) ✕ Should retrieve YouTube search suggestions (722 ms) ✓ Should retrieve YouTube Music search suggestions (233 ms) Comments ✓ Should retrieve comments (585 ms) ✕ Should retrieve next batch of comments (221 ms) ✕ Should retrieve comment replies (1 ms) General ✕ Should retrieve playlist with YouTube (732 ms) ✓ Should retrieve home feed (838 ms) ✓ Should retrieve trending content (543 ms) ✓ Should retrieve video info (639 ms) ✕ Should download video (5 ms) * fix: tests (7/12) YouTube.js Tests Search ✓ Should search on YouTube (1984 ms) ✕ Should search on YouTube Music (1139 ms) ✕ Should retrieve YouTube search suggestions (1433 ms) ✓ Should retrieve YouTube Music search suggestions (529 ms) Comments ✓ Should retrieve comments (324 ms) ✓ Should retrieve next batch of comments (395 ms) ✕ Should retrieve comment replies General ✕ Should retrieve playlist with YouTube (653 ms) ✓ Should retrieve home feed (1085 ms) ✓ Should retrieve trending content (513 ms) ✓ Should retrieve video info (921 ms) ✕ Should download video (3 ms) * fix: download tests (8/12) YouTube.js Tests Search ✓ Should search on YouTube (1293 ms) ✕ Should search on YouTube Music (927 ms) ✕ Should retrieve YouTube search suggestions (1250 ms) ✓ Should retrieve YouTube Music search suggestions (258 ms) Comments ✓ Should retrieve comments (803 ms) ✓ Should retrieve next batch of comments (511 ms) ✕ Should retrieve comment replies General ✕ Should retrieve playlist with YouTube (528 ms) ✓ Should retrieve home feed (1047 ms) ✓ Should retrieve trending content (548 ms) ✓ Should retrieve video info (825 ms) ✓ Should download video (1779 ms) * fix: tests (9/12) YouTube.js Tests Search ✓ Should search on YouTube (1276 ms) ✕ Should search on YouTube Music (955 ms) ✓ Should retrieve YouTube search suggestions (661 ms) ✓ Should retrieve YouTube Music search suggestions (491 ms) Comments ✓ Should retrieve comments (624 ms) ✓ Should retrieve next batch of comments (353 ms) ✕ Should retrieve comment replies General ✕ Should retrieve playlist with YouTube (672 ms) ✓ Should retrieve home feed (1277 ms) ✓ Should retrieve trending content (999 ms) ✓ Should retrieve video info (1106 ms) ✓ Should download video (2514 ms) * feat: key based type validation for parsers * fix: comments tests pass (10/12) YouTube.js Tests Search ✓ Should search on YouTube (938 ms) ✕ Should search on YouTube Music (850 ms) ✓ Should retrieve YouTube search suggestions (528 ms) ✓ Should retrieve YouTube Music search suggestions (224 ms) Comments ✓ Should retrieve comments (518 ms) ✓ Should retrieve next batch of comments (337 ms) ✓ Should retrieve comment replies (358 ms) General ✕ Should retrieve playlist with YouTube (466 ms) ✓ Should retrieve home feed (1051 ms) ✓ Should retrieve trending content (623 ms) ✓ Should retrieve video info (863 ms) ✓ Should download video (2656 ms) * refactor: type safety checks removing @ts-ignore * fix: playlist tests pass (11/12) YouTube.js Tests Search ✓ Should search on YouTube (991 ms) ✕ Should search on YouTube Music (924 ms) ✓ Should retrieve YouTube search suggestions (606 ms) ✓ Should retrieve YouTube Music search suggestions (225 ms) Comments ✓ Should retrieve comments (393 ms) ✓ Should retrieve next batch of comments (284 ms) ✓ Should retrieve comment replies (252 ms) General ✓ Should retrieve playlist with YouTube (578 ms) ✓ Should retrieve home feed (1148 ms) ✓ Should retrieve trending content (541 ms) ✓ Should retrieve video info (799 ms) ✓ Should download video (1419 ms) * fix: all tests pass for node 🎉 YouTube.js Tests Search ✓ Should search on YouTube (1053 ms) ✓ Should search on YouTube Music (761 ms) ✓ Should retrieve YouTube search suggestions (453 ms) ✓ Should retrieve YouTube Music search suggestions (221 ms) Comments ✓ Should retrieve comments (627 ms) ✓ Should retrieve next batch of comments (412 ms) ✓ Should retrieve comment replies (268 ms) General ✓ Should retrieve playlist with YouTube (565 ms) ✓ Should retrieve home feed (775 ms) ✓ Should retrieve trending content (498 ms) ✓ Should retrieve video info (875 ms) ✓ Should download video (1364 ms) * build: working Deno bundle Still need to test whether this bundle works in the browser * docs: update deno example to download video * refactor: MusicResponsiveListItem to TS * docs: TSDoc for Parser helpers * docs: Parser documentation for TS * docs: add note about parseItem and parseArray * test: remove browser tests since they're identical * feat: browser support and proxy example * fix: PlaylistManager TS after merge * feat: in-browser video streaming * refactor: cleanup the Dash example * feat: allow custom fetch implementations * feat: fetch debugger * fix: OAuth login * refactor: remove file extensions from imports * refactor: build scripts * fix: CustomEvent on node * fix: LiveChat * fix: linting * fix: liniting in build-parser-json * chore: update test workflow * fix: NToken errors after lint fixes * fix: codacy complaints * docs: update to reflect changes Definitly needs more work but its a start * refactor: cleanup imports/exports * fix: browser example - Remove user-agent before making request. - Fix cache on browsers * fix: cache on node * fix: stupid mistake * refactor: Session#signIn to wait untill success This also splits the 'auth' event up into 3 distinct events: - 'auth' -> fired on success - 'auth-pending' -> fired when pending authentication - 'auth-error' -> fired when an error occurred * refactor: freeze Constants * refactor: cleanup HTTPClient Request * refactor: debugFetch readability * chore: lint * refactor: replace jsdoc with tsdoc eslint plugin remove @param annotations without descriptions * fix: bunch of liniting warnings * refactor: better inference on YTNode#is As suggested by @MasterOfBob777 * fix: linting warnings * revert: undici import * refactor: rename `list_type` to `item_type`
This commit is contained in:
@@ -1,25 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
class AuthorCommentBadge {
|
||||
type = 'AuthorCommentBadge';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class AuthorCommentBadge extends YTNode {
|
||||
static type = 'AuthorCommentBadge';
|
||||
#data;
|
||||
|
||||
constructor(data) {
|
||||
super();
|
||||
this.icon_type = data.icon.iconType;
|
||||
this.tooltip = data.iconTooltip;
|
||||
|
||||
// *** For consistency
|
||||
this.tooltip === 'Verified' &&
|
||||
(this.style = 'BADGE_STYLE_TYPE_VERIFIED') &&
|
||||
(data.style = 'BADGE_STYLE_TYPE_VERIFIED');
|
||||
|
||||
(this.style = 'BADGE_STYLE_TYPE_VERIFIED') &&
|
||||
(data.style = 'BADGE_STYLE_TYPE_VERIFIED');
|
||||
this.#data = data;
|
||||
}
|
||||
|
||||
get orig_badge() {
|
||||
return this.#data;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuthorCommentBadge;
|
||||
export default AuthorCommentBadge;
|
||||
|
||||
@@ -1,82 +1,67 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
import Text from '../misc/Text';
|
||||
import Thumbnail from '../misc/Thumbnail';
|
||||
import Author from '../misc/Author';
|
||||
import Proto from '../../../proto/index';
|
||||
import { InnertubeError } from '../../../utils/Utils';
|
||||
|
||||
const Parser = require('../..');
|
||||
const Text = require('../Text');
|
||||
const Thumbnail = require('../Thumbnail');
|
||||
const Author = require('../Author');
|
||||
const Proto = require('../../../proto');
|
||||
const { InnertubeError } = require('../../../utils/Utils');
|
||||
|
||||
class Comment {
|
||||
type = 'Comment';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class Comment extends YTNode {
|
||||
static type = 'Comment';
|
||||
#actions;
|
||||
|
||||
constructor(data) {
|
||||
super();
|
||||
this.content = new Text(data.contentText);
|
||||
this.published = new Text(data.publishedTimeText);
|
||||
this.author_is_channel_owner = data.authorIsChannelOwner;
|
||||
this.current_user_reply_thumbnail = Thumbnail.fromResponse(data.currentUserReplyThumbnail);
|
||||
this.author_badge = Parser.parse(data.authorCommentBadge, 'comments');
|
||||
|
||||
this.author_badge = Parser.parse(data.authorCommentBadge);
|
||||
this.author = new Author({
|
||||
...data.authorText,
|
||||
navigationEndpoint: data.authorEndpoint
|
||||
}, this.author_badge ? [ {
|
||||
metadataBadgeRenderer: this.author_badge?.orig_badge
|
||||
} ] : null, data.authorThumbnail);
|
||||
|
||||
this.action_menu = Parser.parse(data.actionMenu);
|
||||
this.action_buttons = Parser.parse(data.actionButtons, 'comments');
|
||||
this.action_buttons = Parser.parse(data.actionButtons);
|
||||
this.comment_id = data.commentId;
|
||||
this.vote_status = data.voteStatus;
|
||||
|
||||
this.vote_count = {
|
||||
text: data.voteCount ? data.voteCount.accessibility.accessibilityData?.label.replace(/\D/g, '') : '0',
|
||||
short_text: data.voteCount ? new Text(data.voteCount).toString() : '0'
|
||||
};
|
||||
|
||||
this.reply_count = data.replyCount || 0;
|
||||
this.is_liked = this.action_buttons.like_button.is_toggled;
|
||||
this.is_disliked = this.action_buttons.dislike_button.is_toggled;
|
||||
this.is_liked = this.action_buttons.item().like_button.is_toggled;
|
||||
this.is_disliked = this.action_buttons.item().dislike_button.is_toggled;
|
||||
this.is_pinned = !!data.pinnedCommentBadge;
|
||||
}
|
||||
|
||||
/**
|
||||
* API response.
|
||||
* @typedef {{ success: boolean, status_code: number, data: object }} Response
|
||||
*/
|
||||
|
||||
/**
|
||||
* Likes the comment.
|
||||
* @returns {Promise.<Response>}
|
||||
*/
|
||||
async like() {
|
||||
const button = this.action_buttons.like_button;
|
||||
|
||||
if (button.is_toggled)
|
||||
throw new InnertubeError('This comment is already liked', { comment_id: this.comment_id });
|
||||
|
||||
const response = await button.endpoint.callTest(this.#actions, { parse: false });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dislikes the comment.
|
||||
* @returns {Promise.<Response>}
|
||||
*/
|
||||
async dislike() {
|
||||
const button = this.action_buttons.dislike_button;
|
||||
|
||||
if (button.is_toggled)
|
||||
throw new InnertubeError('This comment is already disliked', { comment_id: this.comment_id });
|
||||
|
||||
const response = await button.endpoint.callTest(this.#actions, { parse: false });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a reply to the comment.
|
||||
* @param {string} text
|
||||
@@ -85,21 +70,16 @@ class Comment {
|
||||
async reply(text) {
|
||||
if (!this.action_buttons.reply_button)
|
||||
throw new InnertubeError('Cannot reply to another reply. Try mentioning the user instead.', { comment_id: this.comment_id });
|
||||
|
||||
const button = this.action_buttons.reply_button;
|
||||
const dialog_button = button.endpoint.dialog.reply_button;
|
||||
|
||||
const payload = {
|
||||
params: {
|
||||
commentText: text
|
||||
}
|
||||
};
|
||||
|
||||
const response = await dialog_button.endpoint.callTest(this.#actions, payload);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the comment to the given language.
|
||||
* @param {string} target_language
|
||||
@@ -107,30 +87,23 @@ class Comment {
|
||||
async translate(target_language) {
|
||||
// Emojis must be removed otherwise InnerTube throws a 400 status code at us.
|
||||
const text = this.content.toString().replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu, '');
|
||||
|
||||
const payload = {
|
||||
text,
|
||||
target_language,
|
||||
comment_id: this.comment_id
|
||||
};
|
||||
|
||||
const action = Proto.encodeCommentActionParams(22, payload);
|
||||
const response = await this.#actions.execute('comment/perform_comment_action', { action, client: 'ANDROID' });
|
||||
|
||||
// TODO: maybe add these to Parser#parseResponse?
|
||||
const mutations = response.data.frameworkUpdates.entityBatchUpdate.mutations;
|
||||
const content = mutations[0].payload.commentEntityPayload.translatedContent.content;
|
||||
|
||||
return { ...response, content };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../../../../core/Actions')} actions
|
||||
* @private
|
||||
* @param {import('../../../../core/Actions').default} actions
|
||||
*/
|
||||
setActions(actions) {
|
||||
this.#actions = actions;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Comment;
|
||||
export default Comment;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
|
||||
const Parser = require('../..');
|
||||
|
||||
class CommentActionButtons {
|
||||
type = 'CommentActionButtons';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentActionButtons extends YTNode {
|
||||
static type = 'CommentActionButtons';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.like_button = Parser.parse(data.likeButton);
|
||||
this.dislike_button = Parser.parse(data.dislikeButton);
|
||||
this.reply_button = Parser.parse(data.replyButton);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentActionButtons;
|
||||
export default CommentActionButtons;
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
|
||||
const Parser = require('../..');
|
||||
|
||||
class CommentReplies {
|
||||
type = 'CommentReplies';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentReplies extends YTNode {
|
||||
static type = 'CommentReplies';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.contents = Parser.parse(data.contents);
|
||||
this.view_replies = Parser.parse(data.viewReplies);
|
||||
this.hide_replies = Parser.parse(data.hideReplies);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentReplies;
|
||||
export default CommentReplies;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
import Thumbnail from '../misc/Thumbnail';
|
||||
import Text from '../misc/Text';
|
||||
|
||||
const Parser = require('../..');
|
||||
const Thumbnail = require('../Thumbnail');
|
||||
const Text = require('../Text');
|
||||
|
||||
class CommentReplyDialog {
|
||||
type = 'CommentReplyDialog';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentReplyDialog extends YTNode {
|
||||
static type = 'CommentReplyDialog';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.reply_button = Parser.parse(data.replyButton);
|
||||
this.cancel_button = Parser.parse(data.cancelButton);
|
||||
this.author_thumbnail = Thumbnail.fromResponse(data.authorThumbnail);
|
||||
@@ -15,5 +15,4 @@ class CommentReplyDialog {
|
||||
this.error_message = new Text(data.errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentReplyDialog;
|
||||
export default CommentReplyDialog;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
import Thumbnail from '../misc/Thumbnail';
|
||||
import Text from '../misc/Text';
|
||||
|
||||
const Parser = require('../..');
|
||||
const Thumbnail = require('../Thumbnail');
|
||||
const Text = require('../Text');
|
||||
|
||||
class CommentSimplebox {
|
||||
type = 'CommentSimplebox';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentSimplebox extends YTNode {
|
||||
static type = 'CommentSimplebox';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.submit_button = Parser.parse(data.submitButton);
|
||||
this.cancel_button = Parser.parse(data.cancelButton);
|
||||
this.author_thumbnails = Thumbnail.fromResponse(data.authorThumbnail);
|
||||
@@ -15,5 +15,4 @@ class CommentSimplebox {
|
||||
this.avatar_size = data.avatarSize;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentSimplebox;
|
||||
export default CommentSimplebox;
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('../..');
|
||||
const { InnertubeError } = require('../../../utils/Utils');
|
||||
|
||||
class CommentThread {
|
||||
type = 'CommentThread';
|
||||
|
||||
#replies;
|
||||
#actions;
|
||||
#continuation;
|
||||
|
||||
constructor(data) {
|
||||
/** @type {import('./Comment')} */
|
||||
this.comment = Parser.parse(data.comment);
|
||||
this.#replies = Parser.parse(data.replies);
|
||||
/** @type {boolean} */
|
||||
this.is_moderated_elq_comment = data.isModeratedElqComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves replies to this comment thread.
|
||||
* @returns {Promise.<CommentThread>}
|
||||
*/
|
||||
async getReplies() {
|
||||
if (!this.#replies)
|
||||
throw new InnertubeError('This comment has no replies.', { comment_id: this.comment.comment_id });
|
||||
|
||||
const continuation = this.#replies.contents.get({ type: 'ContinuationItem' });
|
||||
const response = await continuation.endpoint.callTest(this.#actions);
|
||||
|
||||
this.replies = response.on_response_received_endpoints_memo.get('Comment').map((comment) => {
|
||||
comment.setActions(this.#actions);
|
||||
return comment;
|
||||
});
|
||||
|
||||
this.#continuation = response.on_response_received_endpoints_memo.get('ContinuationItem')?.[0];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves next batch of replies.
|
||||
* @returns {Promise.<CommentThread>}
|
||||
*/
|
||||
async getContinuation() {
|
||||
if (!this.replies)
|
||||
throw new InnertubeError('Continuation not available.');
|
||||
|
||||
if (!this.#continuation)
|
||||
throw new InnertubeError('Continuation not found.');
|
||||
|
||||
const response = await this.#continuation.button.endpoint.callTest(this.#actions);
|
||||
|
||||
this.replies = response.on_response_received_endpoints_memo.get('Comment').map((comment) => {
|
||||
comment.setActions(this.#actions);
|
||||
return comment;
|
||||
});
|
||||
|
||||
this.#continuation = response.on_response_received_endpoints_memo.get('ContinuationItem')?.[0];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../../../core/Actions')} actions
|
||||
* @private
|
||||
*/
|
||||
setActions(actions) {
|
||||
this.#actions = actions;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentThread;
|
||||
63
lib/parser/classes/comments/CommentThread.ts
Normal file
63
lib/parser/classes/comments/CommentThread.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import Parser from '../../index';
|
||||
import { InnertubeError } from '../../../utils/Utils';
|
||||
|
||||
import { YTNode } from '../../helpers';
|
||||
import Comment from './Comment';
|
||||
import ContinuationItem from '../ContinuationItem';
|
||||
import Actions from '../../../core/Actions';
|
||||
import NavigationEndpoint from '../NavigationEndpoint';
|
||||
|
||||
class CommentThread extends YTNode {
|
||||
static type = 'CommentThread';
|
||||
#replies;
|
||||
#actions?: Actions;
|
||||
#continuation?: ContinuationItem;
|
||||
is_moderated_elq_comment: boolean;
|
||||
comment;
|
||||
replies: Comment[] | undefined;
|
||||
constructor(data: any) {
|
||||
super();
|
||||
this.comment = Parser.parseItem(data.comment, Comment);
|
||||
this.#replies = Parser.parseItem(data.replies);
|
||||
this.is_moderated_elq_comment = data.isModeratedElqComment;
|
||||
}
|
||||
/**
|
||||
* Retrieves replies to this comment thread.
|
||||
*/
|
||||
async getReplies() {
|
||||
if (!this.#actions)
|
||||
throw new InnertubeError('Actions not set for this CommentThread.');
|
||||
if (!this.#replies)
|
||||
throw new InnertubeError('This comment has no replies.', { comment_id: this.comment?.comment_id });
|
||||
const continuation = this.#replies.key('contents').parsed().array().get({ type: 'ContinuationItem' })?.as(ContinuationItem);
|
||||
const response = await continuation?.endpoint.callTest(this.#actions);
|
||||
this.replies = response?.on_response_received_endpoints_memo?.getType(Comment).map((comment) => {
|
||||
comment.setActions(this.#actions);
|
||||
return comment;
|
||||
});
|
||||
this.#continuation = response?.on_response_received_endpoints_memo.getType(ContinuationItem)?.[0];
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Retrieves next batch of replies.
|
||||
*/
|
||||
async getContinuation() {
|
||||
if (!this.replies)
|
||||
throw new InnertubeError('Continuation not available.');
|
||||
if (!this.#continuation)
|
||||
throw new InnertubeError('Continuation not found.');
|
||||
if (!this.#actions)
|
||||
throw new InnertubeError('Actions not set for this CommentThread.');
|
||||
const response = await this.#continuation.button?.item().key('endpoint').nodeOfType(NavigationEndpoint).callTest(this.#actions);
|
||||
this.replies = response?.on_response_received_endpoints_memo.getType(Comment).map((comment) => {
|
||||
comment.setActions(this.#actions);
|
||||
return comment;
|
||||
});
|
||||
this.#continuation = response?.on_response_received_endpoints_memo.getType(ContinuationItem)?.[0];
|
||||
return this;
|
||||
}
|
||||
setActions(actions: Actions) {
|
||||
this.#actions = actions;
|
||||
}
|
||||
}
|
||||
export default CommentThread;
|
||||
@@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
import Text from '../misc/Text';
|
||||
import Thumbnail from '../misc/Thumbnail';
|
||||
|
||||
const Text = require('../Text');
|
||||
const Thumbnail = require('../Thumbnail');
|
||||
|
||||
class CommentsEntryPointHeader {
|
||||
type = 'CommentsEntryPointHeader';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentsEntryPointHeader extends YTNode {
|
||||
static type = 'CommentsEntryPointHeader';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.header = new Text(data.headerText);
|
||||
this.comment_count = new Text(data.commentCount);
|
||||
this.teaser_avatar = Thumbnail.fromResponse(data.teaserAvatar || data.simpleboxAvatar);
|
||||
@@ -14,5 +14,4 @@ class CommentsEntryPointHeader {
|
||||
this.simplebox_placeholder = new Text(data.simpleboxPlaceholder);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentsEntryPointHeader;
|
||||
export default CommentsEntryPointHeader;
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
'use strict';
|
||||
import Parser from '../../index';
|
||||
import Text from '../misc/Text';
|
||||
import Thumbnail from '../misc/Thumbnail';
|
||||
|
||||
const Parser = require('../..');
|
||||
const Text = require('../Text');
|
||||
const Thumbnail = require('../Thumbnail');
|
||||
|
||||
class CommentsHeader {
|
||||
type = 'CommentsHeader';
|
||||
import { YTNode } from '../../helpers';
|
||||
|
||||
class CommentsHeader extends YTNode {
|
||||
static type = 'CommentsHeader';
|
||||
constructor(data) {
|
||||
super();
|
||||
this.title = new Text(data.titleText);
|
||||
this.count = new Text(data.countText);
|
||||
this.comments_count = new Text(data.commentsCount);
|
||||
this.create_renderer = Parser.parse(data.createRenderer, 'comments');
|
||||
this.create_renderer = Parser.parseItem(data.createRenderer);
|
||||
this.sort_menu = Parser.parse(data.sortMenu);
|
||||
|
||||
this.custom_emojis = data.customEmojis?.map((emoji) => ({
|
||||
emoji_id: emoji.emojiId,
|
||||
shortcuts: emoji.shortcuts,
|
||||
@@ -23,5 +22,4 @@ class CommentsHeader {
|
||||
})) || null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentsHeader;
|
||||
export default CommentsHeader;
|
||||
|
||||
Reference in New Issue
Block a user