wukko 1b4872c1de tiktok is back!
- added support for tiktok (images won't work, they're only accessible through the app)
- hopefully main input bar is now not rounded on ios, i fucking hate apple
- if service is not supported, a correlating error will appear, not generic one
- removed duplicates from config that are present in package json already
- tiny bit of clean up
2022-07-28 22:03:17 +06:00

31 lines
1.3 KiB
JavaScript

import got from "got";
import loc from "../../localization/manager.js";
import { genericUserAgent} from "../config.js";
import { unicodeDecode } from "../sub/utils.js";
export default async function(obj) {
try {
if (!obj.postId) {
let html = await got.get(`https://vt.tiktok.com/${obj.id}`, { headers: { "user-agent": genericUserAgent } });
html.on('error', (err) => {
return { error: loc(obj.lang, 'ErrorCantConnectToServiceAPI', 'tiktok') };
});
html = html.body
obj.postId = html.split('video/')[1].split('?')[0]
}
let url = `https://tiktok.com/@video/video/${obj.postId}`
let html = await got.get(url, { headers: { "user-agent": genericUserAgent } });
html.on('error', (err) => {
return { error: loc(obj.lang, 'ErrorCantConnectToServiceAPI', 'tiktok') };
});
html = html.body;
if (html.includes(',"preloadList":[{"url":"')) {
return { urls: unicodeDecode(html.split(',"preloadList":[{"url":"')[1].split('","id":"')[0].trim()), filename: `tiktok_${obj.postId}.mp4` };
} else {
return { error: loc(obj.lang, 'ErrorEmptyDownload') };
}
} catch (e) {
return { error: loc(obj.lang, 'ErrorBadFetch') };
}
}