mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +00:00
first commit, add facebook
This commit is contained in:
parent
6d17ff2e06
commit
12c36f7ced
@ -25,6 +25,7 @@ import streamable from "./services/streamable.js";
|
|||||||
import twitch from "./services/twitch.js";
|
import twitch from "./services/twitch.js";
|
||||||
import rutube from "./services/rutube.js";
|
import rutube from "./services/rutube.js";
|
||||||
import dailymotion from "./services/dailymotion.js";
|
import dailymotion from "./services/dailymotion.js";
|
||||||
|
import facebook from "./services/facebook.js";
|
||||||
|
|
||||||
export default async function(host, patternMatch, url, lang, obj) {
|
export default async function(host, patternMatch, url, lang, obj) {
|
||||||
assert(url instanceof URL);
|
assert(url instanceof URL);
|
||||||
@ -157,6 +158,9 @@ export default async function(host, patternMatch, url, lang, obj) {
|
|||||||
break;
|
break;
|
||||||
case "dailymotion":
|
case "dailymotion":
|
||||||
r = await dailymotion(patternMatch);
|
r = await dailymotion(patternMatch);
|
||||||
|
break;
|
||||||
|
case "facebook":
|
||||||
|
r = await facebook(patternMatch);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return apiJSON(0, { t: errorUnsupported(lang) });
|
return apiJSON(0, { t: errorUnsupported(lang) });
|
||||||
|
71
src/modules/processing/services/facebook.js
Normal file
71
src/modules/processing/services/facebook.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import { genericUserAgent } from "../../config.js";
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'User-Agent': genericUserAgent,
|
||||||
|
'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-Encoding': 'gzip, deflate, br',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-Site': 'none',
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveUrl(url) {
|
||||||
|
return fetch(url, { headers })
|
||||||
|
.then(r => {
|
||||||
|
if (r.headers.get('location')) {
|
||||||
|
return decodeURIComponent(r.headers.get('location'))
|
||||||
|
}
|
||||||
|
if (r.headers.get('link')) {
|
||||||
|
const linkMatch = r.headers.get('link').match(/<(.*?)\/>/)
|
||||||
|
return decodeURIComponent(linkMatch[1])
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
.catch(() => false)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function ({ shortLink, username, id }) {
|
||||||
|
const isShortLink = !!shortLink?.length
|
||||||
|
|
||||||
|
let url = isShortLink
|
||||||
|
? `https://fb.watch/${shortLink}`
|
||||||
|
: `https://web.facebook.com/${username}/videos/${id}`
|
||||||
|
|
||||||
|
if (isShortLink) {
|
||||||
|
url = await resolveUrl(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = await fetch(url, { headers })
|
||||||
|
.then(r => r.text())
|
||||||
|
.catch(() => false)
|
||||||
|
|
||||||
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
|
const urls = []
|
||||||
|
const hd = html.match('"browser_native_hd_url":"(.*?)"')
|
||||||
|
const sd = html.match('"browser_native_sd_url":"(.*?)"')
|
||||||
|
|
||||||
|
if (hd?.length) {
|
||||||
|
urls.push(JSON.parse(`["${hd[1]}"]`)[0])
|
||||||
|
}
|
||||||
|
if (sd?.length) {
|
||||||
|
urls.push(JSON.parse(`["${sd[1]}"]`)[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!urls.length) {
|
||||||
|
return { error: 'ErrorEmptyDownload' };
|
||||||
|
}
|
||||||
|
|
||||||
|
let filename = `facebook_${id}.mp4`
|
||||||
|
if (isShortLink) {
|
||||||
|
filename = `facebook_${shortLink}.mp4`
|
||||||
|
} else if (username?.length && username !== 'user') {
|
||||||
|
filename = `facebook_${username}_${id}.mp4`
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
urls: urls[0],
|
||||||
|
filename,
|
||||||
|
audioFilename: `${filename.slice(0, -4)}_audio`,
|
||||||
|
};
|
||||||
|
}
|
@ -115,6 +115,18 @@
|
|||||||
"dailymotion": {
|
"dailymotion": {
|
||||||
"alias": "dailymotion videos",
|
"alias": "dailymotion videos",
|
||||||
"patterns": ["video/:id"],
|
"patterns": ["video/:id"],
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"facebook": {
|
||||||
|
"alias": "facebook videos",
|
||||||
|
"altDomains": ["fb.watch"],
|
||||||
|
"subdomains": ["web"],
|
||||||
|
"patterns": [
|
||||||
|
"_shortLink/:shortLink",
|
||||||
|
":username/videos/:caption/:id",
|
||||||
|
":username/videos/:id",
|
||||||
|
"reel/:id"
|
||||||
|
],
|
||||||
"enabled": true
|
"enabled": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ export const testers = {
|
|||||||
|| patternMatch.tvId?.length <= 24,
|
|| patternMatch.tvId?.length <= 24,
|
||||||
|
|
||||||
"dailymotion": (patternMatch) => patternMatch.id?.length <= 32,
|
"dailymotion": (patternMatch) => patternMatch.id?.length <= 32,
|
||||||
|
|
||||||
"instagram": (patternMatch) =>
|
"instagram": (patternMatch) =>
|
||||||
patternMatch.postId?.length <= 12
|
patternMatch.postId?.length <= 12
|
||||||
|| (patternMatch.username?.length <= 30 && patternMatch.storyId?.length <= 24),
|
|| (patternMatch.username?.length <= 30 && patternMatch.storyId?.length <= 24),
|
||||||
@ -14,10 +13,8 @@ export const testers = {
|
|||||||
|
|
||||||
"pinterest": (patternMatch) =>
|
"pinterest": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 128 || patternMatch.shortLink?.length <= 32,
|
patternMatch.id?.length <= 128 || patternMatch.shortLink?.length <= 32,
|
||||||
|
|
||||||
"reddit": (patternMatch) =>
|
"reddit": (patternMatch) =>
|
||||||
patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10,
|
patternMatch.sub?.length <= 22 && patternMatch.id?.length <= 10,
|
||||||
|
|
||||||
"rutube": (patternMatch) =>
|
"rutube": (patternMatch) =>
|
||||||
patternMatch.id?.length === 32,
|
patternMatch.id?.length === 32,
|
||||||
|
|
||||||
@ -34,23 +31,24 @@ export const testers = {
|
|||||||
"tumblr": (patternMatch) =>
|
"tumblr": (patternMatch) =>
|
||||||
patternMatch.id?.length < 21
|
patternMatch.id?.length < 21
|
||||||
|| (patternMatch.id?.length < 21 && patternMatch.user?.length <= 32),
|
|| (patternMatch.id?.length < 21 && patternMatch.user?.length <= 32),
|
||||||
|
|
||||||
"twitch": (patternMatch) =>
|
"twitch": (patternMatch) =>
|
||||||
patternMatch.channel && patternMatch.clip?.length <= 100,
|
patternMatch.channel && patternMatch.clip?.length <= 100,
|
||||||
|
|
||||||
"twitter": (patternMatch) =>
|
"twitter": (patternMatch) =>
|
||||||
patternMatch.id?.length < 20,
|
patternMatch.id?.length < 20,
|
||||||
|
|
||||||
"vimeo": (patternMatch) =>
|
"vimeo": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 11
|
patternMatch.id?.length <= 11
|
||||||
&& (!patternMatch.password || patternMatch.password.length < 16),
|
&& (!patternMatch.password || patternMatch.password.length < 16),
|
||||||
|
|
||||||
"vine": (patternMatch) =>
|
"vine": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 12,
|
patternMatch.id?.length <= 12,
|
||||||
|
|
||||||
"vk": (patternMatch) =>
|
"vk": (patternMatch) =>
|
||||||
patternMatch.userId?.length <= 10 && patternMatch.videoId?.length <= 10,
|
patternMatch.userId?.length <= 10 && patternMatch.videoId?.length <= 10,
|
||||||
|
|
||||||
"youtube": (patternMatch) =>
|
"youtube": (patternMatch) =>
|
||||||
patternMatch.id?.length <= 11,
|
patternMatch.id?.length <= 11,
|
||||||
|
|
||||||
|
"facebook": (patternMatch) =>
|
||||||
|
patternMatch.shortLink?.length <= 11
|
||||||
|
|| patternMatch.username?.length <= 30
|
||||||
|
|| patternMatch.caption?.length <= 255
|
||||||
|
|| patternMatch.id?.length <= 20,
|
||||||
}
|
}
|
@ -64,6 +64,16 @@ export function aliasURL(url) {
|
|||||||
if (url.hostname === 'dai.ly' && parts.length === 2) {
|
if (url.hostname === 'dai.ly' && parts.length === 2) {
|
||||||
url = new URL(`https://dailymotion.com/video/${parts[1]}`)
|
url = new URL(`https://dailymotion.com/video/${parts[1]}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "facebook":
|
||||||
|
case "fb":
|
||||||
|
if (url.searchParams.get('v')) {
|
||||||
|
url = new URL(`https://web.facebook.com/user/videos/${url.searchParams.get('v')}`)
|
||||||
|
}
|
||||||
|
if (url.hostname === 'fb.watch') {
|
||||||
|
url = new URL(`https://web.facebook.com/_shortLink/${parts[1]}`)
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
@ -1115,5 +1115,46 @@
|
|||||||
"code": 200,
|
"code": 200,
|
||||||
"status": "stream"
|
"status": "stream"
|
||||||
}
|
}
|
||||||
|
}],
|
||||||
|
"facebook": [{
|
||||||
|
"name": "direct video with username and id",
|
||||||
|
"url": "https://web.facebook.com/100048111287134/videos/1157798148685638/",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "direct video with id as query param",
|
||||||
|
"url": "https://web.facebook.com/watch/?v=883839773514682&ref=sharing",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "direct video with caption",
|
||||||
|
"url": "https://web.facebook.com/wood57/videos/𝐒𝐞𝐛𝐚𝐬𝐤𝐨𝐦-𝐟𝐮𝐥𝐥/883839773514682",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "shortlink video",
|
||||||
|
"url": "https://fb.watch/r1K6XHMfGT/",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"name": "reel video",
|
||||||
|
"url": "https://web.facebook.com/reel/730293269054758",
|
||||||
|
"params": {},
|
||||||
|
"expected": {
|
||||||
|
"code": 200,
|
||||||
|
"status": "stream"
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user