// tiktokdl.js — bundle standalone. npm deps: axios, node:url /** * Scraper: tiktokdl.js * Source : kyioapi/tiktokdl.js * * Input : Function parameters / CLI args (e.g. query: string, url: string, options: object) * Output : Promise (JSON formatted scraping response / stream URL / media metadata) * * CLI Run: * node kyioapi/tiktokdl.js [functionName] [args...] * node cli.js kyioapi/tiktokdl.js [functionName] [args...] */ import * as __ns_393 from 'axios' const axios = __ns_393.default import * as __ns_394 from 'node:url' const pathToFileURL = __ns_394.pathToFileURL const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"; /** * TikTok Downloader Scraper * Base: tiktokdl.web.id * Returns direct media links decoded from base64 IDs. */ async function tiktokdl(url) { try { const headers = { "User-Agent": userAgent, "Accept": "application/json", "Accept-Language": "id-ID,id;q=0.9,en-US;q=0.8" }; const apiUrl = `https://tiktokdl.web.id/api/tiktok?url=${encodeURIComponent(url)}`; const response = await axios.get(apiUrl, { headers, timeout: 30000 }); const data = response.data; if (!data.status) { return { status: false, message: data.message || "Gagal memproses URL TikTok" }; } const decode = (str) => { try { return Buffer.from(str, 'base64').toString(); } catch (e) { return null; } }; const result = { status: true, author: data.author || "Unknown", description: data.description || "TikTok Download", isSlide: data.isSlide || false, video: data.videoId ? decode(data.videoId) : null, audio: data.audioId ? decode(data.audioId) : null, images: [] }; if (data.imageIds && data.imageIds.length > 0) { result.images = data.imageIds.map(id => decode(id)).filter(Boolean); } return result; } catch (e) { throw new Error("Gagal terhubung ke server TikTokDL"); } } // ───────────────────────────────────────────────────────────────────── // Self-test: jalankan langsung dengan `node tiktokdl.js [args...]` // ───────────────────────────────────────────────────────────────────── if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { const __exports = { tiktokdl: tiktokdl } const __fns = Object.fromEntries(Object.entries(__exports).filter(([, v]) => typeof v === 'function')) const __names = Object.keys(__fns) if (__names.length === 0) { console.log('Tidak ada fungsi yang bisa di-demo. Import modul ini dari kode lain.') } else { const __search = __names.find((n) => /search|cari/i.test(n)) const __name = __search || __names[0] const __fn = __fns[__name] const __isClass = /^class\s/.test(Function.prototype.toString.call(__fn)) let __args = process.argv.slice(2).map((a) => { try { return JSON.parse(a) } catch { return a } }) if (__args.length === 0 && __search) __args.push('naruto') if (__args.length === 0 && !__search && !__isClass && __fn.length > 0) { console.log('Fungsi: ' + __names.join(', ')) console.log('Contoh: node ' + "tiktokdl.js" + ' ' + __name + ' ') } else { ;(async () => { try { const r = __isClass ? new __fn(...__args) : await __fn(...__args) console.log(JSON.stringify(r, null, 2)) } catch (e) { console.error('Error: ' + (e && e.message ? e.message : e)) process.exitCode = 1 } })() } } }