Files
ContentGen_BE/test-service.js
T
Harun CAN a40619ef33
Backend Deploy 🚀 / build-and-deploy (push) Has been cancelled
main
2026-05-06 10:48:07 +02:00

50 lines
1.5 KiB
JavaScript

const { YoutubeToolsService } = require('./dist/modules/youtube-tools/youtube-tools.service');
// We need to mock Prisma and Logger
const mockPrisma = {
youtubeAnalysis: {
create: async (data) => console.log('Saved to DB')
}
};
const mockLogger = { log: console.log, error: console.error };
async function test() {
const service = new YoutubeToolsService(mockPrisma);
service.logger = mockLogger;
// We can't easily inject the whole nest app, but we can just copy the comment extraction logic
const { Innertube } = require('youtubei.js');
const youtubeClient = await Innertube.create({ lang: 'tr', location: 'TR' });
const videoId = 'ix8cLltPCCE';
const commentThread = await youtubeClient.getComments(videoId);
let comments = [];
if (commentThread.contents) {
for (const thread of commentThread.contents) {
if (thread.comment?.content?.text) {
comments.push(thread.comment.content.text);
}
}
}
let currentThread = commentThread;
let pages = 0;
while (currentThread.has_continuation && comments.length < 5000 && pages < 250) {
pages++;
const next = await currentThread.getContinuation();
if (next.contents) {
for (const thread of next.contents) {
if (thread.comment?.content?.text) {
comments.push(thread.comment.content.text);
}
}
}
currentThread = next;
}
console.log('Total fetched by logic:', comments.length);
}
test().catch(console.error);