diff --git a/api/src/processing/match.js b/api/src/processing/match.js index e6c03a9e..e5cc5523 100644 --- a/api/src/processing/match.js +++ b/api/src/processing/match.js @@ -234,7 +234,7 @@ export default async function({ host, patternMatch, params }) { case "threads": r = await threads({ ...patternMatch, - quality: obj.vQuality, + quality: params.videoQuality, dispatcher }); break; diff --git a/api/src/processing/service-config.js b/api/src/processing/service-config.js index 8d8bf4ac..c48000d3 100644 --- a/api/src/processing/service-config.js +++ b/api/src/processing/service-config.js @@ -108,6 +108,10 @@ export const services = { "s/:id" ], }, + threads: { + patterns: [":user/post/:id"], + tld: "net", + }, tiktok: { patterns: [ ":user/video/:postId", diff --git a/api/src/processing/service-patterns.js b/api/src/processing/service-patterns.js index 2105a563..723ab8a1 100644 --- a/api/src/processing/service-patterns.js +++ b/api/src/processing/service-patterns.js @@ -38,6 +38,9 @@ export const testers = { "streamable": pattern => pattern.id?.length === 6, + "threads": pattern => + pattern.user?.length <= 33 && pattern.id?.length <= 32, + "tiktok": pattern => pattern.postId?.length <= 21 || pattern.id?.length <= 13, diff --git a/api/src/processing/services/threads.js b/api/src/processing/services/threads.js index ba620ed6..279de16c 100644 --- a/api/src/processing/services/threads.js +++ b/api/src/processing/services/threads.js @@ -34,31 +34,31 @@ export default async function({ user, id, quality, dispatcher }) { if (cookie) updateCookie(cookie, response.headers); if (response.status !== 200) { - return { error: 'ErrorCouldntFetch' }; + return { error: 'fetch.fail' }; } const html = await response.text(); const dataString = html.match(DATA_REGEX)?.[1]; if (!dataString) { - return { error: 'ErrorCouldntFetch' }; + return { error: 'fetch.fail' }; } const data = JSON.parse(dataString); const post = data?.require?.[0]?.[3]?.[0]?.__bbox?.require?.[0]?.[3]?.[1]?.__bbox?.result?.data?.data?.edges[0]?.node?.thread_items[0]?.post; if (!post) { - return { error: 'ErrorCouldntFetch' }; + return { error: 'fetch.fail' }; } // Video if (post.media_type === 2) { if (!post.video_versions) { - return { error: 'ErrorEmptyDownload' }; + return { error: 'fetch.empty' }; } // types: 640p = 101, 480p = 102, 480p-low = 103 const selectedQualityType = quality === 'max' ? 101 : quality && parseInt(quality) <= 480 ? 102 : 101; const video = post.video_versions.find((v) => v.type === selectedQualityType) || post.video_versions.sort((a, b) => a.type - b.type)[0]; if (!video) { - return { error: 'ErrorEmptyDownload' }; + return { error: 'fetch.empty' }; } return { @@ -71,7 +71,7 @@ export default async function({ user, id, quality, dispatcher }) { // Photo if (post.media_type === 1) { if (!post.image_versions2?.candidates) { - return { error: 'ErrorEmptyDownload' }; + return { error: 'fetch.empty' }; } return { @@ -83,7 +83,7 @@ export default async function({ user, id, quality, dispatcher }) { // Mixed if (post.media_type === 8) { if (!post.carousel_media) { - return { error: 'ErrorEmptyDownload' }; + return { error: 'fetch.empty' }; } return { @@ -94,13 +94,12 @@ export default async function({ user, id, quality, dispatcher }) { ** set to `same-origin`, so we need to proxy them */ thumb: createStream({ service: "threads", - type: "default", - u: media.image_versions2.candidates[0].url, - filename: "image.jpg" + type: "proxy", + u: media.image_versions2.candidates[0].url }) })) } } - return { error: 'ErrorUnsupported' }; + return { error: 'fetch.fail' }; } diff --git a/api/src/util/tests.json b/api/src/util/tests.json index 94005c0a..ce9b3fe7 100644 --- a/api/src/util/tests.json +++ b/api/src/util/tests.json @@ -1493,5 +1493,30 @@ "status": "error" } } - ] + ], + "threads": [{ + "name": "video", + "url": "https://www.threads.net/@zuck/post/CzecNnZPaxr", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } + }, { + "name": "photo", + "url": "https://www.threads.net/@soren.iverson/post/C8PdJ59pMLr", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } + }, { + "name": "mixed media", + "url": "https://www.threads.net/@snazzahguy/post/C8Q7UZDseWz", + "params": {}, + "expected": { + "code": 200, + "status": "picker" + } + }] } diff --git a/src/modules/processing/servicesConfig.json b/src/modules/processing/servicesConfig.json deleted file mode 100644 index e69de29b..00000000 diff --git a/src/modules/processing/servicesPatternTesters.js b/src/modules/processing/servicesPatternTesters.js deleted file mode 100644 index e69de29b..00000000 diff --git a/src/util/tests.json b/src/util/tests.json deleted file mode 100644 index e69de29b..00000000