mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +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) {
|
switch (host) {
|
||||||
case "instagram":
|
case "instagram":
|
||||||
case "twitter":
|
case "twitter":
|
||||||
|
case "snapchat":
|
||||||
params = { picker: r.picker };
|
params = { picker: r.picker };
|
||||||
break;
|
break;
|
||||||
case "douyin":
|
case "douyin":
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { genericUserAgent } from "../../config.js";
|
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 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) {
|
export default async function(obj) {
|
||||||
let link;
|
let link;
|
||||||
@ -14,6 +15,8 @@ export default async function(obj) {
|
|||||||
|
|
||||||
if (!link && obj.username && obj.storyId) {
|
if (!link && obj.username && obj.storyId) {
|
||||||
link = `https://www.snapchat.com/add/${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) {
|
} else if (!link && obj.spotlightId) {
|
||||||
link = `https://www.snapchat.com/spotlight/${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 });
|
}).then((r) => { return r.text() }).catch(() => { return false });
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
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 nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||||
const videoURL = html.match(storyVideoRegex)?.[1];
|
if (nextDataString) {
|
||||||
if (videoURL) return {
|
const data = JSON.parse(nextDataString);
|
||||||
urls: videoURL,
|
const storyId = data.query.profileParams[1];
|
||||||
filename: `snapchat_${id}.mp4`,
|
|
||||||
audioFilename: `snapchat_${id}_audio`
|
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": {
|
"snapchat": {
|
||||||
"alias": "snapchat stories & spotlights",
|
"alias": "snapchat stories & spotlights",
|
||||||
"subdomains": ["t", "story"],
|
"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
|
"enabled": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ export const testers = {
|
|||||||
|| patternMatch.shortLink?.length <= 32,
|
|| patternMatch.shortLink?.length <= 32,
|
||||||
|
|
||||||
"snapchat": (patternMatch) =>
|
"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.spotlightId?.length <= 255
|
||||||
|| patternMatch.shortLink?.length <= 16,
|
|| patternMatch.shortLink?.length <= 16,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user