Back to Home
Gistify Snippet
kyiov
13h ago·1 file(s)
Public

TikTok Video & Slide Image Downloader

TikTok downloader scraper extracting watermark-free video, audio, and photo slide albums with base64 decoding.

#scraper#tiktok#downloader#media#javascript
0
Raw
tiktokdl.jsjavascript
110 lines
1// tiktokdl.js — bundle standalone. npm deps: axios, node:url
2
3/**
4 * Scraper: tiktokdl.js
5 * Source : kyioapi/tiktokdl.js
6 *
7 * Input : Function parameters / CLI args (e.g. query: string, url: string, options: object)
8 * Output : Promise<Object | Array | Buffer> (JSON formatted scraping response / stream URL / media metadata)
9 *
10 * CLI Run:
11 * node kyioapi/tiktokdl.js [functionName] [args...]
12 * node cli.js kyioapi/tiktokdl.js [functionName] [args...]
13 */
14
15import * as __ns_393 from 'axios'
16const axios = __ns_393.default
17import * as __ns_394 from 'node:url'
18const pathToFileURL = __ns_394.pathToFileURL
19
20
21
22const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
23
24/**
25 * TikTok Downloader Scraper
26 * Base: tiktokdl.web.id
27 * Returns direct media links decoded from base64 IDs.
28 */
29async function tiktokdl(url) {
30 try {
31 const headers = {
32 "User-Agent": userAgent,
33 "Accept": "application/json",
34 "Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8"
35 };
36
37 const apiUrl = `https://tiktokdl.web.id/api/tiktok?url=${encodeURIComponent(url)}`;
38
39 const response = await axios.get(apiUrl, {
40 headers,
41 timeout: 30000
42 });
43
44 const data = response.data;
45
46 if (!data.status) {
47 return {
48 status: false,
49 message: data.message || "Gagal memproses URL TikTok"
50 };
51 }
52
53 const decode = (str) => {
54 try { return Buffer.from(str, 'base64').toString(); } catch (e) { return null; }
55 };
56
57 const result = {
58 status: true,
59 author: data.author || "Unknown",
60 description: data.description || "TikTok Download",
61 isSlide: data.isSlide || false,
62 video: data.videoId ? decode(data.videoId) : null,
63 audio: data.audioId ? decode(data.audioId) : null,
64 images: []
65 };
66
67 if (data.imageIds && data.imageIds.length > 0) {
68 result.images = data.imageIds.map(id => decode(id)).filter(Boolean);
69 }
70
71 return result;
72
73 } catch (e) {
74 throw new Error("Gagal terhubung ke server TikTokDL");
75 }
76}
77
78// ─────────────────────────────────────────────────────────────────────
79// Self-test: jalankan langsung dengan `node tiktokdl.js [args...]`
80// ─────────────────────────────────────────────────────────────────────
81if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
82 const __exports = { tiktokdl: tiktokdl }
83 const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function'))
84 const __names = Object.keys(__fns)
85 if (__names.length === 0) {
86 console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.')
87 } else {
88 const __search = __names.find((n) => /search|cari/i.test(n))
89 const __name = __search || __names[0]
90 const __fn = __fns[__name]
91 const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn))
92 let __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } })
93 if (__args.length === 0 && __search) __args.push('naruto')
94 if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) {
95 console.log('Fungsi: ' + __names.join(', '))
96 console.log('Contoh: node ' + "tiktokdl.js" + ' ' + __name + ' <arg>')
97 } else {
98 ;(async () => {
99 try {
100 const r = __isClass ? new __fn(...__args) : await __fn(...__args)
101 console.log(JSON.stringify(r, null, 2))
102 } catch (e) {
103 console.error('Error: ' + (e && e.message ? e.message : e))
104 process.exitCode = 1
105 }
106 })()
107 }
108 }
109}
110
Discussion & Comments0

No comments yet — be the first to leave feedback or start a code discussion.

Sign in with your GitHub account to write comments and join the discussion.