File size: 1,501 Bytes
ce70c6b
3243277
ce70c6b
 
 
 
 
3243277
 
 
ce70c6b
3243277
 
 
ce70c6b
3243277
 
ce70c6b
3243277
 
 
 
ce70c6b
3243277
ce70c6b
3243277
 
 
 
 
ce70c6b
 
3243277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce70c6b
3243277
ce70c6b
 
3243277
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import express from "express"
import fetch from "node-fetch"
import { exec } from "child_process"

const app = express()
const PORT = 7860

function isYouTube(url) {
  return /youtube\.com|youtu\.be/.test(url)
}

app.get("/api/info", async (req, res) => {
  const url = req.query.url
  if (!url) return res.json({ status:false, error:"URL required" })

  // ✅ YOUTUBE → OEMBED
  if (isYouTube(url)) {
    try {
      const r = await fetch(
        `https://www.youtube.com/oembed?url=${url}&format=json`
      )
      const d = await r.json()

      return res.json({
        status: true,
        platform: "youtube",
        title: d.title,
        author: d.author_name,
        author_url: d.author_url,
        thumbnail: d.thumbnail_url
      })
    } catch {
      return res.json({ status:false, error:"YT info failed" })
    }
  }

  // ✅ SOSMED LAIN → yt-dlp
  exec(`yt-dlp -j --no-playlist "${url}"`,
    { maxBuffer: 1024 * 1024 * 10 },
    (err, stdout) => {
      if (err) return res.json({ status:false, error:"Fetch failed" })

      try {
        const d = JSON.parse(stdout)
        res.json({
          status: true,
          platform: d.extractor_key,
          title: d.title,
          duration: d.duration,
          thumbnail: d.thumbnail,
          uploader: d.uploader,
          view_count: d.view_count
        })
      } catch {
        res.json({ status:false, error:"Parse error" })
      }
    }
  )
})

app.listen(PORT, () => console.log("HF INFO API ready"))