2024-01-17 10:05:39 +01:00
|
|
|
import { genericUserAgent } from "../../config.js";
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
const videoLinkBase = {
|
|
|
|
"regular": "https://v1.pinimg.com/videos/mc/720p/",
|
|
|
|
"story": "https://v1.pinimg.com/videos/mc/720p/"
|
|
|
|
}
|
|
|
|
|
|
|
|
export default async function(o) {
|
|
|
|
let id = o.id, type = "regular";
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
if (!o.id && o.shortLink) {
|
|
|
|
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]
|
|
|
|
}).catch(() => {});
|
|
|
|
}
|
2024-01-17 18:20:49 +01:00
|
|
|
if (id.includes("--")) {
|
|
|
|
id = id.split("--")[1];
|
|
|
|
type = "story";
|
|
|
|
}
|
2024-01-17 10:05:39 +01:00
|
|
|
if (!id) return { error: 'ErrorCouldntFetch' };
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
let html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
|
|
|
headers: { "user-agent": genericUserAgent }
|
|
|
|
}).then((r) => { return r.text() }).catch(() => { return false });
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
let videoLink = html.split(`"url":"${videoLinkBase[type]}`)[1]?.split('"')[0];
|
|
|
|
if (!html.includes(videoLink)) return { error: 'ErrorEmptyDownload' };
|
2023-10-12 19:14:54 +02:00
|
|
|
|
|
|
|
return {
|
2024-01-17 10:05:39 +01:00
|
|
|
urls: `${videoLinkBase[type]}${videoLink}`,
|
|
|
|
filename: `pinterest_${o.id}.mp4`,
|
|
|
|
audioFilename: `pinterest_${o.id}_audio`
|
2023-10-12 19:14:54 +02:00
|
|
|
}
|
2023-05-24 19:32:41 +02:00
|
|
|
}
|