diff --git a/examples/comments/CommentThread.md b/examples/comments/CommentThread.md index bfe33e7d..38f951d8 100644 --- a/examples/comments/CommentThread.md +++ b/examples/comments/CommentThread.md @@ -5,8 +5,8 @@ A `CommentThread` represents a top-level comment and its replies. ## API * CommentThread - * [.comment](#comment) ⇒ `Comment` - * [.replies](#replies) ⇒ `Comment[]` + * [.comment](#comment) ⇒ `Comment | CommentView` + * [.replies](#replies) ⇒ `(Comment | CommentView)[]` * [.getReplies](#getreplies) ⇒ `function` * [.getContinuation](#getcontinuation) ⇒ `function` * [.has_continuation](#hascontinuation) ⇒ `boolean` @@ -14,7 +14,7 @@ A `CommentThread` represents a top-level comment and its replies. ### comment -The top-level comment. **Note:** More about `Comment` [here](./Comment.md). +The top-level comment. **Note:** More about the `Comment` node [here](./Comment.md) (OUTDATED! `Comment` has been replaced by [`CommentView`](./CommentView.md) nodes). **Type:** [`Comment`](../../src/parser/classes/comments/Comment.ts) @@ -22,7 +22,7 @@ The top-level comment. **Note:** More about `Comment` [here](./Comment.md). ### replies An array of replies to the top-level comment. (not populated until [`getReplies()`](#getreplies) is called). -**Type:** [`Comment[]`](../../src/parser/classes/comments/Comment.ts) +**Type:** [`(Comment | CommentView)[]`](../../src/parser/classes/comments/Comment.ts) ### getReplies() diff --git a/examples/comments/CommentView.md b/examples/comments/CommentView.md new file mode 100644 index 00000000..ad6355d0 --- /dev/null +++ b/examples/comments/CommentView.md @@ -0,0 +1,48 @@ +## CommentView +Contains information about a single comment. A [`CommentView`](../../src/parser/classes/comments/CommentView.ts) can be a top-level comment or a reply to a top-level comment. + +## API + +* Comment + * [.like](#like) ⇒ `function` + * [.unlike](#like) ⇒ `function` + * [.dislike](#dislike) ⇒ `function` + * [.undislike](#dislike) ⇒ `function` + * [.reply](#reply) ⇒ `function` + * [.translate](#translate) ⇒ `function` + + +### like() +Likes the comment. + +**Returns:** `Promise.` + + +### unlike() +Unlikes the comment. + +**Returns:** `Promise.` + + +### dislike() +Dislikes the comment. + +**Returns:** `Promise.` + + +### undislike() +Undislikes the comment. + +**Returns:** `Promise.` + + +### reply(comment_text: string) +Replies to the comment. + +**Returns:** `Promise.` + + +### translate(target_language: string) +Translates the comment to the given language. + +**Returns:** `Promise.` \ No newline at end of file diff --git a/examples/comments/README.md b/examples/comments/README.md index 2ebcc19d..ed81d41e 100644 --- a/examples/comments/README.md +++ b/examples/comments/README.md @@ -59,7 +59,4 @@ Returns whether there are more comments to be fetched. ### page Returns original InnerTube response (sanitized). -**Returns:** `ParsedResponse` - -## Example -See [`index.ts`](./index.ts). \ No newline at end of file +**Returns:** `ParsedResponse` \ No newline at end of file diff --git a/examples/comments/index.ts b/examples/comments/index.ts deleted file mode 100644 index 39a07aa6..00000000 --- a/examples/comments/index.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Innertube, UniversalCache } from 'youtubei.js'; - -(async () => { - const yt = await Innertube.create({ cache: new UniversalCache(false), generate_session_locally: true }); - - const comment_section = await yt.getComments('a-rqu-hjobc'); - - console.info(`This video has ${comment_section.header?.comments_count.toString() || 'N/A'} comments.\n`); - - for (const thread of comment_section.contents) { - const comment = thread.comment; - - if (comment) { - console.info( - `${comment.is_pinned ? '[Pinned]' : ''}`, - `${comment.is_member ? `${comment.sponsor_comment_badge?.tooltip}` : ''}`, - `${comment.author.name} • ${comment.published}\n`, - `${comment.content.toString()}`, '\n', - `Likes: ${comment.vote_count}`, '\n' - ); - - if (thread.has_replies) { - console.info('Replies:', '\n'); - - let comment_thread = await thread.getReplies(); - - while (true) { - for (const reply of comment_thread?.replies || []) { - console.info( - `> ${reply.author.name} • ${reply.published}\n`, - `${reply.content.toString()}`, '\n', - `Likes: ${reply.vote_count}`, '\n' - ); - } - - try { - comment_thread = await comment_thread.getContinuation(); - } catch { break; }; - } - } - } - - console.log('\n'); - } -})(); \ No newline at end of file