From b51bcc2a7cd247b88bd73cf20624ec4023de7eb9 Mon Sep 17 00:00:00 2001 From: wukko Date: Sun, 23 Jun 2024 23:35:29 +0600 Subject: [PATCH] vimeo: added more checks to avoid exceptions --- src/modules/processing/services/vimeo.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/processing/services/vimeo.js b/src/modules/processing/services/vimeo.js index a80561f9..d79d2e92 100644 --- a/src/modules/processing/services/vimeo.js +++ b/src/modules/processing/services/vimeo.js @@ -29,6 +29,7 @@ export default async function(obj) { const api = await fetch(url) .then(r => r.json()) .catch(() => {}); + if (!api) return { error: 'ErrorCouldntFetch' }; const fileMetadata = { @@ -36,10 +37,12 @@ export default async function(obj) { 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] }; - 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) .then(r => r.text()) @@ -47,17 +50,19 @@ export default async function(obj) { 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) ); - if (!variants) return { error: 'ErrorEmptyDownload' }; + if (!variants || variants.length === 0) return { error: 'ErrorEmptyDownload' }; let bestQuality; - if (quality < resolutionMatch[variants[0].resolution.width]) { + + if (quality < resolutionMatch[variants[0]?.resolution?.width]) { bestQuality = variants.find(v => (quality === resolutionMatch[v.resolution.width]) ); } + if (!bestQuality) bestQuality = variants[0]; const expandLink = (path) => {