mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +00:00
Merge branch 'current' into newgrounds-support
This commit is contained in:
commit
2dfd4f7da0
@ -193,7 +193,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;
|
||||||
@ -204,8 +204,7 @@ export default async function(host, patternMatch, lang, obj) {
|
|||||||
break;
|
break;
|
||||||
case "facebook":
|
case "facebook":
|
||||||
r = await facebook({
|
r = await facebook({
|
||||||
...patternMatch,
|
...patternMatch
|
||||||
sourceUrl: url.href
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "newgrounds":
|
case "newgrounds":
|
||||||
|
@ -4,59 +4,53 @@ const headers = {
|
|||||||
'User-Agent': genericUserAgent,
|
'User-Agent': genericUserAgent,
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
||||||
'Accept-Language': 'en-US,en;q=0.5',
|
'Accept-Language': 'en-US,en;q=0.5',
|
||||||
'Accept-Encoding': 'gzip, deflate, br',
|
|
||||||
'Sec-Fetch-Mode': 'navigate',
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
'Sec-Fetch-Site': 'none',
|
'Sec-Fetch-Site': 'none',
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveUrl(url) {
|
const resolveUrl = (url) => {
|
||||||
return fetch(url, { headers })
|
return fetch(url, { headers })
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.headers.get('location')) {
|
if (r.headers.get('location')) {
|
||||||
return decodeURIComponent(r.headers.get('location'))
|
return decodeURIComponent(r.headers.get('location'));
|
||||||
}
|
}
|
||||||
if (r.headers.get('link')) {
|
if (r.headers.get('link')) {
|
||||||
const linkMatch = r.headers.get('link').match(/<(.*?)\/>/)
|
const linkMatch = r.headers.get('link').match(/<(.*?)\/>/);
|
||||||
return decodeURIComponent(linkMatch[1])
|
return decodeURIComponent(linkMatch[1]);
|
||||||
}
|
}
|
||||||
return false
|
return false;
|
||||||
})
|
})
|
||||||
.catch(() => false)
|
.catch(() => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function({ sourceUrl, shortLink, username, id }) {
|
export default async function({ id, shareType, shortLink }) {
|
||||||
const isShortLink = !!shortLink?.length
|
let url = `https://web.facebook.com/i/videos/${id}`;
|
||||||
const isSharedLink = !!sourceUrl.match(/\/share\/\w\//)?.length
|
|
||||||
|
|
||||||
let url = isShortLink
|
if (shareType) url = `https://web.facebook.com/share/${shareType}/${id}`;
|
||||||
? `https://fb.watch/${shortLink}`
|
if (shortLink) url = await resolveUrl(`https://fb.watch/${shortLink}`);
|
||||||
: `https://web.facebook.com/${username}/videos/${id}`
|
|
||||||
|
|
||||||
if (isShortLink) url = await resolveUrl(url)
|
|
||||||
if (isSharedLink) url = sourceUrl
|
|
||||||
|
|
||||||
const html = await fetch(url, { headers })
|
const html = await fetch(url, { headers })
|
||||||
.then(r => r.text())
|
.then(r => r.text())
|
||||||
.catch(() => false)
|
.catch(() => false);
|
||||||
|
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
const urls = []
|
const urls = [];
|
||||||
const hd = html.match('"browser_native_hd_url":(".*?")')
|
const hd = html.match('"browser_native_hd_url":(".*?")');
|
||||||
const sd = html.match('"browser_native_sd_url":(".*?")')
|
const sd = html.match('"browser_native_sd_url":(".*?")');
|
||||||
|
|
||||||
if (hd?.[1]) urls.push(JSON.parse(hd[1]))
|
if (hd?.[1]) urls.push(JSON.parse(hd[1]));
|
||||||
if (sd?.[1]) urls.push(JSON.parse(sd[1]))
|
if (sd?.[1]) urls.push(JSON.parse(sd[1]));
|
||||||
|
|
||||||
if (!urls.length) {
|
if (!urls.length) {
|
||||||
return { error: 'ErrorEmptyDownload' };
|
return { error: 'ErrorEmptyDownload' };
|
||||||
}
|
}
|
||||||
|
|
||||||
let filename = `facebook_${id || shortLink}.mp4`
|
const baseFilename = `facebook_${id || shortLink}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: urls[0],
|
urls: urls[0],
|
||||||
filename,
|
filename: `${baseFilename}.mp4`,
|
||||||
audioFilename: `${filename.slice(0, -4)}_audio`,
|
audioFilename: `${baseFilename}_audio`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
":username/videos/:caption/:id",
|
":username/videos/:caption/:id",
|
||||||
":username/videos/:id",
|
":username/videos/:id",
|
||||||
"reel/:id",
|
"reel/:id",
|
||||||
"share/:shortLink/:id"
|
"share/:shareType/:id"
|
||||||
],
|
],
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
|
@ -68,10 +68,11 @@ export const testers = {
|
|||||||
patternMatch.shortLink?.length <= 11
|
patternMatch.shortLink?.length <= 11
|
||||||
|| patternMatch.username?.length <= 30
|
|| patternMatch.username?.length <= 30
|
||||||
|| patternMatch.caption?.length <= 255
|
|| patternMatch.caption?.length <= 255
|
||||||
|| patternMatch.id?.length <= 20,
|
|| patternMatch.id?.length <= 20 && !patternMatch.shareType
|
||||||
|
|| patternMatch.id?.length <= 20 && patternMatch.shareType?.length === 1,
|
||||||
|
|
||||||
"newgrounds": (patternMatch) =>
|
"newgrounds": (patternMatch) =>
|
||||||
(patternMatch.type == 'portal' && patternMatch.method == 'view')
|
(patternMatch.type == 'portal' && patternMatch.method == 'view')
|
||||||
|| (patternMatch.type == 'audio' && patternMatch.method == 'listen')
|
|| (patternMatch.type == 'audio' && patternMatch.method == 'listen')
|
||||||
&& patternMatch.id?.length >= 1,
|
&& patternMatch.id?.length >= 1,
|
||||||
}
|
}
|
@ -1064,7 +1064,7 @@
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"name": "yappy",
|
"name": "yappy",
|
||||||
"url": "https://rutube.ru/yappy/a06b1bf53bce403b9a069107f23c47eb/",
|
"url": "https://rutube.ru/yappy/c8c32bf7aee04412837656ea26c2b25b/",
|
||||||
"params": {},
|
"params": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
"code": 200,
|
"code": 200,
|
||||||
@ -1231,6 +1231,7 @@
|
|||||||
}, {
|
}, {
|
||||||
"name": "reel video",
|
"name": "reel video",
|
||||||
"url": "https://web.facebook.com/reel/730293269054758",
|
"url": "https://web.facebook.com/reel/730293269054758",
|
||||||
|
"canFail": true,
|
||||||
"params": {},
|
"params": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
"code": 200,
|
"code": 200,
|
||||||
|
Loading…
Reference in New Issue
Block a user