const express = require('express'); const puppeteer = require('puppeteer'); const path = require('path'); const app = express(); const port = 7860; app.use(express.static(path.join(__dirname, 'public'))); app.get('/reel', async (req, res) => { const reelUrl = req.query.url; try { const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); await page.goto(reelUrl, { waitUntil: 'networkidle2' }); const mediaUrls = await page.evaluate(() => { const videoElements = document.querySelectorAll('video'); const imageElements = document.querySelectorAll('img'); const urls = []; videoElements.forEach(video => { urls.push({ type: 'video', url: video.src }); }); imageElements.forEach(image => { if (image.naturalWidth / image.naturalHeight !== 1) { urls.push({ type: 'image', url: image.src }); } }); return urls; }); await browser.close(); res.json(mediaUrls); } catch (error) { console.error('Error:', error); res.status(500).send('Internal Server Error'); } }); app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); });