mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 01:18:27 +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":
|
||||
if (Array.isArray(r.urls)) {
|
||||
params = { type: "merge" }
|
||||
params = { type: "merge" };
|
||||
} else if (r.subtitles) {
|
||||
params = { type: "remux" };
|
||||
} else {
|
||||
responseType = "redirect";
|
||||
}
|
||||
|
@ -167,6 +167,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
|
||||
password: patternMatch.password,
|
||||
quality: params.videoQuality,
|
||||
isAudioOnly,
|
||||
subtitleLang,
|
||||
});
|
||||
break;
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user