Skip to content

Commit

Permalink
merge: api 10.7.2 from main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
wukko committed Feb 10, 2025
2 parents fb739f5 + 0794788 commit ad23b70
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 25 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 2 additions & 3 deletions api/src/processing/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 30 additions & 6 deletions api/src/processing/service-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
Expand All @@ -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: "*",
},
Expand Down
6 changes: 4 additions & 2 deletions api/src/processing/service-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
33 changes: 24 additions & 9 deletions api/src/processing/services/reddit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resolveRedirectingURL } from "../url.js";
import { genericUserAgent, env } from "../../config.js";
import { getCookie, updateCookieValues } from "../cookie/manager.js";

Expand Down Expand Up @@ -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`);

if (obj.user) {
url.pathname = `/user/${obj.user}/comments/${obj.id}.json`;
let params = obj;

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';

Expand All @@ -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)
Expand All @@ -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')) {
Expand Down Expand Up @@ -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`
}
}
6 changes: 3 additions & 3 deletions api/src/processing/services/snapchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 => {
Expand Down
1 change: 0 additions & 1 deletion api/src/util/tests/snapchat.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
{
"name": "story",
"url": "https://www.snapchat.com/add/bazerkmakane",
"canFail": true,
"params": {},
"expected": {
"code": 200,
Expand Down

0 comments on commit ad23b70

Please sign in to comment.