changed the way watermarked tiktok videos are downloaded
This commit is contained in:
parent
d49f363dfe
commit
c0d78f2b01
2 changed files with 18 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "cobalt",
|
"name": "cobalt",
|
||||||
"description": "save what you love",
|
"description": "save what you love",
|
||||||
"version": "4.1",
|
"version": "4.1.1",
|
||||||
"author": "wukko",
|
"author": "wukko",
|
||||||
"exports": "./src/cobalt.js",
|
"exports": "./src/cobalt.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
@ -41,16 +41,20 @@ export default async function(obj) {
|
||||||
detail = selector(JSON.parse(detail.body), obj.host, obj.postId);
|
detail = selector(JSON.parse(detail.body), obj.host, obj.postId);
|
||||||
if (!detail) throw new Error()
|
if (!detail) throw new Error()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (obj.host === "tiktok") {
|
try {
|
||||||
let html = await got.get(`https://tiktok.com/@video/video/${obj.postId}`, { headers: { "user-agent": userAgent } });
|
if (obj.host === "tiktok") {
|
||||||
html = html.body;
|
let webAppDetail = await got.get(`https://m.tiktok.com/api/item/detail/?itemId=${obj.postId}`, { headers: { "user-agent": userAgent } });
|
||||||
if (html.includes(',"preloadList":[{"url":"')) {
|
webAppDetail = JSON.parse(webAppDetail.body);
|
||||||
return {
|
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`
|
filename: `${obj.host}_${obj.postId}_video.mp4`
|
||||||
}
|
}
|
||||||
} else throw new Error()
|
} else {
|
||||||
} else throw new Error()
|
return { error: loc(obj.lang, 'ErrorCouldntFetch') }
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { error: loc(obj.lang, 'ErrorCouldntFetch') }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let video, videoFilename, audioFilename, isMp3, audio, images,
|
let video, videoFilename, audioFilename, isMp3, audio, images,
|
||||||
filenameBase = `${obj.host}_${obj.postId}`;
|
filenameBase = `${obj.host}_${obj.postId}`;
|
||||||
|
@ -64,10 +68,12 @@ export default async function(obj) {
|
||||||
videoFilename = `${filenameBase}_video_nw.mp4` // nw - no watermark
|
videoFilename = `${filenameBase}_video_nw.mp4` // nw - no watermark
|
||||||
if (!obj.noWatermark) {
|
if (!obj.noWatermark) {
|
||||||
if (obj.host === "tiktok") {
|
if (obj.host === "tiktok") {
|
||||||
let html = await got.get(`https://tiktok.com/@video/video/${obj.postId}`, { headers: { "user-agent": userAgent } });
|
try {
|
||||||
html = html.body;
|
let webAppDetail = await got.get(`https://m.tiktok.com/api/item/detail/?itemId=${obj.postId}`, { headers: { "user-agent": userAgent } });
|
||||||
if (html.includes(',"preloadList":[{"url":"')) {
|
webAppDetail = JSON.parse(webAppDetail.body);
|
||||||
video = unicodeDecode(html.split(',"preloadList":[{"url":"')[1].split('","id":"')[0].trim())
|
video = webAppDetail.itemInfo.itemStruct.video.downloadAddr;
|
||||||
|
} catch (e) {
|
||||||
|
video = detail["video"]["download_addr"]["url_list"][0]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
video = detail['video']['play_addr']['url_list'][0]
|
video = detail['video']['play_addr']['url_list'][0]
|
||||||
|
|
Loading…
Reference in a new issue