mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
vimeo: added more checks to avoid exceptions
This commit is contained in:
parent
de7df94271
commit
b51bcc2a7c
1 changed files with 10 additions and 5 deletions
|
@ -29,6 +29,7 @@ export default async function(obj) {
|
||||||
const api = await fetch(url)
|
const api = await fetch(url)
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
if (!api) return { error: 'ErrorCouldntFetch' };
|
if (!api) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
const fileMetadata = {
|
const fileMetadata = {
|
||||||
|
@ -36,10 +37,12 @@ export default async function(obj) {
|
||||||
artist: cleanString(api.video.owner.name.trim()),
|
artist: cleanString(api.video.owner.name.trim()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (api.video.duration > env.durationLimit)
|
if (api.video?.duration > env.durationLimit)
|
||||||
return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
||||||
|
|
||||||
const urlMasterHLS = api.request.files.hls.cdns.akfire_interconnect_quic.url;
|
const urlMasterHLS = api.request?.files?.hls?.cdns?.akfire_interconnect_quic?.url;
|
||||||
|
|
||||||
|
if (!urlMasterHLS) return { error: 'ErrorCouldntFetch' }
|
||||||
|
|
||||||
const masterHLS = await fetch(urlMasterHLS)
|
const masterHLS = await fetch(urlMasterHLS)
|
||||||
.then(r => r.text())
|
.then(r => r.text())
|
||||||
|
@ -47,17 +50,19 @@ export default async function(obj) {
|
||||||
|
|
||||||
if (!masterHLS) return { error: 'ErrorCouldntFetch' };
|
if (!masterHLS) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
const variants = HLS.parse(masterHLS).variants.sort(
|
const variants = HLS.parse(masterHLS)?.variants?.sort(
|
||||||
(a, b) => Number(b.bandwidth) - Number(a.bandwidth)
|
(a, b) => Number(b.bandwidth) - Number(a.bandwidth)
|
||||||
);
|
);
|
||||||
if (!variants) return { error: 'ErrorEmptyDownload' };
|
if (!variants || variants.length === 0) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
let bestQuality;
|
let bestQuality;
|
||||||
if (quality < resolutionMatch[variants[0].resolution.width]) {
|
|
||||||
|
if (quality < resolutionMatch[variants[0]?.resolution?.width]) {
|
||||||
bestQuality = variants.find(v =>
|
bestQuality = variants.find(v =>
|
||||||
(quality === resolutionMatch[v.resolution.width])
|
(quality === resolutionMatch[v.resolution.width])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bestQuality) bestQuality = variants[0];
|
if (!bestQuality) bestQuality = variants[0];
|
||||||
|
|
||||||
const expandLink = (path) => {
|
const expandLink = (path) => {
|
||||||
|
|
Loading…
Reference in a new issue