api/tiktok: add support for subtitles

This commit is contained in:
wukko 2025-06-20 20:07:50 +06:00
parent aff2d22edc
commit 630e4a6e0d
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 23 additions and 1 deletions

View File

@ -169,9 +169,14 @@ export default function({
} }
break; break;
case "tiktok":
params = {
type: r.subtitles ? "remux" : "proxy"
};
break;
case "ok": case "ok":
case "vk": case "vk":
case "tiktok":
case "xiaohongshu": case "xiaohongshu":
params = { type: "proxy" }; params = { type: "proxy" };
break; break;

View File

@ -150,6 +150,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
isAudioOnly, isAudioOnly,
h265: params.allowH265, h265: params.allowH265,
alwaysProxy: params.alwaysProxy, alwaysProxy: params.alwaysProxy,
subtitleLang,
}); });
break; break;

View File

@ -4,6 +4,7 @@ import { extract, normalizeURL } from "../url.js";
import { genericUserAgent } from "../../config.js"; import { genericUserAgent } from "../../config.js";
import { updateCookie } from "../cookie/manager.js"; import { updateCookie } from "../cookie/manager.js";
import { createStream } from "../../stream/manage.js"; import { createStream } from "../../stream/manage.js";
import { convertLanguageCode } from "../../misc/language-codes.js";
const shortDomain = "https://vt.tiktok.com/"; const shortDomain = "https://vt.tiktok.com/";
@ -97,8 +98,23 @@ export default async function(obj) {
} }
if (video) { if (video) {
let subtitles, fileMetadata;
if (obj.subtitleLang && detail?.video?.subtitleInfos?.length) {
const langCode = convertLanguageCode(obj.subtitleLang);
const subtitle = detail?.video?.subtitleInfos.find(
s => s.LanguageCodeName.startsWith(langCode) && s.Format === "webvtt"
)
if (subtitle) {
subtitles = subtitle.Url;
fileMetadata = {
sublanguage: langCode,
}
}
}
return { return {
urls: video, urls: video,
subtitles,
fileMetadata,
filename: videoFilename, filename: videoFilename,
headers: { cookie } headers: { cookie }
} }