mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 19:28:29 +00:00
fix(snapchat): update with suggested changes
This commit is contained in:
parent
d725829743
commit
f091792b91
@ -9,21 +9,27 @@ async function getSpotlight(id) {
|
|||||||
const html = await fetch(`https://www.snapchat.com/spotlight/${id}`, {
|
const html = await fetch(`https://www.snapchat.com/spotlight/${id}`, {
|
||||||
headers: { 'User-Agent': genericUserAgent }
|
headers: { 'User-Agent': genericUserAgent }
|
||||||
}).then((r) => r.text()).catch(() => null);
|
}).then((r) => r.text()).catch(() => null);
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
if (!html) {
|
||||||
|
return { error: 'ErrorCouldntFetch' };
|
||||||
|
}
|
||||||
|
|
||||||
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
||||||
if (videoURL) return {
|
if (videoURL) {
|
||||||
|
return {
|
||||||
urls: videoURL,
|
urls: videoURL,
|
||||||
filename: `snapchat_${id}.mp4`,
|
filename: `snapchat_${id}.mp4`,
|
||||||
audioFilename: `snapchat_${id}_audio`
|
audioFilename: `snapchat_${id}_audio`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getStory(username, storyId) {
|
async function getStory(username, storyId) {
|
||||||
const html = await fetch(`https://www.snapchat.com/add/${username}${storyId ? `/${storyId}` : ''}`, {
|
const html = await fetch(`https://www.snapchat.com/add/${username}${storyId ? `/${storyId}` : ''}`, {
|
||||||
headers: { 'User-Agent': genericUserAgent }
|
headers: { 'User-Agent': genericUserAgent }
|
||||||
}).then((r) => r.text()).catch(() => null);
|
}).then((r) => r.text()).catch(() => null);
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
if (!html) {
|
||||||
|
return { error: 'ErrorCouldntFetch' };
|
||||||
|
}
|
||||||
|
|
||||||
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||||
if (nextDataString) {
|
if (nextDataString) {
|
||||||
@ -33,11 +39,12 @@ async function getStory(username, storyId) {
|
|||||||
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) {
|
||||||
return {
|
return {
|
||||||
urls: story.snapUrls.mediaUrl,
|
urls: story.snapUrls.mediaUrl,
|
||||||
isPhoto: true
|
isPhoto: true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: story.snapUrls.mediaUrl,
|
urls: story.snapUrls.mediaUrl,
|
||||||
@ -64,9 +71,16 @@ export default async function(obj) {
|
|||||||
let params = obj;
|
let params = obj;
|
||||||
if (obj.url.hostname === 't.snapchat.com' && obj.shortLink) {
|
if (obj.url.hostname === 't.snapchat.com' && obj.shortLink) {
|
||||||
const link = await getRedirectingURL(`https://t.snapchat.com/${obj.shortLink}`);
|
const link = await getRedirectingURL(`https://t.snapchat.com/${obj.shortLink}`);
|
||||||
if (!link || !link.startsWith('https://www.snapchat.com/')) return { error: 'ErrorCouldntFetch' };
|
|
||||||
|
if (!link?.startsWith('https://www.snapchat.com/')) {
|
||||||
|
return { error: 'ErrorCouldntFetch' };
|
||||||
|
}
|
||||||
|
|
||||||
const extractResult = extract(normalizeURL(link));
|
const extractResult = extract(normalizeURL(link));
|
||||||
if (!extractResult || extractResult.host !== 'snapchat') return { error: 'ErrorCouldntFetch' };
|
if (extractResult?.host !== 'snapchat') {
|
||||||
|
return { error: 'ErrorCouldntFetch' };
|
||||||
|
}
|
||||||
|
|
||||||
params = extractResult.patternMatch;
|
params = extractResult.patternMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user