api/vimeo: add subtitle parsing from the mobile api

This commit is contained in:
wukko 2025-06-20 18:21:00 +06:00
parent a5838f3c05
commit a44bea6b50
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 25 additions and 3 deletions

View File

@ -145,7 +145,9 @@ export default function({
case "vimeo":
if (Array.isArray(r.urls)) {
params = { type: "merge" }
params = { type: "merge" };
} else if (r.subtitles) {
params = { type: "remux" };
} else {
responseType = "redirect";
}

View File

@ -167,6 +167,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
password: patternMatch.password,
quality: params.videoQuality,
isAudioOnly,
subtitleLang,
});
break;

View File

@ -40,7 +40,7 @@ const compareQuality = (rendition, requestedQuality) => {
return Math.abs(quality - requestedQuality);
}
const getDirectLink = (data, quality) => {
const getDirectLink = async (data, quality, subtitleLang) => {
if (!data.files) return;
const match = data.files
@ -56,8 +56,23 @@ const getDirectLink = (data, quality) => {
if (!match) return;
let subtitles;
if (subtitleLang && data.config_url) {
const config = await fetch(data.config_url)
.then(r => r.json())
.catch(() => {});
if (config && config.request?.text_tracks?.length) {
subtitles = config.request.text_tracks.find(
t => t.lang.startsWith(subtitleLang)
);
subtitles = new URL(subtitles.url, "https://player.vimeo.com/").toString();
}
}
return {
urls: match.link,
subtitles,
filenameAttributes: {
resolution: `${match.width}x${match.height}`,
qualityLabel: match.rendition,
@ -143,7 +158,7 @@ export default async function(obj) {
response = await getHLS(info.config_url, { ...obj, quality });
}
if (!response) response = getDirectLink(info, quality);
if (!response) response = await getDirectLink(info, quality, obj.subtitleLang);
if (!response) response = { error: "fetch.empty" };
if (response.error) {
@ -155,6 +170,10 @@ export default async function(obj) {
artist: info.user.name,
};
if (response.subtitles) {
fileMetadata.sublanguage = obj.subtitleLang;
}
return merge(
{
fileMetadata,