twitter: add support for downloading photos

This commit is contained in:
wukko 2024-07-26 21:17:37 +06:00
parent 57051968f3
commit dad13548e6
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -147,7 +147,6 @@ export default async function({ id, index, toGif, dispatcher }) {
} }
let media = (repostedTweet?.media || baseTweet?.extended_entities?.media); 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/<index>) // check if there's a video at given index (/video/<index>)
if (index >= 0 && index < media?.length) { if (index >= 0 && index < media?.length) {
@ -159,18 +158,38 @@ export default async function({ id, index, toGif, dispatcher }) {
case 0: case 0:
return { error: 'ErrorNoVideosInTweet' }; return { error: 'ErrorNoVideosInTweet' };
case 1: case 1:
if (media[0].type === "photo") {
return {
type: "normal",
isPhoto: true,
urls: `${media[0].media_url_https}?name=4096x4096`
}
}
return { return {
type: needsFixing(media[0]) ? "remux" : "normal", type: needsFixing(media[0]) ? "remux" : "normal",
urls: bestQuality(media[0].video_info.variants), urls: bestQuality(media[0].video_info.variants),
filename: `twitter_${id}.mp4`, filename: `twitter_${id}.mp4`,
audioFilename: `twitter_${id}_audio`, audioFilename: `twitter_${id}_audio`,
isGif: media[0].type === "animated_gif" isGif: media[0].type === "animated_gif"
}; }
default: default:
const picker = media.map((content, i) => { 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); let url = bestQuality(content.video_info.variants);
const shouldRenderGif = content.type === 'animated_gif' && toGif; const shouldRenderGif = content.type === 'animated_gif' && toGif;
let type = "video";
if (shouldRenderGif) type = "gif";
if (needsFixing(content) || shouldRenderGif) { if (needsFixing(content) || shouldRenderGif) {
url = createStream({ url = createStream({
service: 'twitter', service: 'twitter',
@ -181,9 +200,9 @@ export default async function({ id, index, toGif, dispatcher }) {
} }
return { return {
type: 'video', type,
url, url,
thumb: content.media_url_https, thumb: content.media_url_https
} }
}); });
return { picker }; return { picker };