Skip to content

best way to save what you love

api/tiktok: add support for subtitles

wukko630e4a6e0d0c
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 }
}