Spaces:
Build error
Build error
Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from "express"
|
| 2 |
+
import { exec } from "child_process"
|
| 3 |
+
|
| 4 |
+
const app = express()
|
| 5 |
+
const PORT = 7860
|
| 6 |
+
|
| 7 |
+
app.get("/api/info", (req, res) => {
|
| 8 |
+
const url = req.query.url
|
| 9 |
+
if (!url) {
|
| 10 |
+
return res.status(400).json({
|
| 11 |
+
status: false,
|
| 12 |
+
error: "URL is required"
|
| 13 |
+
})
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
const cmd = `yt-dlp -j --no-playlist "${url}"`
|
| 17 |
+
|
| 18 |
+
exec(cmd, { maxBuffer: 1024 * 1024 * 10 }, (err, stdout) => {
|
| 19 |
+
if (err) {
|
| 20 |
+
return res.json({
|
| 21 |
+
status: false,
|
| 22 |
+
error: "Failed to fetch info"
|
| 23 |
+
})
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
try {
|
| 27 |
+
const data = JSON.parse(stdout)
|
| 28 |
+
|
| 29 |
+
res.json({
|
| 30 |
+
status: true,
|
| 31 |
+
platform: data.extractor_key,
|
| 32 |
+
title: data.title,
|
| 33 |
+
description: data.description,
|
| 34 |
+
duration: data.duration,
|
| 35 |
+
duration_string: data.duration_string,
|
| 36 |
+
thumbnail: data.thumbnail,
|
| 37 |
+
uploader: data.uploader,
|
| 38 |
+
uploader_url: data.uploader_url,
|
| 39 |
+
view_count: data.view_count,
|
| 40 |
+
like_count: data.like_count,
|
| 41 |
+
comment_count: data.comment_count,
|
| 42 |
+
upload_date: data.upload_date,
|
| 43 |
+
formats_available: data.formats
|
| 44 |
+
?.filter(f => f.height)
|
| 45 |
+
.map(f => `${f.height}p`)
|
| 46 |
+
.filter((v, i, a) => a.indexOf(v) === i)
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
} catch {
|
| 50 |
+
res.json({
|
| 51 |
+
status: false,
|
| 52 |
+
error: "Invalid response"
|
| 53 |
+
})
|
| 54 |
+
}
|
| 55 |
+
})
|
| 56 |
+
})
|
| 57 |
+
|
| 58 |
+
app.listen(PORT, () => {
|
| 59 |
+
console.log("INFO API running on port", PORT)
|
| 60 |
+
})
|