File size: 2,239 Bytes
1abbfc9
3c8c65c
 
80d66cf
1abbfc9
 
 
 
9392271
34dd4fd
9392271
 
 
 
3c8c65c
 
148bb44
9392271
 
 
 
 
34dd4fd
 
 
80d66cf
 
a6e8cab
 
8b97255
1abbfc9
 
 
b7315c5
67984a3
34dd4fd
80d66cf
 
 
2f695e8
4f6a8fe
80d66cf
4fc5959
a6e8cab
 
1abbfc9
dc8e676
1abbfc9
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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}`);
});