const express = require('express'); const cheerio = require('cheerio'); const axios = require('axios'); const FormData = require('form-data'); const app = express(); const PORT = 7860; async function transcript(url) { /*const response = await axios.post( 'https://youtubetotranscript.com/transcript', new URLSearchParams({ youtube_url: url }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ); const html = response.data; const $ = cheerio.load(html); const text = $('.transcript-segment') .map((i, el) => $(el).text().trim()) .get() .join(' '); return text;*/ const { data } = await axios.get(`https://fastrestapis.fasturl.cloud/tool/yt-transcript?url=${encodeURIComponent(url)}`); return data?.status === 200 ? data?.result : undefined; }; const countWords = str => str.split(/\s+/).filter(Boolean).length; app.get('/summary', async (req, res) => { const { url } = req.query; if (!url) return res.status(400).json({ error: 'Missing video URL' }); try { const rttex = await transcript(url); const prompt = `INPUT: ${rttex}`; const sysp = `You are an advanced AI designed for high-quality summarization. Your task is to generate precise, concise, and accurate summaries, extracting only the essential information while maintaining clarity. Do not include explanations, opinions, or unnecessary details. Ensure the summary is in the same language as the input. Dont use any symbol, max words 150, to the point.`; const form = new FormData(); form.append('content', `${sysp}\n${prompt}`); form.append('model', '@google/gemini-2.0-pro-exp-02-05'); //form.append('system', 'Use "-" for list, use "_" for italic, dont use LaTeX') const { data } = await axios.post('https://mind.hydrooo.web.id/v2/chat', form, { headers: form.getHeaders() }); const rres = data?.result?.messages[0]?.content?.trim(); res.json({ status: true, words: countWords(rres), summary: rres }) } catch (error) { console.log(error); res.status(500).json({ error: 'Failed to fetch transcript' }); } }); app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); });