mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-13 14:16:25 +01:00
merge: api 10.7.2 from main branch
This commit is contained in:
commit
ad23b70e9d
7 changed files with 63 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@imput/cobalt-api",
|
||||
"description": "save what you love",
|
||||
"version": "10.7",
|
||||
"version": "10.7.2",
|
||||
"author": "imput",
|
||||
"exports": "./src/cobalt.js",
|
||||
"type": "module",
|
||||
|
|
|
@ -120,9 +120,8 @@ export default async function({ host, patternMatch, params }) {
|
|||
|
||||
case "reddit":
|
||||
r = await reddit({
|
||||
sub: patternMatch.sub,
|
||||
id: patternMatch.id,
|
||||
user: patternMatch.user
|
||||
...patternMatch,
|
||||
dispatcher,
|
||||
});
|
||||
break;
|
||||
|
||||
|
|
|
@ -35,14 +35,25 @@ export const services = {
|
|||
},
|
||||
instagram: {
|
||||
patterns: [
|
||||
"reels/:postId",
|
||||
":username/reel/:postId",
|
||||
"reel/:postId",
|
||||
"p/:postId",
|
||||
":username/p/:postId",
|
||||
"tv/:postId",
|
||||
"reel/:postId",
|
||||
"reels/:postId",
|
||||
"stories/:username/:storyId",
|
||||
"share/:shareId"
|
||||
|
||||
/*
|
||||
share & username links use the same url pattern,
|
||||
so we test the share pattern first, cuz id type is different.
|
||||
however, if someone has the "share" username and the user
|
||||
somehow gets a link of this ancient style, it's joever.
|
||||
*/
|
||||
|
||||
"share/:shareId",
|
||||
"share/p/:shareId",
|
||||
"share/reel/:shareId",
|
||||
|
||||
":username/p/:postId",
|
||||
":username/reel/:postId",
|
||||
],
|
||||
altDomains: ["ddinstagram.com"],
|
||||
},
|
||||
|
@ -65,8 +76,21 @@ export const services = {
|
|||
},
|
||||
reddit: {
|
||||
patterns: [
|
||||
"comments/:id",
|
||||
|
||||
"r/:sub/comments/:id",
|
||||
"r/:sub/comments/:id/:title",
|
||||
"user/:user/comments/:id/:title"
|
||||
"r/:sub/comments/:id/comment/:commentId",
|
||||
|
||||
"user/:user/comments/:id",
|
||||
"user/:user/comments/:id/:title",
|
||||
"user/:user/comments/:id/comment/:commentId",
|
||||
|
||||
"r/u_:user/comments/:id",
|
||||
"r/u_:user/comments/:id/:title",
|
||||
"r/u_:user/comments/:id/comment/:commentId",
|
||||
|
||||
"r/:sub/s/:shareId"
|
||||
],
|
||||
subdomains: "*",
|
||||
},
|
||||
|
|
|
@ -20,8 +20,10 @@ export const testers = {
|
|||
pattern.id?.length <= 128 || pattern.shortLink?.length <= 32,
|
||||
|
||||
"reddit": pattern =>
|
||||
(pattern.sub?.length <= 22 && pattern.id?.length <= 10)
|
||||
|| (pattern.user?.length <= 22 && pattern.id?.length <= 10),
|
||||
pattern.id?.length <= 16 && !pattern.sub && !pattern.user
|
||||
|| (pattern.sub?.length <= 22 && pattern.id?.length <= 16)
|
||||
|| (pattern.user?.length <= 22 && pattern.id?.length <= 16)
|
||||
|| (pattern.sub?.length <= 22 && pattern.shareId?.length <= 16),
|
||||
|
||||
"rutube": pattern =>
|
||||
(pattern.id?.length === 32 && pattern.key?.length <= 32) ||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { resolveRedirectingURL } from "../url.js";
|
||||
import { genericUserAgent, env } from "../../config.js";
|
||||
import { getCookie, updateCookieValues } from "../cookie/manager.js";
|
||||
|
||||
|
@ -48,12 +49,20 @@ async function getAccessToken() {
|
|||
}
|
||||
|
||||
export default async function(obj) {
|
||||
let url = new URL(`https://www.reddit.com/r/${obj.sub}/comments/${obj.id}.json`);
|
||||
let params = obj;
|
||||
|
||||
if (obj.user) {
|
||||
url.pathname = `/user/${obj.user}/comments/${obj.id}.json`;
|
||||
if (!params.id && params.shareId) {
|
||||
params = await resolveRedirectingURL(
|
||||
`https://www.reddit.com/r/${params.sub}/s/${params.shareId}`,
|
||||
obj.dispatcher,
|
||||
genericUserAgent
|
||||
);
|
||||
}
|
||||
|
||||
if (!params?.id) return { error: "fetch.short_link" };
|
||||
|
||||
const url = new URL(`https://www.reddit.com/comments/${params.id}.json`);
|
||||
|
||||
const accessToken = await getAccessToken();
|
||||
if (accessToken) url.hostname = 'oauth.reddit.com';
|
||||
|
||||
|
@ -73,12 +82,17 @@ export default async function(obj) {
|
|||
|
||||
data = data[0]?.data?.children[0]?.data;
|
||||
|
||||
const id = `${String(obj.sub).toLowerCase()}_${obj.id}`;
|
||||
let sourceId;
|
||||
if (params.sub || params.user) {
|
||||
sourceId = `${String(params.sub || params.user).toLowerCase()}_${params.id}`;
|
||||
} else {
|
||||
sourceId = params.id;
|
||||
}
|
||||
|
||||
if (data?.url?.endsWith('.gif')) return {
|
||||
typeId: "redirect",
|
||||
urls: data.url,
|
||||
filename: `reddit_${id}.gif`,
|
||||
filename: `reddit_${sourceId}.gif`,
|
||||
}
|
||||
|
||||
if (!data.secure_media?.reddit_video)
|
||||
|
@ -87,8 +101,9 @@ export default async function(obj) {
|
|||
if (data.secure_media?.reddit_video?.duration > env.durationLimit)
|
||||
return { error: "content.too_long" };
|
||||
|
||||
const video = data.secure_media?.reddit_video?.fallback_url?.split('?')[0];
|
||||
|
||||
let audio = false,
|
||||
video = data.secure_media?.reddit_video?.fallback_url?.split('?')[0],
|
||||
audioFileLink = `${data.secure_media?.reddit_video?.fallback_url?.split('DASH')[0]}audio`;
|
||||
|
||||
if (video.match('.mp4')) {
|
||||
|
@ -121,7 +136,7 @@ export default async function(obj) {
|
|||
typeId: "tunnel",
|
||||
type: "merge",
|
||||
urls: [video, audioFileLink],
|
||||
audioFilename: `reddit_${id}_audio`,
|
||||
filename: `reddit_${id}.mp4`
|
||||
audioFilename: `reddit_${sourceId}_audio`,
|
||||
filename: `reddit_${sourceId}.mp4`
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ async function getStory(username, storyId, alwaysProxy) {
|
|||
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||
if (nextDataString) {
|
||||
const data = JSON.parse(nextDataString);
|
||||
const storyIdParam = data.query.profileParams[1];
|
||||
const storyIdParam = data?.query?.profileParams?.[1];
|
||||
|
||||
if (storyIdParam && data.props.pageProps.story) {
|
||||
if (storyIdParam && data?.props?.pageProps?.story) {
|
||||
const story = data.props.pageProps.story.snapList.find((snap) => snap.snapId.value === storyIdParam);
|
||||
if (story) {
|
||||
if (story.snapMediaType === 0) {
|
||||
|
@ -61,7 +61,7 @@ async function getStory(username, storyId, alwaysProxy) {
|
|||
}
|
||||
}
|
||||
|
||||
const defaultStory = data.props.pageProps.curatedHighlights[0];
|
||||
const defaultStory = data?.props?.pageProps?.curatedHighlights?.[0];
|
||||
if (defaultStory) {
|
||||
return {
|
||||
picker: defaultStory.snapList.map(snap => {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
{
|
||||
"name": "story",
|
||||
"url": "https://www.snapchat.com/add/bazerkmakane",
|
||||
"canFail": true,
|
||||
"params": {},
|
||||
"expected": {
|
||||
"code": 200,
|
||||
|
|
Loading…
Reference in a new issue