Files
YouTube.js/examples/comments/index.js
LuanRT 1d62e469a9 refactor: rewrite Comments Section logic (#88)
* feat: add core comments section classes

* chore: update type declarations

* chore: fix linter warnings

* style: fix linter

* chore: update tests

* chore(tests): fix typo

* chore(tests): fix typo x2

* fix(tests): `getReplies()` method is only present in `CommentThread` and not `Comment`

* chore(tests): fix comment id path

* chore(tests): remove outdated code

* chore(tests): fix results path

* chore: enforce code style

* chore: update type declarations

* docs: add examples and documentation

* chore(docs): fix paths

* chore(docs): fix more paths

* chore(docs): fix `Comments.js` path

* chore(docs): fix typo

* chore(docs): mention example file

* chore(examples): fix imports

* chore(examples): fix typo
2022-07-02 19:55:33 -03:00

33 lines
872 B
JavaScript

import Innertube from 'youtubei.js';
const session = await new Innertube();
const comments = await session.getComments('a-rqu-hjobc');
console.info(`This video has ${comments.header.comments_count.toString()} comments.`);
for (const thread of comments.contents) {
const comment = thread.comment;
console.info(
`${comment.author.name}${comment.published}\n`,
`${comment.content.toString()}`, '\n',
`Likes: ${comment.vote_count.short_text}`, '\n'
);
if (comment.reply_count > 0) {
console.info('Replies:', '\n');
const comment_thread = await thread.getReplies();
for (const reply of comment_thread.replies) {
console.info(
`> ${reply.author.name}${reply.published}\n`,
`${reply.content.toString()}`, '\n',
`Likes: ${reply.vote_count.short_text}`, '\n'
);
}
}
console.log('\n');
}