Download index.js from Duongkum999/Ins: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/Duongkum999/Ins/resolve/main/index.js
- Command line
-
hf download hf://Duongkum999/Ins/index.js
-
curl -L -o index.js https://huggingface.co/Duongkum999/Ins/resolve/main/index.js
1.96 kB
| const express = require('express'); | |
| const puppeteer = require('puppeteer'); | |
| const path = require('path'); | |
| const app = express(); | |
| const port = 8000; | |
| // Sử dụng middleware express.static để phục vụ các tệp tĩnh từ thư mục 'public' | |
| app.use(express.static(path.join(__dirname, 'public'))); | |
| // Endpoint '/reel' để trích xuất cả video và hình ảnh từ một URL được cung cấp | |
| app.get('/reel', async (req, res) => { | |
| const reelUrl = req.query.url; | |
| try { | |
| // Khởi tạo một trình duyệt Puppeteer với tùy chọn '--no-sandbox' | |
| 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 = []; | |
| // Trích xuất các URL của video | |
| videoElements.forEach(video => { | |
| urls.push({ type: 'video', url: video.src }); | |
| }); | |
| // Trích xuất các URL của hình ảnh và loại bỏ các hình ảnh tỷ lệ 1:1 | |
| 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'); | |
| } | |
| }); | |
| // Lắng nghe các kết nối trên cổng đã được chỉ định | |
| app.listen(port, () => { | |
| console.log(`Server is running at http://localhost:${port}`); | |
| }); | |