Skip to content

best way to save what you love

api/vimeo: add subtitle parsing from the mobile api

wukkoa44bea6b5056
diff --git a/api/src/processing/match-action.js b/api/src/processing/match-action.js
index ce8a456d..a3d9230c 100644
--- a/api/src/processing/match-action.js
+++ b/api/src/processing/match-action.js
@@ -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";
}
diff --git a/api/src/processing/match.js b/api/src/processing/match.js
index 11e2b9ab..f71dd635 100644
--- a/api/src/processing/match.js
+++ b/api/src/processing/match.js
@@ -167,6 +167,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
password: patternMatch.password,
quality: params.videoQuality,
isAudioOnly,
+ subtitleLang,
});
break;
diff --git a/api/src/processing/services/vimeo.js b/api/src/processing/services/vimeo.js
index 8d704771..7a65f17a 100644
--- a/api/src/processing/services/vimeo.js
+++ b/api/src/processing/services/vimeo.js
@@ -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,