| const express = require("express"); |
| const { yt, tiktok, instagram, threads, twitter } = require('./lib/yt.js'); |
|
|
| const app = express(); |
| app.use(express.json()); |
| app.set('json spaces', 4); |
|
|
| app.all('/dl/start', async (req, res) => { |
| const { url, typeYT = 'mp3' } = req.query || req.body; |
| if(/^https?:\/\/(?:www\.)?(?:youtube\.com\/(?:embed\/|v\/|watch\?v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/.test(url)) { |
| if(!['mp3', 'mp4'].includes(typeYT)) return res.json({ status: false, r: 'invalid type, use mp3 or mp4.' }); |
| const ytr = await yt(url, typeYT); |
| res.json({ status: true, ...ytr }); |
| } else if(/^https?:\/\/(?:www\.)?(?:twitter|x)\.com\/(?:i\/web\/status|[^\/]+\/status)\/(\d+)/.test(url)) { |
| const xr = await twitter(url); |
| res.json(xr); |
| } else if(/^https?:\/\/(?:www\.)?(?:tiktok\.com\/(?:@[^\/]+\/video|t)\/|vt\.tiktok\.com\/)([a-zA-Z0-9]+)/.test(url)) { |
| const ttr = await tiktok(url); |
| res.json(ttr); |
| } else if(/^https?:\/\/(?:www\.)?instagram\.com\/(?:reel|p|tv)\/([a-zA-Z0-9_-]+)/.test(url)) { |
| const igr = await instagram(url); |
| res.json({ status: true, ...igr }); |
| } else if(/^https?:\/\/(?:www\.)?facebook\.com\/(?:watch\/\?v=|reels\/|[^\/]+\/videos\/)(\d+)/.test(url)) { |
| |
| } else if(/^https?:\/\/(?:www\.)?threads\.net\/@[^\/]+\/post\/([a-zA-Z0-9_-]+)/.test(url)) { |
| const thr = await threads(url); |
| res.json(thr); |
| } else { |
| res.json({ status: false, r: 'not supported' }); |
| } |
| }); |
|
|
| const PORT = 7860; |
| app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); |