Files
cobalt/src/modules/processing/services/twitter_lite.js
wukko 5955594e48 even more cleansing
- added support for x.com urls
- removed del shortcut for clearing url input area because it was causing regular typing issues
- added info about no liability
- fixed donate button glow and text backdrop padding
- updated donation and privacy policy texts for more clarity in both english and russian
- made cors question in setup script to take yes as answer, not just 'y'
- text-to-copy now has proper rounding when highlighted
- home screen now smoothly fades in instead of popping in
2023-08-14 00:09:50 +06:00

40 lines
1.6 KiB
JavaScript

function bestQuality(arr) {
return arr.filter((v) => { if (v["content_type"] === "video/mp4") return true }).sort((a, b) => Number(b.bitrate) - Number(a.bitrate))[0]["url"]
}
export default async function(obj) {
if (!obj.spaceId) {
let synd = await fetch(`https://cdn.syndication.twimg.com/tweet-result?id=${obj.id}`, {
headers: {
"User-Agent": "Googlebot/2.1 (+http://www.google.com/bot.html)"
}
}).then((r) => { return r.status === 200 ? r.text() : false }).catch((e) => { return false });
if (!synd) {
return { error: 'ErrorTweetUnavailable' }
} else {
synd = JSON.parse(synd);
}
if (!synd.mediaDetails) return { error: 'ErrorNoVideosInTweet' };
let single, multiple = [], media = synd.mediaDetails;
media = media.filter((i) => { if (i["type"] === "video" || i["type"] === "animated_gif") return true })
if (media.length > 1) {
for (let i in media) { multiple.push({type: "video", thumb: media[i]["media_url_https"], url: bestQuality(media[i]["video_info"]["variants"])}) }
} else if (media.length === 1) {
single = bestQuality(media[0]["video_info"]["variants"])
} else {
return { error: 'ErrorNoVideosInTweet' }
}
if (single) {
return { urls: single, filename: `twitter_${obj.id}.mp4`, audioFilename: `twitter_${obj.id}_audio` }
} else if (multiple) {
return { picker: multiple }
} else {
return { error: 'ErrorNoVideosInTweet' }
}
} else {
return { error: 'ErrorTwitterRIP' }
}
}