mirror of
https://github.com/wukko/cobalt.git
synced 2025-01-12 11:52:12 +01:00
pinterest: fix video link parsing
This commit is contained in:
parent
d4d2f0a6f1
commit
c86e209e55
1 changed files with 9 additions and 12 deletions
|
@ -1,22 +1,16 @@
|
||||||
import { genericUserAgent } from "../../config.js";
|
import { genericUserAgent } from "../../config.js";
|
||||||
|
|
||||||
const videoLinkBase = {
|
const linkRegex = /"url":"(https:\/\/v1.pinimg.com\/videos\/.*?)"/g;
|
||||||
"regular": "https://v1.pinimg.com/videos/mc/720p/",
|
|
||||||
"story": "https://v1.pinimg.com/videos/mc/720p/"
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function(o) {
|
export default async function(o) {
|
||||||
let id = o.id, type = "regular";
|
let id = o.id;
|
||||||
|
|
||||||
if (!o.id && o.shortLink) {
|
if (!o.id && o.shortLink) {
|
||||||
id = await fetch(`https://api.pinterest.com/url_shortener/${o.shortLink}/redirect/`, { redirect: "manual" }).then((r) => {
|
id = await fetch(`https://api.pinterest.com/url_shortener/${o.shortLink}/redirect/`, { redirect: "manual" }).then((r) => {
|
||||||
return r.headers.get("location").split('pin/')[1].split('/')[0]
|
return r.headers.get("location").split('pin/')[1].split('/')[0]
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
if (id.includes("--")) {
|
if (id.includes("--")) id = id.split("--")[1];
|
||||||
id = id.split("--")[1];
|
|
||||||
type = "story";
|
|
||||||
}
|
|
||||||
if (!id) return { error: 'ErrorCouldntFetch' };
|
if (!id) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
let html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
let html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
||||||
|
@ -25,11 +19,14 @@ export default async function(o) {
|
||||||
|
|
||||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||||
|
|
||||||
let videoLink = html.split(`"url":"${videoLinkBase[type]}`)[1]?.split('"')[0];
|
let videoLink = [...html.matchAll(linkRegex)]
|
||||||
if (!html.includes(videoLink)) return { error: 'ErrorEmptyDownload' };
|
.map(([, link]) => link)
|
||||||
|
.filter(a => a.endsWith('.mp4') && a.includes('720p'))[0];
|
||||||
|
|
||||||
|
if (!videoLink) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: `${videoLinkBase[type]}${videoLink}`,
|
urls: videoLink,
|
||||||
filename: `pinterest_${o.id}.mp4`,
|
filename: `pinterest_${o.id}.mp4`,
|
||||||
audioFilename: `pinterest_${o.id}_audio`
|
audioFilename: `pinterest_${o.id}_audio`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue