6.2.2: fixes related to twitter screwing everything up

(also fixes an issue with some instagram links)
This commit is contained in:
wukko
2023-06-30 16:29:21 +06:00
parent aaa99d48a3
commit db5d62ae58
10 changed files with 50 additions and 27 deletions

View File

@@ -364,7 +364,6 @@ export default function(obj) {
body: `<div id="desc-error" class="desc-padding subtext"></div>`
})}
<div id="popup-backdrop" style="visibility: hidden;" onclick="hideAllPopups()"></div>
<div id="urgent-notice" class="urgent-notice explanation center" onclick="popup('about', 1, 'changelog')" style="visibility: hidden;">${emoji("🎉", 18)} ${t("UrgentUpdate6")}</div>
<div id="cobalt-main-box" class="center" style="visibility: hidden;">
<div id="logo">${appName}</div>
<div id="download-area">

View File

@@ -8,7 +8,7 @@ import matchActionDecider from "./matchActionDecider.js";
import bilibili from "./services/bilibili.js";
import reddit from "./services/reddit.js";
import twitter from "./services/twitter.js";
import twitter from "./services/twitter_lite.js";
import youtube from "./services/youtube.js";
import vk from "./services/vk.js";
import tiktok from "./services/tiktok.js";

View File

@@ -9,7 +9,6 @@ export default async function(obj) {
let _headers = {
"user-agent": genericUserAgent,
"authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
// ^ no explicit content, but with multi media support
"host": "api.twitter.com",
"x-twitter-client-language": "en",
"x-twitter-active-user": "yes",
@@ -29,23 +28,6 @@ export default async function(obj) {
if (!obj.spaceId) {
let conversation = await fetch(conversationURL, { headers: _headers }).then((r) => { return r.status === 200 ? r.json() : false }).catch((e) => { return false });
if (!conversation || !conversation.globalObjects.tweets[obj.id]) {
_headers.authorization = "Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw";
// ^ explicit content, but no multi media support
delete _headers["x-guest-token"];
delete _headers["cookie"];
req_act = await fetch(activateURL, {
method: "POST",
headers: _headers
}).then((r) => { return r.status === 200 ? r.json() : false}).catch(() => { return false });
if (!req_act) return { error: 'ErrorCouldntFetch' };
_headers["x-guest-token"] = req_act["guest_token"];
_headers['cookie'] = `guest_id=v1%3A${req_act["guest_token"]};`;
conversation = await fetch(conversationURL, { headers: _headers }).then((r) => { return r.status === 200 ? r.json() : false }).catch(() => { return false });
}
if (!conversation || !conversation.globalObjects.tweets[obj.id]) return { error: 'ErrorTweetUnavailable' };
let baseMedia, baseTweet = conversation.globalObjects.tweets[obj.id];

View File

@@ -0,0 +1,39 @@
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"].split("?")[0]
}
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' }
}
}

View File

@@ -12,7 +12,7 @@
"enabled": true
},
"twitter": {
"alias": "twitter posts & spaces & voice",
"alias": "twitter posts & voice",
"patterns": [":user/status/:id", ":user/status/:id/video/:v", "i/spaces/:spaceId"],
"enabled": true
},

View File

@@ -62,7 +62,7 @@ export function msToTime(d) {
return r;
}
export function cleanURL(url, host) {
let forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@"]
let forbiddenChars = ['}', '{', '(', ')', '\\', '%', '>', '<', '^', '*', '!', '~', ';', ':', ',', '`', '[', ']', '#', '$', '"', "'", "@", '==']
switch(host) {
case "vk":
url = url.includes('clip') ? url.split('&')[0] : url.split('?')[0];