mirror of
https://github.com/imputnet/cobalt.git
synced 2026-01-26 16:51:17 +00:00
4.5
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import got from "got";
|
||||
import loc from "../../localization/manager.js";
|
||||
import { genericUserAgent, quality } from "../config.js";
|
||||
import { quality, services } from "../config.js";
|
||||
|
||||
export default async function(obj) {
|
||||
try {
|
||||
let api = await got.get(`https://player.vimeo.com/video/${obj.id}/config`, { headers: { "user-agent": genericUserAgent } });
|
||||
api.on('error', (err) => {
|
||||
return { error: loc(obj.lang, 'ErrorCouldntFetch', 'vimeo') };
|
||||
});
|
||||
api = api.body
|
||||
if (api.includes('}}},"progressive":[{')) {
|
||||
api = JSON.parse(api)
|
||||
if (api["request"]["files"]["progressive"]) {
|
||||
let api = await fetch(`https://player.vimeo.com/video/${obj.id}/config`).then(async (r) => {return await r.json()}).catch(() => {return false});
|
||||
if (!api) return { error: 'ErrorCouldntFetch' };
|
||||
|
||||
let downloadType = "";
|
||||
if (JSON.stringify(api).includes('"progressive":[{')) {
|
||||
downloadType = "progressive";
|
||||
} else if (JSON.stringify(api).includes('"files":{"dash":{"')) downloadType = "dash";
|
||||
|
||||
switch(downloadType) {
|
||||
case "progressive":
|
||||
let all = api["request"]["files"]["progressive"].sort((a, b) => Number(b.width) - Number(a.width));
|
||||
let best = all[0]
|
||||
try {
|
||||
@@ -29,10 +29,52 @@ export default async function(obj) {
|
||||
} catch (e) {
|
||||
best = all[0]
|
||||
}
|
||||
return { urls: best["url"], audioFilename: loc(obj.lang, 'ErrorEmptyDownload') }
|
||||
} else return { error: loc(obj.lang, 'ErrorEmptyDownload') }
|
||||
} else return { error: loc(obj.lang, 'ErrorBrokenLink', 'vimeo') }
|
||||
return { urls: best["url"] };
|
||||
case "dash":
|
||||
let masterJSONURL = api["request"]["files"]["dash"]["cdns"]["akfire_interconnect_quic"]["url"];
|
||||
let masterJSON = await fetch(masterJSONURL).then(async (r) => {return await r.json()}).catch(() => {return false});
|
||||
if (!masterJSON) return { error: 'ErrorCouldntFetch' };
|
||||
if (masterJSON.video) {
|
||||
let type = "";
|
||||
if (masterJSON.base_url.includes("parcel")) {
|
||||
type = "parcel"
|
||||
} else if (masterJSON.base_url == "../") {
|
||||
type = "chop"
|
||||
}
|
||||
let masterJSON_Video = masterJSON.video.sort((a, b) => Number(b.width) - Number(a.width));
|
||||
let masterJSON_Audio = masterJSON.audio.sort((a, b) => Number(b.bitrate) - Number(a.bitrate)).filter((a)=> {if (a['mime_type'] === "audio/mp4") return true;});
|
||||
|
||||
let bestVideo = masterJSON_Video[0]
|
||||
let bestAudio = masterJSON_Audio[0]
|
||||
switch (type) {
|
||||
case "parcel":
|
||||
if (obj.quality != "max") {
|
||||
let pref = parseInt(quality[obj.quality], 10)
|
||||
for (let i in masterJSON_Video) {
|
||||
let currQuality = parseInt(services.vimeo.resolutionMatch[masterJSON_Video[i]["width"]], 10)
|
||||
if (currQuality < pref) {
|
||||
break;
|
||||
} else if (currQuality == pref) {
|
||||
bestVideo = masterJSON_Video[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
let baseUrl = masterJSONURL.split("/sep/")[0]
|
||||
let videoUrl = `${baseUrl}/parcel/video/${bestVideo.index_segment.split('?')[0]}`;
|
||||
let audioUrl = `${baseUrl}/parcel/audio/${bestAudio.index_segment.split('?')[0]}`;
|
||||
|
||||
return { urls: [videoUrl, audioUrl], audioFilename: `vimeo_${obj.id}_audio`, filename: `vimeo_${obj.id}_${bestVideo["width"]}x${bestVideo["height"]}.mp4` }
|
||||
case "chop": // TO-DO: support chop type of streams
|
||||
default:
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
} else {
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
default:
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
} catch (e) {
|
||||
return { error: loc(obj.lang, 'ErrorBadFetch') };
|
||||
return { error: 'ErrorBadFetch' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user