Compare commits

...

6 commits

Author SHA1 Message Date
Snazzah 739ea58786
Merge 5dfc16b76c into 709d14ee9e 2024-04-30 00:56:20 +01:00
hyperdefined 709d14ee9e
feat: ddinstagram.com support (#402)
Co-authored-by: dumbmoron <log@riseup.net>
2024-04-30 01:11:25 +06:00
Snazzah 5dfc16b76c
chore: update readme 2024-04-18 13:11:43 -05:00
Snazzah 7ac9c2895b
chore: a bit of better matching 2024-04-15 21:46:52 -05:00
Snazzah 48c48c61de
chore: remove redundancy 2024-04-15 21:43:36 -05:00
Snazzah 0dfc59a972
feat: snapchat support 2024-04-15 21:42:19 -05:00
8 changed files with 127 additions and 1 deletions

View file

@ -21,6 +21,7 @@ this list is not final and keeps expanding over time. if support for a service y
| pinterest | ✅ | ✅ | ✅ | | |
| reddit | ✅ | ✅ | ✅ | ❌ | ❌ |
| rutube | ✅ | ✅ | ✅ | ✅ | ✅ |
| snapchat stories & spotlights | ✅ | ✅ | ✅ | | |
| soundcloud | | ✅ | | ✅ | ✅ |
| streamable | ✅ | ✅ | ✅ | | |
| tiktok | ✅ | ✅ | ✅ | ❌ | ❌ |
@ -44,6 +45,7 @@ this list is not final and keeps expanding over time. if support for a service y
| instagram | supports photos, videos, and stories. lets you pick what to save from multi-media posts. |
| pinterest | supports videos and stories. |
| reddit | supports gifs and videos. |
| snapchat | supports spotlights and stories. stories will need to be directly linked to a video. |
| soundcloud | supports private links. |
| tiktok | supports videos with or without watermark, images from slideshow without watermark, and full (original) audios. |
| twitter/x | lets you pick what to save from multi-media posts. may not be 100% reliable due to current management. |

View file

@ -25,6 +25,7 @@ import streamable from "./services/streamable.js";
import twitch from "./services/twitch.js";
import rutube from "./services/rutube.js";
import dailymotion from "./services/dailymotion.js";
import snapchat from "./services/snapchat.js";
export default async function(host, patternMatch, url, lang, obj) {
assert(url instanceof URL);
@ -159,6 +160,15 @@ export default async function(host, patternMatch, url, lang, obj) {
case "dailymotion":
r = await dailymotion(patternMatch);
break;
case "snapchat":
r = await snapchat({
url,
username: patternMatch.username,
storyId: patternMatch.storyId,
spotlightId: patternMatch.spotlightId,
shortLink: patternMatch.shortLink || false
});
break;
default:
return apiJSON(0, { t: errorUnsupported(lang) });
}

View file

@ -120,6 +120,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
case "tumblr":
case "pinterest":
case "streamable":
case "snapchat":
responseType = 1;
break;
}

View file

@ -0,0 +1,54 @@
import { genericUserAgent } from "../../config.js";
const SPOTLIGHT_VIDEO_REGEX = /<link data-react-helmet="true" rel="preload" href="(https:\/\/cf-st\.sc-cdn\.net\/d\/[\w.?=]+&amp;uc=\d+)" as="video"\/>/;
export default async function(obj) {
let link;
if (obj.url.hostname === 't.snapchat.com' && obj.shortLink) {
link = await fetch(`https://t.snapchat.com/${obj.shortLink}`, { redirect: "manual" }).then((r) => {
if (r.status === 303 && r.headers.get("location").startsWith("https://www.snapchat.com/")) {
return r.headers.get("location").split('?', 1)[0]
}
}).catch(() => {});
}
if (!link && obj.username && obj.storyId) {
link = `https://www.snapchat.com/add/${obj.username}/${obj.storyId}`
} else if (!link && obj.spotlightId) {
link = `https://www.snapchat.com/spotlight/${obj.spotlightId}`
}
const path = new URL(link).pathname;
if (path.startsWith('/spotlight/')) {
const html = await fetch(link, {
headers: { "user-agent": genericUserAgent }
}).then((r) => { return r.text() }).catch(() => { return false });
if (!html) return { error: 'ErrorCouldntFetch' };
const id = path.split('/')[2];
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
if (videoURL) return {
urls: videoURL,
filename: `snapchat_${id}.mp4`,
audioFilename: `snapchat_${id}_audio`
}
} else if (path.startsWith('/add/')) {
const html = await fetch(link, {
headers: { "user-agent": genericUserAgent }
}).then((r) => { return r.text() }).catch(() => { return false });
if (!html) return { error: 'ErrorCouldntFetch' };
const id = path.split('/')[3];
const storyVideoRegex = new RegExp(`"snapId":{"value":"${id}"},"snapMediaType":1,"snapUrls":{"mediaUrl":"(https:\\/\\/bolt-gcdn\\.sc-cdn\\.net\\/3\/[^"]+)","mediaPreviewUrl"`);
const videoURL = html.match(storyVideoRegex)?.[1];
if (videoURL) return {
urls: videoURL,
filename: `snapchat_${id}.mp4`,
audioFilename: `snapchat_${id}_audio`
}
}
return { error: 'ErrorCouldntFetch' };
}

View file

@ -79,6 +79,7 @@
},
"instagram": {
"alias": "instagram reels, posts & stories",
"altDomains": ["ddinstagram.com"],
"patterns": [
"reels/:postId", ":username/reel/:postId", "reel/:postId", "p/:postId", ":username/p/:postId",
"tv/:postId", "stories/:username/:storyId"
@ -117,6 +118,12 @@
"alias": "dailymotion videos",
"patterns": ["video/:id"],
"enabled": true
},
"snapchat": {
"alias": "snapchat stories & spotlights",
"subdomains": ["t", "story"],
"patterns": [":shortLink", "spotlight/:spotlightId", "add/:username/:storyId", "u/:username/:storyId"],
"enabled": true
}
}
}

