fix: facebook shared link pattern with clean up

This commit is contained in:
Brama Udi 2024-07-07 21:39:30 +07:00
parent 98929c493c
commit 20975cb0fd
No known key found for this signature in database
GPG Key ID: C163FBB0BB454FBD

View File

@ -26,19 +26,14 @@ function resolveUrl(url) {
export default async function({ sourceUrl, shortLink, username, id }) { export default async function({ sourceUrl, shortLink, username, id }) {
const isShortLink = !!shortLink?.length const isShortLink = !!shortLink?.length
const isSharedLink = !!sourceUrl.match(/\/share\/v\//)?.length const isSharedLink = !!sourceUrl.match(/\/share\/\w\//)?.length
let url = isShortLink let url = isShortLink
? `https://fb.watch/${shortLink}` ? `https://fb.watch/${shortLink}`
: `https://web.facebook.com/${username}/videos/${id}` : `https://web.facebook.com/${username}/videos/${id}`
if (isShortLink) { if (isShortLink) url = await resolveUrl(url)
url = await resolveUrl(url) if (isSharedLink) url = (sourceUrl)
}
if (isSharedLink) {
url = sourceUrl
}
const html = await fetch(url, { headers }) const html = await fetch(url, { headers })
.then(r => r.text()) .then(r => r.text())
@ -50,12 +45,8 @@ export default async function({ sourceUrl, shortLink, username, id }) {
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]) { if (hd?.[1]) urls.push(JSON.parse(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' };