mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-18 20:12:12 +00:00
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
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import Parser from '../../index.js';
|
||||
import Comment from './Comment.js';
|
||||
import ContinuationItem from '../ContinuationItem.js';
|
||||
import CommentReplies from './CommentReplies.js';
|
||||
import Button from '../Button.js';
|
||||
import type Actions from '../../../core/Actions.js';
|
||||
import type { ObservedArray } from '../../helpers.js';
|
||||
import ContinuationItem from '../ContinuationItem.js';
|
||||
import Comment from './Comment.js';
|
||||
import CommentReplies from './CommentReplies.js';
|
||||
|
||||
import { InnertubeError } from '../../../utils/Utils.js';
|
||||
import { observe, YTNode } from '../../helpers.js';
|
||||
|
||||
import type Actions from '../../../core/Actions.js';
|
||||
import type { ObservedArray } from '../../helpers.js';
|
||||
import type { RawNode } from '../../index.js';
|
||||
|
||||
class CommentThread extends YTNode {
|
||||
export default class CommentThread extends YTNode {
|
||||
static type = 'CommentThread';
|
||||
|
||||
#actions?: Actions;
|
||||
@@ -23,7 +25,7 @@ class CommentThread extends YTNode {
|
||||
|
||||
constructor(data: RawNode) {
|
||||
super();
|
||||
this.comment = Parser.parseItem<Comment>(data.comment, Comment);
|
||||
this.comment = Parser.parseItem(data.comment, Comment);
|
||||
this.comment_replies_data = Parser.parseItem(data.replies, CommentReplies);
|
||||
this.is_moderated_elq_comment = data.isModeratedElqComment;
|
||||
this.has_replies = !!this.comment_replies_data;
|
||||
@@ -37,7 +39,7 @@ class CommentThread extends YTNode {
|
||||
throw new InnertubeError('Actions instance not set for this thread.');
|
||||
|
||||
if (!this.comment_replies_data)
|
||||
throw new InnertubeError('This comment has no replies.', { comment_id: this.comment?.comment_id });
|
||||
throw new InnertubeError('This comment has no replies.', this);
|
||||
|
||||
const continuation = this.comment_replies_data.contents?.firstOfType(ContinuationItem);
|
||||
|
||||
@@ -87,7 +89,7 @@ class CommentThread extends YTNode {
|
||||
return comment;
|
||||
}));
|
||||
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem)?.[0];
|
||||
this.#continuation = response.on_response_received_endpoints_memo.getType(ContinuationItem).first();
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -101,6 +103,4 @@ class CommentThread extends YTNode {
|
||||
setActions(actions: Actions) {
|
||||
this.#actions = actions;
|
||||
}
|
||||
}
|
||||
|
||||
export default CommentThread;
|
||||
}
|
||||
Reference in New Issue
Block a user