From 630e4a6e0d0c81ffa27d5c559ddc53c22b240b82 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 20 Jun 2025 20:07:50 +0600 Subject: [PATCH] api/tiktok: add support for subtitles --- api/src/processing/match-action.js | 7 ++++++- api/src/processing/match.js | 1 + api/src/processing/services/tiktok.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/src/processing/match-action.js b/api/src/processing/match-action.js index 0124d208..f8cc39a9 100644 --- a/api/src/processing/match-action.js +++ b/api/src/processing/match-action.js @@ -169,9 +169,14 @@ export default function({ } break; + case "tiktok": + params = { + type: r.subtitles ? "remux" : "proxy" + }; + break; + case "ok": case "vk": - case "tiktok": case "xiaohongshu": params = { type: "proxy" }; break; diff --git a/api/src/processing/match.js b/api/src/processing/match.js index 220d9593..1d91f327 100644 --- a/api/src/processing/match.js +++ b/api/src/processing/match.js @@ -150,6 +150,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey isAudioOnly, h265: params.allowH265, alwaysProxy: params.alwaysProxy, + subtitleLang, }); break; diff --git a/api/src/processing/services/tiktok.js b/api/src/processing/services/tiktok.js index 93e07c50..4524596d 100644 --- a/api/src/processing/services/tiktok.js +++ b/api/src/processing/services/tiktok.js @@ -4,6 +4,7 @@ import { extract, normalizeURL } from "../url.js"; import { genericUserAgent } from "../../config.js"; import { updateCookie } from "../cookie/manager.js"; import { createStream } from "../../stream/manage.js"; +import { convertLanguageCode } from "../../misc/language-codes.js"; const shortDomain = "https://vt.tiktok.com/"; @@ -97,8 +98,23 @@ export default async function(obj) { } 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 { urls: video, + subtitles, + fileMetadata, filename: videoFilename, headers: { cookie } }