snapchat: clean up
This commit is contained in:
parent
83af16bb12
commit
a388839e15
2 changed files with 14 additions and 14 deletions
|
@ -192,7 +192,7 @@ export default async function(host, patternMatch, lang, obj) {
|
||||||
break;
|
break;
|
||||||
case "snapchat":
|
case "snapchat":
|
||||||
r = await snapchat({
|
r = await snapchat({
|
||||||
url,
|
hostname: url.hostname,
|
||||||
...patternMatch
|
...patternMatch
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,8 +9,8 @@ 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) {
|
if (!html) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'ErrorCouldntFetch' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
||||||
|
@ -27,9 +27,9 @@ 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) {
|
if (!html) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'ErrorCouldntFetch' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
const nextDataString = html.match(NEXT_DATA_REGEX)?.[1];
|
||||||
if (nextDataString) {
|
if (nextDataString) {
|
||||||
|
@ -67,18 +67,18 @@ async function getStory(username, storyId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function(obj) {
|
export default async function (obj) {
|
||||||
let params = obj;
|
let params = obj;
|
||||||
if (obj.url.hostname === 't.snapchat.com' && obj.shortLink) {
|
if (obj.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?.startsWith('https://www.snapchat.com/')) {
|
if (!link?.startsWith('https://www.snapchat.com/')) {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'ErrorCouldntFetch' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractResult = extract(normalizeURL(link));
|
const extractResult = extract(normalizeURL(link));
|
||||||
if (extractResult?.host !== 'snapchat') {
|
if (extractResult?.host !== 'snapchat') {
|
||||||
return { error: 'ErrorCouldntFetch' };
|
return { error: 'ErrorCouldntFetch' };
|
||||||
}
|
}
|
||||||
|
|
||||||
params = extractResult.patternMatch;
|
params = extractResult.patternMatch;
|
||||||
|
|
Loading…
Reference in a new issue