Update server.js
Browse files
server.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const ytdl = require('@distube/ytdl-core');
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
const PORT = 7860;
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
const xml = await res.text();
|
| 15 |
-
return xml.match(/<text[^>]*>(.*?)<\/text>/g).map(t => t.replace(/<[^>]+>/g, ''));
|
| 16 |
-
}
|
| 17 |
|
| 18 |
app.get('/transcript', async (req, res) => {
|
| 19 |
const { url } = req.query;
|
| 20 |
if (!url) return res.status(400).json({ error: 'Missing video URL' });
|
| 21 |
try {
|
| 22 |
-
const
|
| 23 |
-
res.json(
|
| 24 |
} catch (error) {
|
| 25 |
console.log(error);
|
| 26 |
res.status(500).json({ error: 'Failed to fetch transcript' });
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const ytdl = require('@distube/ytdl-core');
|
| 3 |
+
const cheerio = require('cheerio');
|
| 4 |
+
const axios = require('axios');
|
| 5 |
|
| 6 |
const app = express();
|
| 7 |
const PORT = 7860;
|
| 8 |
|
| 9 |
+
|
| 10 |
+
async function transcript(url) {
|
| 11 |
+
const response = await axios.post( 'https://youtubetotranscript.com/transcript', new URLSearchParams({ youtube_url: url }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } );
|
| 12 |
+
const html = response.data;
|
| 13 |
+
const $ = cheerio.load(html); const texts = $('.transcript-segment').map((i, el) => $(el).text().trim()).get();
|
| 14 |
+
};
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
app.get('/transcript', async (req, res) => {
|
| 17 |
const { url } = req.query;
|
| 18 |
if (!url) return res.status(400).json({ error: 'Missing video URL' });
|
| 19 |
try {
|
| 20 |
+
const rttex = await transcript(url);
|
| 21 |
+
res.json(rttex);
|
| 22 |
} catch (error) {
|
| 23 |
console.log(error);
|
| 24 |
res.status(500).json({ error: 'Failed to fetch transcript' });
|