mirror of
https://github.com/imputnet/cobalt.git
synced 2026-02-21 16:05:53 +00:00
refactoring & fixes
- added duration check to vimeo module - fixed quality picking in vimeo module for progressive video type - dropping requests from ie users instead of redirecting - probably something else but i forgot to be honest
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { quality, services } from "../config.js";
|
||||
import { maxVideoDuration, quality, services } from "../config.js";
|
||||
|
||||
export default async function(obj) {
|
||||
try {
|
||||
let api = await fetch(`https://player.vimeo.com/video/${obj.id}/config`).then((r) => {return r.json()}).catch(() => {return false});
|
||||
if (!api) return { error: 'ErrorCouldntFetch' };
|
||||
|
||||
let downloadType = "";
|
||||
let downloadType = "dash";
|
||||
if (JSON.stringify(api).includes('"progressive":[{')) {
|
||||
downloadType = "progressive";
|
||||
} else if (JSON.stringify(api).includes('"files":{"dash":{"')) downloadType = "dash";
|
||||
}
|
||||
|
||||
switch(downloadType) {
|
||||
case "progressive":
|
||||
@@ -19,10 +19,13 @@ export default async function(obj) {
|
||||
let pref = parseInt(quality[obj.quality], 10)
|
||||
for (let i in all) {
|
||||
let currQuality = parseInt(all[i]["quality"].replace('p', ''), 10)
|
||||
if (currQuality === pref) {
|
||||
best = all[i];
|
||||
break
|
||||
}
|
||||
if (currQuality < pref) {
|
||||
break;
|
||||
} else if (currQuality == pref) {
|
||||
best = all[i]
|
||||
best = all[i-1];
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,45 +34,46 @@ export default async function(obj) {
|
||||
}
|
||||
return { urls: best["url"], filename: `tumblr_${obj.id}.mp4` };
|
||||
case "dash":
|
||||
if (api.video.duration > maxVideoDuration / 1000) {
|
||||
return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
||||
}
|
||||
let masterJSONURL = api["request"]["files"]["dash"]["cdns"]["akfire_interconnect_quic"]["url"];
|
||||
let masterJSON = await fetch(masterJSONURL).then((r) => {return 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]
|
||||
}
|
||||
if (!masterJSON.video) {
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
let type = "parcel";
|
||||
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]}`;
|
||||
}
|
||||
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' }
|
||||
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' }
|
||||
}
|
||||
default:
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
|
||||
Reference in New Issue
Block a user