mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-13 22:26:28 +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",
|
"name": "@imput/cobalt-api",
|
||||||
"description": "save what you love",
|
"description": "save what you love",
|
||||||
"version": "10.7",
|
"version": "10.7.2",
|
||||||
"author": "imput",
|
"author": "imput",
|
||||||
"exports": "./src/cobalt.js",
|
"exports": "./src/cobalt.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
@ -120,9 +120,8 @@ export default async function({ host, patternMatch, params }) {
|
||||||
|
|
||||||
case "reddit":
|
case "reddit":
|
||||||
r = await reddit({
|
r = await reddit({
|
||||||
sub: patternMatch.sub,
|
...patternMatch,
|
||||||
id: patternMatch.id,
|
dispatcher,
|
||||||
user: patternMatch.user
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,25 @@ export const services = {
|
||||||
},
|
},
|
||||||
instagram: {
|
instagram: {
|
||||||
patterns: [
|
patterns: [
|
||||||
"reels/:postId",
|
|
||||||
":username/reel/:postId",
|
|
||||||
"reel/:postId",
|
|
||||||
"p/:postId",
|
"p/:postId",
|
||||||
":username/p/:postId",
|
|
||||||
"tv/:postId",
|
"tv/:postId",
|
||||||
|
"reel/:postId",
|
||||||
|
"reels/:postId",
|
||||||
"stories/:username/:storyId",
|
"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"],
|
altDomains: ["ddinstagram.com"],
|
||||||
},
|
},
|
||||||
|
@ -65,8 +76,21 @@ export const services = {
|
||||||
},
|
},
|
||||||
reddit: {
|
reddit: {
|
||||||
patterns: [
|
patterns: [
|
||||||
|
"comments/:id",
|
||||||
|
|
||||||
|
"r/:sub/comments/:id",
|
||||||
"r/:sub/comments/:id/:title",
|
"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: "*",
|
subdomains: "*",
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,8 +20,10 @@ export const testers = {
|
||||||
pattern.id?.length <= 128 || pattern.shortLink?.length <= 32,
|
pattern.id?.length <= 128 || pattern.shortLink?.length <= 32,
|
||||||
|
|
||||||
"reddit": pattern =>
|
"reddit": pattern =>
|
||||||
(pattern.sub?.length <= 22 && pattern.id?.length <= 10)
|
pattern.id?.length <= 16 && !pattern.sub && !pattern.user
|
||||||
|| (pattern.user?.length <= 22 && pattern.id?.length <= 10),
|
|| (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 =>
|
"rutube": pattern =>
|
||||||
(pattern.id?.length === 32 && pattern.key?.length <= 32) ||
|
(pattern.id?.length === 32 && pattern.key?.length <= 32) ||
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { resolveRedirectingURL } from "../url.js";
|
||||||
import { genericUserAgent, env } from "../../config.js";
|
import { genericUserAgent, env } from "../../config.js";
|
||||||
import { getCookie, updateCookieValues } from "../cookie/manager.js";
|
import { getCookie, updateCookieValues } from "../cookie/manager.js";
|
||||||
|
|
||||||
|
@ -48,12 +49,20 @@ async function getAccessToken() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function(obj) {
|
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) {
|
if (!params.id && params.shareId) {
|
||||||
url.pathname = `/user/${obj.user}/comments/${obj.id}.json`;
|
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();
|
const accessToken = await getAccessToken();
|
||||||
if (accessToken) url.hostname = 'oauth.reddit.com';
|
if (accessToken) url.hostname = 'oauth.reddit.com';
|
||||||
|
|
||||||
|
@ -73,12 +82,17 @@ export default async function(obj) {
|
||||||
|
|
||||||
data = data[0]?.data?.children[0]?.data;
|
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 {
|
if (data?.url?.endsWith('.gif')) return {
|
||||||
typeId: "redirect",
|
typeId: "redirect",
|
||||||
urls: data.url,
|
urls: data.url,
|
||||||
filename: `reddit_${id}.gif`,
|
filename: `reddit_${sourceId}.gif`,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.secure_media?.reddit_video)
|
if (!data.secure_media?.reddit_video)
|
||||||
|
@ -87,8 +101,9 @@ export default async function(obj) {
|
||||||
if (data.secure_media?.reddit_video?.duration > env.durationLimit)
|
if (data.secure_media?.reddit_video?.duration > env.durationLimit)
|
||||||
return { error: "content.too_long" };
|
return { error: "content.too_long" };
|
||||||
|
|
||||||
|
const video = data.secure_media?.reddit_video?.fallback_url?.split('?')[0];
|
||||||
|
|
||||||
let audio = false,
|
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`;
|
audioFileLink = `${data.secure_media?.reddit_video?.fallback_url?.split('DASH')[0]}audio`;
|
||||||
|
|
||||||
if (video.match('.mp4')) {
|
if (video.match('.mp4')) {
|
||||||
|
@ -121,7 +136,7 @@ export default async function(obj) {
|
||||||
typeId: "tunnel",
|
typeId: "tunnel",
|
||||||
type: "merge",
|
type: "merge",
|
||||||
urls: [video, audioFileLink],
|
urls: [video, audioFileLink],
|
||||||
audioFilename: `reddit_${id}_audio`,
|
audioFilename: `reddit_${sourceId}_audio`,
|
||||||
filename: `reddit_${id}.mp4`
|
filename: `reddit_${sourceId}.mp4`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ async function getStory(username, storyId, alwaysProxy) {
|
||||||
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||||
if (nextDataString) {
|
if (nextDataString) {
|
||||||
const data = JSON.parse(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);
|
const story = data.props.pageProps.story.snapList.find((snap) => snap.snapId.value === storyIdParam);
|
||||||
if (story) {
|
if (story) {
|
||||||
if (story.snapMediaType === 0) {
|
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) {
|
if (defaultStory) {
|
||||||
return {
|
return {
|
||||||
picker: defaultStory.snapList.map(snap => {
|
picker: defaultStory.snapList.map(snap => {
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
{
|
{
|
||||||
"name": "story",
|
"name": "story",
|
||||||
"url": "https://www.snapchat.com/add/bazerkmakane",
|
"url": "https://www.snapchat.com/add/bazerkmakane",
|
||||||
"canFail": true,
|
|
||||||
"params": {},
|
"params": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
"code": 200,
|
"code": 200,
|
||||||
|
|
Loading…
Reference in a new issue