File size: 1,633 Bytes
4c23b55
 
b578104
4c23b55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b578104
4c23b55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b578104
4c23b55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
import express from "express";
import axios from "axios";
import * as cheerio from "cheerio";
import cors from "cors";

const app = express();
app.use(cors());

app.get("/", (req, res) => {
  res.json({
    status: "TikTok Standalone API by Muhammad Farel",
    usage: "/api?url=LINK_TIKTOK"
  });
});

app.get("/api", async (req, res) => {
  const url = req.query.url;
  if (!url) return res.json({ error: "Masukkan parameter ?url=" });

  try {
    const html = await axios.get(url, {
      headers: { "User-Agent": "Mozilla/5.0" }
    });

    const $ = cheerio.load(html.data);
    const raw = $("#SIGI_STATE").html();

    if (!raw) return res.json({ error: "Gagal membaca SIGI_STATE" });

    const data = JSON.parse(raw);

    const videoId = Object.keys(data.ItemModule)[0];
    const item = data.ItemModule[videoId];

    if (!item) return res.json({ error: "Video tidak ditemukan" });

    const withWM = item.video.downloadAddr;
    const noWM = item.video.downloadAddr.replace("watermark=1", "watermark=0");
    const music = item.music.playUrl;

    res.json({
      status: "success",
      author: item.author,
      username: item.author,
      title: item.desc,
      cover: item.cover,
      duration: item.video.duration,
      resolution: `${item.video.height}x${item.video.width}`,
      video: {
        no_watermark: noWM,
        watermark: withWM
      },
      audio: music,
      raw: item
    });

  } catch (err) {
    res.json({
      error: "Terjadi kesalahan saat scrape",
      detail: err.message
    });
  }
});

const PORT = 7860;
app.listen(PORT, () => console.log("API berjalan di port", PORT));