View file

@ -25,6 +25,11 @@ export const testers = {
(patternMatch.author?.length <= 255 && patternMatch.song?.length <= 255)
|| patternMatch.shortLink?.length <= 32,
"snapchat": (patternMatch) =>
(patternMatch.username?.length <= 32 && patternMatch.storyId?.length <= 255)
|| patternMatch.spotlightId?.length <= 255
|| patternMatch.shortLink?.length <= 16,
"streamable": (patternMatch) =>
patternMatch.id?.length === 6,

View file

@ -64,6 +64,12 @@ export function aliasURL(url) {
if (url.hostname === 'dai.ly' && parts.length === 2) {
url = new URL(`https://dailymotion.com/video/${parts[1]}`)
}
break;
case "ddinstagram":
if (services.instagram.altDomains.includes(host.domain) && [null, 'd', 'g'].includes(host.subdomain)) {
url.hostname = 'instagram.com';
}
break;
}
return url

View file

@ -878,6 +878,30 @@
"code": 200,
"status": "redirect"
}
}, {
"name": "ddinstagram link",
"url": "https://ddinstagram.com/p/CmCVWoIr9OH/",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}, {
"name": "d.ddinstagram.com link",
"url": "https://d.ddinstagram.com/p/CmCVWoIr9OH/",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}, {
"name": "g.ddinstagram.com link",
"url": "https://g.ddinstagram.com/p/CmCVWoIr9OH/",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}],
"vine": [{
"name": "regular vine link (9+10=21)",
@ -1131,5 +1155,22 @@
"code": 200,
"status": "stream"
}
}],
"snapchat": [{
"name": "spotlight",
"url": "https://www.snapchat.com/spotlight/W7_EDlXWTBiXAEEniNoMPwAAYdWxucG9pZmNqAY46j0a5AY46j0YbAAAAAQ",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}, {
"name": "shortlinked spotlight",
"url": "https://t.snapchat.com/4ZsiBLDi",
"params": {},
"expected": {
"code": 200,
"status": "redirect"
}
}]
}
}