mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-14 17:28:27 +00:00
fix tiktok downloads
This commit is contained in:
parent
ad0846ac73
commit
ce828adde1
@ -1,23 +1,22 @@
|
|||||||
import got from "got";
|
import got from "got";
|
||||||
import loc from "../../localization/manager.js";
|
import loc from "../../localization/manager.js";
|
||||||
import { genericUserAgent } from "../config.js";
|
|
||||||
import { unicodeDecode } from "../sub/utils.js";
|
import { unicodeDecode } from "../sub/utils.js";
|
||||||
|
|
||||||
let userAgent = genericUserAgent.split(' Chrome/1')[0]
|
let userAgent = "Mozilla/5.0 (Linux; Android 10; Pixel 4 XL)"
|
||||||
let config = {
|
let config = {
|
||||||
tiktok: {
|
tiktok: {
|
||||||
short: "https://vt.tiktok.com/",
|
short: "https://vt.tiktok.com/",
|
||||||
api: "https://api.tiktokv.com/aweme/v1/aweme/detail/?aweme_id=",
|
api: "https://api.tiktokv.com/aweme/v1/feed/?version_code=2613&device_type=pixel?aweme_id=",
|
||||||
},
|
},
|
||||||
douyin: {
|
douyin: {
|
||||||
short: "https://v.douyin.com/",
|
short: "https://v.douyin.com/",
|
||||||
api: "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=",
|
api: "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=",
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
function selector(j, h) {
|
function selector(j, h) {
|
||||||
switch (h) {
|
switch (h) {
|
||||||
case "tiktok":
|
case "tiktok":
|
||||||
return j["aweme_detail"]
|
return j["aweme_list"][0];
|
||||||
case "douyin":
|
case "douyin":
|
||||||
return j['item_list'][0]
|
return j['item_list'][0]
|
||||||
}
|
}
|
||||||
@ -34,13 +33,11 @@ export default async function(obj) {
|
|||||||
if (html.slice(0, 17) === '<a href="https://' && html.includes('/video/')) obj.postId = html.split('video/')[1].split('?')[0].replace("/", '')
|
if (html.slice(0, 17) === '<a href="https://' && html.includes('/video/')) obj.postId = html.split('video/')[1].split('?')[0].replace("/", '')
|
||||||
}
|
}
|
||||||
if (!obj.postId) return { error: loc(obj.lang, 'ErrorCantGetID') };
|
if (!obj.postId) return { error: loc(obj.lang, 'ErrorCantGetID') };
|
||||||
|
let detail = await got.get(`${config[obj.host]["api"]}${obj.postId}`, { headers: { "user-agent": userAgent } });
|
||||||
let detail = await got.get(`${config[obj.host]["api"]}${obj.postId}`);
|
|
||||||
detail.on('error', (err) => {
|
detail.on('error', (err) => {
|
||||||
return { error: loc(obj.lang, 'ErrorCantConnectToServiceAPI', obj.host) };
|
return { error: loc(obj.lang, 'ErrorCantConnectToServiceAPI', obj.host) };
|
||||||
});
|
});
|
||||||
detail = selector(JSON.parse(detail.body), obj.host);
|
detail = selector(JSON.parse(detail.body), obj.host);
|
||||||
|
|
||||||
let video, videoFilename, audioFilename, isMp3, audio,
|
let video, videoFilename, audioFilename, isMp3, audio,
|
||||||
images = detail["image_post_info"] ? detail["image_post_info"]["images"] : false,
|
images = detail["image_post_info"] ? detail["image_post_info"]["images"] : false,
|
||||||
filenameBase = `${obj.host}_${obj.postId}`;
|
filenameBase = `${obj.host}_${obj.postId}`;
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
"tiktok": {
|
"tiktok": {
|
||||||
"patterns": [":user/video/:postId", ":id", "t/:id"],
|
"patterns": [":user/video/:postId", ":id", "t/:id"],
|
||||||
"audioFormats": ["best", "m4a", "mp3"],
|
"audioFormats": ["best", "m4a", "mp3"],
|
||||||
"enabled": false
|
"enabled": true
|
||||||
},
|
},
|
||||||
"douyin": {
|
"douyin": {
|
||||||
"patterns": ["video/:postId", ":id"],
|
"patterns": ["video/:postId", ":id"],
|
||||||
|
Loading…
Reference in New Issue
Block a user