generated from fahricansecer/boilerplate-be
@@ -0,0 +1,34 @@
|
||||
const { Innertube } = require('youtubei.js');
|
||||
|
||||
async function test() {
|
||||
const youtube = await Innertube.create({ lang: 'tr', location: 'TR' });
|
||||
const videoId = 'ix8cLltPCCE';
|
||||
console.log('Fetching comments for', videoId);
|
||||
const commentThread = await youtube.getComments(videoId);
|
||||
|
||||
let comments = [];
|
||||
let currentThread = commentThread;
|
||||
let pages = 0;
|
||||
|
||||
while (currentThread) {
|
||||
if (currentThread.contents) {
|
||||
for (const thread of currentThread.contents) {
|
||||
if (thread.comment?.content?.text) {
|
||||
comments.push(thread.comment.content.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentThread.has_continuation && pages < 50) {
|
||||
pages++;
|
||||
currentThread = await currentThread.getContinuation();
|
||||
console.log('Page', pages, 'Total so far:', comments.length);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Total comments fetched:', comments.length);
|
||||
}
|
||||
|
||||
test().catch(console.error);
|
||||
Reference in New Issue
Block a user