From dad13548e6e176a48793f91e56a149da1ba96b32 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 26 Jul 2024 21:17:37 +0600 Subject: [PATCH] twitter: add support for downloading photos --- src/modules/processing/services/twitter.js | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/modules/processing/services/twitter.js b/src/modules/processing/services/twitter.js index 36a8669b..30681636 100644 --- a/src/modules/processing/services/twitter.js +++ b/src/modules/processing/services/twitter.js @@ -147,7 +147,6 @@ export default async function({ id, index, toGif, dispatcher }) { } let media = (repostedTweet?.media || baseTweet?.extended_entities?.media); - media = media?.filter(m => m.video_info?.variants?.length); // check if there's a video at given index (/video/) if (index >= 0 && index < media?.length) { @@ -159,18 +158,38 @@ export default async function({ id, index, toGif, dispatcher }) { case 0: return { error: 'ErrorNoVideosInTweet' }; case 1: + if (media[0].type === "photo") { + return { + type: "normal", + isPhoto: true, + urls: `${media[0].media_url_https}?name=4096x4096` + } + } + return { type: needsFixing(media[0]) ? "remux" : "normal", urls: bestQuality(media[0].video_info.variants), filename: `twitter_${id}.mp4`, audioFilename: `twitter_${id}_audio`, isGif: media[0].type === "animated_gif" - }; + } default: const picker = media.map((content, i) => { + if (content.type === "photo") { + let url = `${content.media_url_https}?name=4096x4096`; + return { + type: "photo", + url, + thumb: url, + } + } + let url = bestQuality(content.video_info.variants); const shouldRenderGif = content.type === 'animated_gif' && toGif; + let type = "video"; + if (shouldRenderGif) type = "gif"; + if (needsFixing(content) || shouldRenderGif) { url = createStream({ service: 'twitter', @@ -181,9 +200,9 @@ export default async function({ id, index, toGif, dispatcher }) { } return { - type: 'video', + type, url, - thumb: content.media_url_https, + thumb: content.media_url_https } }); return { picker };