twitter: downloading specific video if given index

This commit is contained in:
dumbmoron 2024-01-05 12:21:59 +00:00
parent 7b41dfef9e
commit ed2c63f9a4
No known key found for this signature in database
GPG key ID: C59997C76C6A8E5F
3 changed files with 9 additions and 4 deletions

View file

@ -36,7 +36,8 @@ export default async function(host, patternMatch, url, lang, obj) {
switch (host) { switch (host) {
case "twitter": case "twitter":
r = await twitter({ r = await twitter({
id: patternMatch["id"] id: patternMatch.id,
index: patternMatch.index - 1
}); });
break; break;
case "vk": case "vk":

View file

@ -71,7 +71,7 @@ const requestTweet = (tweetId, token) => {
}); });
} }
export default async function({ id }) { export default async function({ id, index }) {
let guestToken = await getGuestToken(); let guestToken = await getGuestToken();
if (!guestToken) return { error: 'ErrorCouldntFetch' }; if (!guestToken) return { error: 'ErrorCouldntFetch' };
@ -92,10 +92,14 @@ export default async function({ id }) {
const baseTweet = tweet.data.tweetResult.result.legacy, const baseTweet = tweet.data.tweetResult.result.legacy,
repostedTweet = baseTweet.retweeted_status_result?.result.legacy.extended_entities; repostedTweet = baseTweet.retweeted_status_result?.result.legacy.extended_entities;
const media = ( let media = (
repostedTweet?.media || baseTweet.extended_entities.media repostedTweet?.media || baseTweet.extended_entities.media
)?.filter(m => ['video', 'animated_gif'].includes(m.type)); )?.filter(m => ['video', 'animated_gif'].includes(m.type));
if (index < media?.length) {
media = [ media[index] ];
}
switch (media?.length) { switch (media?.length) {
case undefined: case undefined:
case 0: case 0:

View file

@ -15,7 +15,7 @@
"alias": "twitter videos & voice", "alias": "twitter videos & voice",
"altDomains": ["x.com", "vxtwitter.com", "fixvx.com"], "altDomains": ["x.com", "vxtwitter.com", "fixvx.com"],
"subdomains": ["mobile"], "subdomains": ["mobile"],
"patterns": [":user/status/:id", ":user/status/:id/video/:v"], "patterns": [":user/status/:id", ":user/status/:id/video/:index"],
"enabled": true "enabled": true
}, },
"vk": { "vk": {