mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-01 04:36:02 +00:00
api/snapchat: always proxy picker thumbs & support proxying everything
This commit is contained in:
parent
892b875e3f
commit
0852f5dc09
|
@ -215,7 +215,10 @@ export default async function(host, patternMatch, obj) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "snapchat":
|
case "snapchat":
|
||||||
r = await snapchat(patternMatch);
|
r = await snapchat({
|
||||||
|
...patternMatch,
|
||||||
|
alwaysProxy: obj.alwaysProxy,
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "loom":
|
case "loom":
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { extract, normalizeURL } from "../url.js";
|
import { extract, normalizeURL } from "../url.js";
|
||||||
import { genericUserAgent } from "../../config.js";
|
import { genericUserAgent } from "../../config.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="(https:\/\/cf-st\.sc-cdn\.net\/d\/[\w.?=]+&uc=\d+)" as="video"\/>/;
|
||||||
|
@ -23,7 +24,7 @@ async function getSpotlight(id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getStory(username, storyId) {
|
async function getStory(username, storyId, alwaysProxy) {
|
||||||
const html = await fetch(
|
const html = await fetch(
|
||||||
`https://www.snapchat.com/add/${username}${storyId ? `/${storyId}` : ''}`,
|
`https://www.snapchat.com/add/${username}${storyId ? `/${storyId}` : ''}`,
|
||||||
{ headers: { 'user-agent': genericUserAgent } }
|
{ headers: { 'user-agent': genericUserAgent } }
|
||||||
|
@ -46,6 +47,7 @@ async function getStory(username, storyId) {
|
||||||
if (story.snapMediaType === 0) {
|
if (story.snapMediaType === 0) {
|
||||||
return {
|
return {
|
||||||
urls: story.snapUrls.mediaUrl,
|
urls: story.snapUrls.mediaUrl,
|
||||||
|
filename: `snapchat_${storyId}.jpg`,
|
||||||
isPhoto: true
|
isPhoto: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,11 +63,33 @@ async function getStory(username, storyId) {
|
||||||
const defaultStory = data.props.pageProps.curatedHighlights[0];
|
const defaultStory = data.props.pageProps.curatedHighlights[0];
|
||||||
if (defaultStory) {
|
if (defaultStory) {
|
||||||
return {
|
return {
|
||||||
picker: defaultStory.snapList.map(snap => ({
|
picker: defaultStory.snapList.map(snap => {
|
||||||
type: snap.snapMediaType === 0 ? 'photo' : 'video',
|
const snapType = snap.snapMediaType === 0 ? "photo" : "video";
|
||||||
url: snap.snapUrls.mediaUrl,
|
const snapExt = snapType === "video" ? "mp4" : "jpg";
|
||||||
thumb: snap.snapMediaType !== 0 ? snap.snapUrls.mediaPreviewUrl.value : undefined,
|
let snapUrl = snap.snapUrls.mediaUrl;
|
||||||
}))
|
|
||||||
|
const proxy = createStream({
|
||||||
|
service: "snapchat",
|
||||||
|
type: "proxy",
|
||||||
|
u: snapUrl,
|
||||||
|
filename: `snapchat_${username}_${snap.timestampInSec.value}.${snapExt}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
let thumbProxy;
|
||||||
|
if (snapType === "video") thumbProxy = createStream({
|
||||||
|
service: "snapchat",
|
||||||
|
type: "proxy",
|
||||||
|
u: snap.snapUrls.mediaPreviewUrl.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (alwaysProxy) snapUrl = proxy;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: snapType,
|
||||||
|
url: snapUrl,
|
||||||
|
thumb: thumbProxy || proxy,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +116,7 @@ export default async function (obj) {
|
||||||
const result = await getSpotlight(params.spotlightId);
|
const result = await getSpotlight(params.spotlightId);
|
||||||
if (result) return result;
|
if (result) return result;
|
||||||
} else if (params.username) {
|
} else if (params.username) {
|
||||||
const result = await getStory(params.username, params.storyId);
|
const result = await getStory(params.username, params.storyId, obj.alwaysProxy);
|
||||||
if (result) return result;
|
if (result) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue