// ============================================================
// TIKTOK DOWNLODER SUPORT SLIDE FOTO + RENDER VIDEO + MP4 /MP3
// GACOR CREATE BY DEPPSEK AI JAILBREK, PENGENDALI AI KIZHCODE
// DI LARANG HPUS WM INI
// ============================================================
const axios = require("axios");
const FormData = require("form-data");
const { CookieJar } = require("tough-cookie");
const cheerio = require("cheerio");
const vm = require("node:vm");
const crypto = require("node:crypto");
const SNAPTIK_BASE = "https://snaptik.app";
const PAGE = `${SNAPTIK_BASE}/en2`;
const API = `${SNAPTIK_BASE}/abc2.php`;
const LANG = "en2";
const UA_MOBILE = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36";
const jar = new CookieJar();
function autoToken() {
const unix = Math.floor(Date.now() / 1000).toString();
return `ey${Buffer.from(unix).toString("base64")}c`;
}
async function saveCookies(res) {
const cookies = res.headers["set-cookie"] || [];
for (const cookie of cookies) {
await jar.setCookie(cookie, SNAPTIK_BASE);
}
}
async function getCookieHeader() {
return jar.getCookieString(SNAPTIK_BASE);
}
function commonHeaders(extra = {}) {
return {
"user-agent": UA_MOBILE,
"accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
"sec-ch-ua": '"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"',
"sec-ch-ua-mobile": "?1",
"sec-ch-ua-platform": '"Android"',
"x-request-id": crypto.randomUUID(),
...extra,
};
}
function extractToken(html) {
const $ = cheerio.load(html);
return $('input[name="token"]').attr("value") || null;
}
async function openHome() {
const res = await axios.get(PAGE, {
timeout: 30000,
validateStatus: () => true,
headers: commonHeaders({
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"upgrade-insecure-requests": "1",
"sec-fetch-site": "none",
"sec-fetch-mode": "navigate",
"sec-fetch-user": "?1",
"sec-fetch-dest": "document",
}),
});
await saveCookies(res);
const html = String(res.data || "");
const token = extractToken(html) || autoToken();
return { status: res.status, token, html };
}
async function submitVideo(url, token) {
const form = new FormData();
form.append("url", url);
form.append("lang", LANG);
form.append("token", token);
const cookie = await getCookieHeader();
const res = await axios.post(API, form, {
timeout: 60000,
validateStatus: () => true,
headers: {
...commonHeaders({
accept: "*/*",
origin: SNAPTIK_BASE,
referer: PAGE,
"sec-fetch-site": "same-origin",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
priority: "u=1, i",
cookie,
}),
...form.getHeaders(),
},
});
await saveCookies(res);
return { status: res.status, body: String(res.data || "") };
}
function decodeObfuscatedResponse(body) {
let decoded = "";
const context = {
console,
Math,
Date,
RegExp,
String,
decodeURIComponent,
escape,
window: { location: { hostname: "snaptik.app" } },
eval(code) {
decoded = String(code || "");
return decoded;
},
};
try {
vm.createContext(context);
vm.runInContext(body, context, { timeout: 3000 });
} catch {}
return decoded || body;
}
async function extractResult(decodedJs) {
const dom = new Map();
const fakeDollar = (selector) => {
if (!dom.has(selector)) {
dom.set(selector, {
innerHTML: "",
style: {},
remove() {},
addClass() {},
removeClass() {},
show() {},
hide() {},
html(value) {
if (value !== undefined) this.innerHTML = String(value);
return this.innerHTML;
},
});
}
return dom.get(selector);
};
const context = {
console,
Math,
Date,
RegExp,
String,
setTimeout,
clearTimeout,
document: {
getElementById() {
return { src: "", style: {} };
},
querySelector() {
return { innerHTML: "", style: {} };
},
},
window: { location: { hostname: "snaptik.app" } },
gtag() {},
fetch: async () => ({ json: async () => ({}) }),
$: fakeDollar,
};
try {
vm.createContext(context);
vm.runInContext(decodedJs, context, { timeout: 3000 });
} catch {}
const html = dom.get("#download")?.innerHTML || decodedJs;
const $ = cheerio.load(html);
const photos = [];
const downloadLinks = [];
let renderToken = null;
$("a[href]").each((_, el) => {
const text = $(el).text().trim().replace(/\s+/g, " ");
let href = $(el).attr("href");
if (!href) return;
if (text.toLowerCase().includes("download with app")) return;
if (text.toLowerCase().includes("download other video")) return;
if (href === "/") return;
if (href.includes("play.google.com")) return;
if (!href.startsWith("http")) {
href = SNAPTIK_BASE + (href.startsWith("/") ? href : "/" + href);
}
if (href.match(/\.(jpg|jpeg|png|webp)(\?|$)/i)) {
photos.push(href);
} else {
downloadLinks.push({ text, url: href });
}
});
renderToken = $(".btn-render").attr("data-token") || null;
return {
title: $(".video-title").first().text().trim() || null,
author: $(".info span").first().text().trim() || null,
thumbnail:
$("#thumbnail").attr("src") ||
$(".avatar").attr("src") ||
$("img").first().attr("src") ||
null,
photos,
downloadLinks,
renderToken,
};
}
async function renderVideo(renderToken) {
if (!renderToken) return null;
const cookie = await getCookieHeader();
const renderRes = await axios.get(`${SNAPTIK_BASE}/render.php`, {
timeout: 30000,
validateStatus: () => true,
params: { token: renderToken },
headers: commonHeaders({ accept: "*/*", referer: PAGE, cookie }),
});
const taskId = renderRes.data?.task_id;
if (!taskId) {
return renderRes.data?.download_url || null;
}
for (let i = 0; i < 30; i++) {
const poll = await axios.get(`${SNAPTIK_BASE}/task.php`, {
timeout: 30000,
validateStatus: () => true,
params: { token: taskId },
headers: commonHeaders({
accept: "*/*",
referer: PAGE,
cookie: await getCookieHeader(),
}),
});
const data = poll.data;
if (data?.download_url) {
return data.download_url;
}
if (data?.status !== 0) {
return null;
}
await new Promise((resolve) => setTimeout(resolve, 3000));
}
return null;
}
async function snaptikSlide(url) {
const home = await openHome();
const post = await submitVideo(url, home.token);
const decoded = decodeObfuscatedResponse(post.body);
const result = await extractResult(decoded);
let renderVideoUrl = null;
if (result.renderToken) {
renderVideoUrl = await renderVideo(result.renderToken);
}
return {
status: post.status === 200,
code: post.status,
input: url,
type: "slide",
title: result.title,
author: result.author,
thumbnail: result.thumbnail,
photos: result.photos,
render_video: renderVideoUrl,
download_links: result.downloadLinks,
};
}
const UA_DESKTOP = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
async function ssstikVideo(url) {
// Resolve short URL
let finalUrl = url;
try {
const redir = await axios.get(url, {
headers: { 'User-Agent': UA_DESKTOP },
maxRedirects: 5,
timeout: 15000,
});
finalUrl = redir.request.res?.responseUrl || url;
} catch (e) {
// fallback
}
// Ambil token dari halaman utama
const mainRes = await axios.get('https://ssstik.io/id', {
headers: { 'User-Agent': UA_DESKTOP, 'Accept': 'text/html' },
timeout: 15000,
});
let token = 'NFFja0Y3';
const tokenMatch = mainRes.data.match(/s_tt\s*=\s*['"]([^'"]+)['"]/);
if (tokenMatch) token = tokenMatch[1];
// Submit
const formData = new URLSearchParams();
formData.append('id', finalUrl);
formData.append('locale', 'id');
formData.append('tt', token);
const postRes = await axios.post('https://ssstik.io/abc?url=dl', formData.toString(), {
headers: {
'User-Agent': UA_DESKTOP,
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
},
timeout: 30000,
});
const html = postRes.data;
const videoMatch = html.match(/href=["'](https:\/\/tikcdn\.io\/ssstik\/\d+\?[^"']+)["']/);
const mp3Match = html.match(/href=["'](https:\/\/tikcdn\.io\/ssstik\/m\/[^"']+)["']/);
const titleMatch = html.match(/<title[^>]*>([^<]*)<\/title>/);
const title = titleMatch ? titleMatch[1].replace(/[^a-z0-9]/gi, '_').substring(0, 50) : null;
return {
status: true,
type: 'video',
title,
video_url: videoMatch ? videoMatch[1] : null,
audio_url: mp3Match ? mp3Match[1] : null,
};
}
// ========== DETEKSI JENIS KONTEN ==========
async function detectType(url) {
try {
const res = await axios.get(url, {
headers: { 'User-Agent': UA_DESKTOP },
maxRedirects: 3,
timeout: 10000,
});
const finalUrl = res.request.res?.responseUrl || url;
return finalUrl.includes('/photo/') ? 'slide' : 'video';
} catch {
return url.includes('photo') ? 'slide' : 'video';
}
}
// ========== FUNGSI UTAMA HYBRID ==========
async function downlodTT(url) {
console.error(`[*] Memproses: ${url}`);
const type = await detectType(url);
console.error(`[*] Tipe terdeteksi: ${type}`);
let result;
if (type === 'slide') {
result = await snaptikSlide(url);
} else {
result = await ssstikVideo(url);
}
console.log(JSON.stringify(result, null, 2));
return result;
}
// contoh make
// downlodTT("https://vt.tiktok.com/ZSQPp5DTx/")
module.exports = { downlodTT };