Skip to content

Commit a44bea6

Browse files
committed
api/vimeo: add subtitle parsing from the mobile api
1 parent a5838f3 commit a44bea6

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

api/src/processing/match-action.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ export default function({
145145

146146
case "vimeo":
147147
if (Array.isArray(r.urls)) {
148-
params = { type: "merge" }
148+
params = { type: "merge" };
149+
} else if (r.subtitles) {
150+
params = { type: "remux" };
149151
} else {
150152
responseType = "redirect";
151153
}

api/src/processing/match.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
167167
password: patternMatch.password,
168168
quality: params.videoQuality,
169169
isAudioOnly,
170+
subtitleLang,
170171
});
171172
break;
172173

api/src/processing/services/vimeo.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const compareQuality = (rendition, requestedQuality) => {
4040
return Math.abs(quality - requestedQuality);
4141
}
4242

43-
const getDirectLink = (data, quality) => {
43+
const getDirectLink = async (data, quality, subtitleLang) => {
4444
if (!data.files) return;
4545

4646
const match = data.files
@@ -56,8 +56,23 @@ const getDirectLink = (data, quality) => {
5656

5757
if (!match) return;
5858

59+
let subtitles;
60+
if (subtitleLang && data.config_url) {
61+
const config = await fetch(data.config_url)
62+
.then(r => r.json())
63+
.catch(() => {});
64+
65+
if (config && config.request?.text_tracks?.length) {
66+
subtitles = config.request.text_tracks.find(
67+
t => t.lang.startsWith(subtitleLang)
68+
);
69+
subtitles = new URL(subtitles.url, "https://player.vimeo.com/").toString();
70+
}
71+
}
72+
5973
return {
6074
urls: match.link,
75+
subtitles,
6176
filenameAttributes: {
6277
resolution: `${match.width}x${match.height}`,
6378
qualityLabel: match.rendition,
@@ -143,7 +158,7 @@ export default async function(obj) {
143158
response = await getHLS(info.config_url, { ...obj, quality });
144159
}
145160

146-
if (!response) response = getDirectLink(info, quality);
161+
if (!response) response = await getDirectLink(info, quality, obj.subtitleLang);
147162
if (!response) response = { error: "fetch.empty" };
148163

149164
if (response.error) {
@@ -155,6 +170,10 @@ export default async function(obj) {
155170
artist: info.user.name,
156171
};
157172

173+
if (response.subtitles) {
174+
fileMetadata.sublanguage = obj.subtitleLang;
175+
}
176+
158177
return merge(
159178
{
160179
fileMetadata,

0 commit comments

Comments
 (0)