mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 03:08:30 +00:00
refactor(snapchat): refactor story matching to use pickers
This commit is contained in:
parent
5dfc16b76c
commit
4b4adc4e8b
@ -63,6 +63,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
|
||||
switch (host) {
|
||||
case "instagram":
|
||||
case "twitter":
|
||||
case "snapchat":
|
||||
params = { picker: r.picker };
|
||||
break;
|
||||
case "douyin":
|
||||
|
@ -1,6 +1,7 @@
|
||||
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.?=]+&uc=\d+)" as="video"\/>/;
|
||||
const NEXT_DATA_REGEX = /<script id="__NEXT_DATA__" type="application\/json">({.+})<\/script><\/body><\/html>$/;
|
||||
|
||||
export default async function(obj) {
|
||||
let link;
|
||||
@ -14,6 +15,8 @@ export default async function(obj) {
|
||||
|
||||
if (!link && obj.username && obj.storyId) {
|
||||
link = `https://www.snapchat.com/add/${obj.username}/${obj.storyId}`
|
||||
} if (!link && obj.username) {
|
||||
link = `https://www.snapchat.com/add/${obj.username}`
|
||||
} else if (!link && obj.spotlightId) {
|
||||
link = `https://www.snapchat.com/spotlight/${obj.spotlightId}`
|
||||
}
|
||||
@ -39,13 +42,38 @@ export default async function(obj) {
|
||||
}).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`
|
||||
|
||||
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||
if (nextDataString) {
|
||||
const data = JSON.parse(nextDataString);
|
||||
const storyId = data.query.profileParams[1];
|
||||
|
||||
if (storyId) {
|
||||
const story = data.props.pageProps.story.snapList.find((snap) => snap.snapId.value === storyId);
|
||||
if (story) {
|
||||
if (story.snapMediaType === 0)
|
||||
return {
|
||||
urls: story.snapUrls.mediaUrl,
|
||||
isPhoto: true
|
||||
}
|
||||
|
||||
return {
|
||||
urls: story.snapUrls.mediaUrl,
|
||||
filename: `snapchat_${id}.mp4`,
|
||||
audioFilename: `snapchat_${id}_audio`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultStory = data.props.pageProps.curatedHighlights[0];
|
||||
if (defaultStory)
|
||||
return {
|
||||
picker: defaultStory.snapList.map((snap) => ({
|
||||
type: snap.snapMediaType === 0 ? "photo" : "video",
|
||||
url: snap.snapUrls.mediaUrl,
|
||||
thumb: snap.snapUrls.mediaPreviewUrl.value
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@
|
||||
"snapchat": {
|
||||
"alias": "snapchat stories & spotlights",
|
||||
"subdomains": ["t", "story"],
|
||||
"patterns": [":shortLink", "spotlight/:spotlightId", "add/:username/:storyId", "u/:username/:storyId"],
|
||||
"patterns": [":shortLink", "spotlight/:spotlightId", "add/:username/:storyId", "u/:username/:storyId", "add/:username", "u/:username"],
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export const testers = {
|
||||
|| patternMatch.shortLink?.length <= 32,
|
||||
|
||||
"snapchat": (patternMatch) =>
|
||||
(patternMatch.username?.length <= 32 && patternMatch.storyId?.length <= 255)
|
||||
(patternMatch.username?.length <= 32 && (!patternMatch.storyId || patternMatch.storyId?.length <= 255))
|
||||
|| patternMatch.spotlightId?.length <= 255
|
||||
|| patternMatch.shortLink?.length <= 16,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user