mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api/snapchat: fix spotlight url extraction
This commit is contained in:
parent
e2c8723c0e
commit
498e6f4419
1 changed files with 4 additions and 2 deletions
|
@ -3,19 +3,21 @@ import { genericUserAgent } from "../../config.js";
|
||||||
import { createStream } from "../../stream/manage.js";
|
import { createStream } from "../../stream/manage.js";
|
||||||
import { getRedirectingURL } from "../../misc/utils.js";
|
import { getRedirectingURL } from "../../misc/utils.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="(.+)" as="video"\/>/;
|
||||||
const NEXT_DATA_REGEX = /<script id="__NEXT_DATA__" type="application\/json">({.+})<\/script><\/body><\/html>$/;
|
const NEXT_DATA_REGEX = /<script id="__NEXT_DATA__" type="application\/json">({.+})<\/script><\/body><\/html>$/;
|
||||||
|
|
||||||
async function getSpotlight(id) {
|
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: "fetch.fail" };
|
return { error: "fetch.fail" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1];
|
||||||
if (videoURL) {
|
|
||||||
|
if (videoURL && new URL(videoURL).hostname.endsWith(".sc-cdn.net")) {
|
||||||
return {
|
return {
|
||||||
urls: videoURL,
|
urls: videoURL,
|
||||||
filename: `snapchat_${id}.mp4`,
|
filename: `snapchat_${id}.mp4`,
|
||||||
|
|
Loading…
Reference in a new issue