From e73ad62b787b1c5bcabbac5e03f71efb7523ebea Mon Sep 17 00:00:00 2001 From: Snazzah Date: Sun, 16 Jun 2024 00:50:07 -0500 Subject: [PATCH 01/10] feat: threads support --- README.md | 2 + src/modules/processing/match.js | 8 ++ src/modules/processing/matchActionDecider.js | 2 + src/modules/processing/services/threads.js | 106 ++++++++++++++++++ src/modules/processing/servicesConfig.json | 6 + .../processing/servicesPatternTesters.js | 3 + src/util/tests.json | 25 +++++ 7 files changed, 152 insertions(+) create mode 100644 src/modules/processing/services/threads.js diff --git a/README.md b/README.md index d2bb064c8..1ea7c26e5 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ this list is not final and keeps expanding over time. if support for a service y | rutube | ✅ | ✅ | ✅ | ✅ | ✅ | | soundcloud | ➖ | ✅ | ➖ | ✅ | ✅ | | streamable | ✅ | ✅ | ✅ | ➖ | ➖ | +| threads posts | ✅ | ✅ | ✅ | ✅ | ✅ | | tiktok | ✅ | ✅ | ✅ | ❌ | ❌ | | tumblr | ✅ | ✅ | ✅ | ➖ | ➖ | | twitch clips | ✅ | ✅ | ✅ | ✅ | ✅ | @@ -49,6 +50,7 @@ this list is not final and keeps expanding over time. if support for a service y | reddit | supports gifs and videos. | | rutube | supports yappy & private links. | | soundcloud | supports private links. | +| threads | supports photos and videos. lets you pick what to save from multi-media posts. | | tiktok | supports videos with or without watermark, images from slideshow without watermark, and full (original) audios. | | twitter/x | lets you pick what to save from multi-media posts. may not be 100% reliable due to current management. | | vimeo | audio downloads are only available for dash. | diff --git a/src/modules/processing/match.js b/src/modules/processing/match.js index 3e38c4db2..c3ceb5872 100644 --- a/src/modules/processing/match.js +++ b/src/modules/processing/match.js @@ -25,6 +25,7 @@ import twitch from "./services/twitch.js"; import rutube from "./services/rutube.js"; import dailymotion from "./services/dailymotion.js"; import loom from "./services/loom.js"; +import threads from "./services/threads.js"; let freebind; @@ -193,6 +194,13 @@ export default async function(host, patternMatch, lang, obj) { id: patternMatch.id }); break; + case "threads": + r = await threads({ + ...patternMatch, + quality: obj.vQuality, + dispatcher + }) + break; default: return createResponse("error", { t: loc(lang, 'ErrorUnsupported') diff --git a/src/modules/processing/matchActionDecider.js b/src/modules/processing/matchActionDecider.js index f7ed3da91..c19136fdf 100644 --- a/src/modules/processing/matchActionDecider.js +++ b/src/modules/processing/matchActionDecider.js @@ -67,6 +67,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di switch (host) { case "instagram": case "twitter": + case "threads": params = { picker: r.picker }; break; case "tiktok": @@ -130,6 +131,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di case "pinterest": case "streamable": case "loom": + case "threads": responseType = "redirect"; break; } diff --git a/src/modules/processing/services/threads.js b/src/modules/processing/services/threads.js new file mode 100644 index 000000000..1bc8c047b --- /dev/null +++ b/src/modules/processing/services/threads.js @@ -0,0 +1,106 @@ +import { createStream } from "../../stream/manage.js"; +import { getCookie, updateCookie } from "../cookie/manager.js"; + +const commonHeaders = { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.7", + "Cache-Control": "no-cache", + "Dnt": "1", + "Priority": "u=0, i", + "Sec-Ch-Ua": '"Not/A)Brand";v="8", "Chromium";v="126", "Brave";v="126"', + "Sec-Ch-Ua-Mobile": "?0", + "Sec-Ch-Ua-Model": '""', + "Sec-Ch-Ua-Platform": '"Windows"', + "Sec-Ch-Ua-Platform-Version": '"15.0.0"', + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "same-origin", + "Sec-Gpc": "1", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36", +}; + +const DATA_REGEX = /