mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
api/vimeo: add subtitle parsing from the mobile api
This commit is contained in:
parent
a5838f3c05
commit
a44bea6b50
@ -145,7 +145,9 @@ export default function({
|
|||||||
|
|
||||||
case "vimeo":
|
case "vimeo":
|
||||||
if (Array.isArray(r.urls)) {
|
if (Array.isArray(r.urls)) {
|
||||||
params = { type: "merge" }
|
params = { type: "merge" };
|
||||||
|
} else if (r.subtitles) {
|
||||||
|
params = { type: "remux" };
|
||||||
} else {
|
} else {
|
||||||
responseType = "redirect";
|
responseType = "redirect";
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
|
|||||||
password: patternMatch.password,
|
password: patternMatch.password,
|
||||||
quality: params.videoQuality,
|
quality: params.videoQuality,
|
||||||
isAudioOnly,
|
isAudioOnly,
|
||||||
|
subtitleLang,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ const compareQuality = (rendition, requestedQuality) => {
|
|||||||
return Math.abs(quality - requestedQuality);
|
return Math.abs(quality - requestedQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDirectLink = (data, quality) => {
|
const getDirectLink = async (data, quality, subtitleLang) => {
|
||||||
if (!data.files) return;
|
if (!data.files) return;
|
||||||
|
|
||||||
const match = data.files
|
const match = data.files
|
||||||
@ -56,8 +56,23 @@ const getDirectLink = (data, quality) => {
|
|||||||
|
|
||||||
if (!match) return;
|
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 {
|
return {
|
||||||
urls: match.link,
|
urls: match.link,
|
||||||
|
subtitles,
|
||||||
filenameAttributes: {
|
filenameAttributes: {
|
||||||
resolution: `${match.width}x${match.height}`,
|
resolution: `${match.width}x${match.height}`,
|
||||||
qualityLabel: match.rendition,
|
qualityLabel: match.rendition,
|
||||||
@ -143,7 +158,7 @@ export default async function(obj) {
|
|||||||
response = await getHLS(info.config_url, { ...obj, quality });
|
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) response = { error: "fetch.empty" };
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
@ -155,6 +170,10 @@ export default async function(obj) {
|
|||||||
artist: info.user.name,
|
artist: info.user.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (response.subtitles) {
|
||||||
|
fileMetadata.sublanguage = obj.subtitleLang;
|
||||||
|
}
|
||||||
|
|
||||||
return merge(
|
return merge(
|
||||||
{
|
{
|
||||||
fileMetadata,
|
fileMetadata,
|
||||||
|
Loading…
Reference in New Issue
Block a user