twitter: fix videos only within affected time range

This commit is contained in:
wukko 2023-12-17 23:05:43 +06:00
parent e00a3a4849
commit 8556a5fe2c
2 changed files with 24 additions and 6 deletions

View file

@ -40,7 +40,6 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted, d
case "bilibili": case "bilibili":
params = { type: "render" }; params = { type: "render" };
break; break;
case "twitter":
case "youtube": case "youtube":
params = { type: r.type }; params = { type: r.type };
break; break;
@ -56,6 +55,14 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted, d
} }
break; break;
case "twitter":
if (r.type === "remux") {
params = { type: r.type };
} else {
responseType = 1;
}
break;
case "vk": case "vk":
case "douyin": case "douyin":
case "tiktok": case "tiktok":

View file

@ -5,6 +5,10 @@ function bestQuality(arr) {
return arr.filter(v => v["content_type"] === "video/mp4").sort((a, b) => Number(b.bitrate) - Number(a.bitrate))[0]["url"] return arr.filter(v => v["content_type"] === "video/mp4").sort((a, b) => Number(b.bitrate) - Number(a.bitrate))[0]["url"]
} }
// fix all videos affected by the container bug in twitter muxer (took them over two weeks to fix it????)
const badContainerStart = new Date(1701446400000);
const badContainerEnd = new Date(1702605600000);
export default async function(obj) { export default async function(obj) {
let _headers = { let _headers = {
"user-agent": genericUserAgent, "user-agent": genericUserAgent,
@ -60,17 +64,24 @@ export default async function(obj) {
let single, multiple = [], media = baseMedia["media"]; let single, multiple = [], media = baseMedia["media"];
media = media.filter((i) => { if (i["type"] === "video" || i["type"] === "animated_gif") return true }); media = media.filter((i) => { if (i["type"] === "video" || i["type"] === "animated_gif") return true });
let tweetDate = new Date(baseTweet.created_at),
needsFixing = tweetDate > badContainerStart && tweetDate < badContainerEnd;
if (media.length > 1) { if (media.length > 1) {
for (let i in media) { for (let i in media) {
multiple.push({ let downloadUrl = bestQuality(media[i]["video_info"]["variants"]);
type: "video", if (needsFixing) {
thumb: media[i]["media_url_https"], downloadUrl = createStream({
url: createStream({
service: "twitter", service: "twitter",
type: "remux", type: "remux",
u: bestQuality(media[i]["video_info"]["variants"]), u: bestQuality(media[i]["video_info"]["variants"]),
filename: `twitter_${obj.id}_${Number(i) + 1}.mp4` filename: `twitter_${obj.id}_${Number(i) + 1}.mp4`
}) })
}
multiple.push({
type: "video",
thumb: media[i]["media_url_https"],
url: downloadUrl
}) })
} }
} else if (media.length === 1) { } else if (media.length === 1) {
@ -81,7 +92,7 @@ export default async function(obj) {
if (single) { if (single) {
return { return {
type: "remux", type: needsFixing? "remux" : "normal",
urls: single, urls: single,
filename: `twitter_${obj.id}.mp4`, filename: `twitter_${obj.id}.mp4`,
audioFilename: `twitter_${obj.id}_audio` audioFilename: `twitter_${obj.id}_audio`