changed the way watermarked tiktok videos are downloaded

This commit is contained in:
wukko 2022-10-28 18:32:51 +06:00
parent d49f363dfe
commit c0d78f2b01
2 changed files with 18 additions and 12 deletions

View file

@ -1,7 +1,7 @@
{
"name": "cobalt",
"description": "save what you love",
"version": "4.1",
"version": "4.1.1",
"author": "wukko",
"exports": "./src/cobalt.js",
"type": "module",

View file

@ -41,16 +41,20 @@ export default async function(obj) {
detail = selector(JSON.parse(detail.body), obj.host, obj.postId);
if (!detail) throw new Error()
} catch (e) {
if (obj.host === "tiktok") {
let html = await got.get(`https://tiktok.com/@video/video/${obj.postId}`, { headers: { "user-agent": userAgent } });
html = html.body;
if (html.includes(',"preloadList":[{"url":"')) {
try {
if (obj.host === "tiktok") {
let webAppDetail = await got.get(`https://m.tiktok.com/api/item/detail/?itemId=${obj.postId}`, { headers: { "user-agent": userAgent } });
webAppDetail = JSON.parse(webAppDetail.body);
return {
urls: unicodeDecode(html.split(',"preloadList":[{"url":"')[1].split('","id":"')[0].trim()),
urls: webAppDetail.itemInfo.itemStruct.video.downloadAddr,
filename: `${obj.host}_${obj.postId}_video.mp4`
}
} else throw new Error()
} else throw new Error()
} else {
return { error: loc(obj.lang, 'ErrorCouldntFetch') }
}
} catch (e) {
return { error: loc(obj.lang, 'ErrorCouldntFetch') }
}
}
let video, videoFilename, audioFilename, isMp3, audio, images,
filenameBase = `${obj.host}_${obj.postId}`;
@ -64,10 +68,12 @@ export default async function(obj) {
videoFilename = `${filenameBase}_video_nw.mp4` // nw - no watermark
if (!obj.noWatermark) {
if (obj.host === "tiktok") {
let html = await got.get(`https://tiktok.com/@video/video/${obj.postId}`, { headers: { "user-agent": userAgent } });
html = html.body;
if (html.includes(',"preloadList":[{"url":"')) {
video = unicodeDecode(html.split(',"preloadList":[{"url":"')[1].split('","id":"')[0].trim())
try {
let webAppDetail = await got.get(`https://m.tiktok.com/api/item/detail/?itemId=${obj.postId}`, { headers: { "user-agent": userAgent } });
webAppDetail = JSON.parse(webAppDetail.body);
video = webAppDetail.itemInfo.itemStruct.video.downloadAddr;
} catch (e) {
video = detail["video"]["download_addr"]["url_list"][0]
}
} else {
video = detail['video']['play_addr']['url_list'][0]