From e1edecb859533914fe40353c262152ba0a4282e5 Mon Sep 17 00:00:00 2001 From: wukko Date: Sun, 7 Jan 2024 14:22:59 +0600 Subject: [PATCH] twitter: fix parsing from /video/ links error is no longer thrown if index is an unexpected value (such as 0 or negative) --- src/modules/processing/services/twitter.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/processing/services/twitter.js b/src/modules/processing/services/twitter.js index 0c254a77..31b26b48 100644 --- a/src/modules/processing/services/twitter.js +++ b/src/modules/processing/services/twitter.js @@ -96,20 +96,22 @@ export default async function({ id, index }) { let media = (repostedTweet?.media || baseTweet.extended_entities.media); media = media?.filter(m => m.video_info?.variants?.length); - if (index < media?.length) { + // check if there's a video at given index (/video/) + if ([0, 1, 2, 3].includes(index) && index < media?.length) { media = [media[index]] } + switch (media?.length) { case undefined: case 0: - return { error: 'ErrorNoVideosInTweet' } + return { error: 'ErrorNoVideosInTweet' }; case 1: return { type: needsFixing(media[0]) ? "remux" : "normal", urls: bestQuality(media[0].video_info.variants), filename: `twitter_${id}.mp4`, audioFilename: `twitter_${id}_audio` - } + }; default: const picker = media.map((video, i) => { let url = bestQuality(video.video_info.variants); @@ -127,6 +129,6 @@ export default async function({ id, index }) { thumb: video.media_url_https, } }); - return { picker } + return { picker }; } }