mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-14 17:28:27 +00:00
wow that did not merge well
This commit is contained in:
parent
acd04d18ae
commit
687649a5e4
@ -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;
|
||||
|
@ -108,6 +108,10 @@ export const services = {
|
||||
"s/:id"
|
||||
],
|
||||
},
|
||||
threads: {
|
||||
patterns: [":user/post/:id"],
|
||||
tld: "net",
|
||||
},
|
||||
tiktok: {
|
||||
patterns: [
|
||||
":user/video/:postId",
|
||||
|
@ -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,
|
||||
|
||||
|
@ -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' };
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user