2024-01-17 10:05:39 +01:00
|
|
|
import { genericUserAgent } from "../../config.js";
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-07-06 10:55:48 +02:00
|
|
|
const videoRegex = /"url":"(https:\/\/v1\.pinimg\.com\/videos\/.*?)"/g;
|
2024-05-15 13:56:10 +02:00
|
|
|
const imageRegex = /src="(https:\/\/i\.pinimg\.com\/.*\.(jpg|gif))"/g;
|
2024-01-17 10:05:39 +01:00
|
|
|
|
|
|
|
export default async function(o) {
|
2024-04-27 16:29:30 +02:00
|
|
|
let id = o.id;
|
2023-05-24 19:32:41 +02:00
|
|
|
|
2024-01-17 10:05:39 +01:00
|
|
|
if (!o.id && o.shortLink) {
|
2024-05-16 17:28:42 +02:00
|
|
|
id = await fetch(`https://api.pinterest.com/url_shortener/${o.shortLink}/redirect/`, { redirect: "manual" })
|
|
|
|
.then(r => r.headers.get("location").split('pin/')[1].split('/')[0])
|
|
|
|
.catch(() => {});
|
2024-01-17 10:05:39 +01:00
|
|
|
}
|
2024-04-27 16:29:30 +02:00
|
|
|
if (id.includes("--")) id = id.split("--")[1];
|
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 }
|
2024-05-16 17:28:42 +02:00
|
|
|
}).then(r => r.text()).catch(() => {});
|
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-05-15 13:56:10 +02:00
|
|
|
let videoLink = [...html.matchAll(videoRegex)]
|
2024-04-27 16:29:30 +02:00
|
|
|
.map(([, link]) => link)
|
2024-05-15 13:56:10 +02:00
|
|
|
.find(a => a.endsWith('.mp4') && a.includes('720p'));
|
2024-04-27 16:29:30 +02:00
|
|
|
|
2024-05-15 13:56:10 +02:00
|
|
|
if (videoLink) return {
|
2024-04-27 16:29:30 +02:00
|
|
|
urls: videoLink,
|
2024-01-17 10:05:39 +01:00
|
|
|
filename: `pinterest_${o.id}.mp4`,
|
|
|
|
audioFilename: `pinterest_${o.id}_audio`
|
2023-10-12 19:14:54 +02:00
|
|
|
}
|
2024-05-15 13:56:10 +02:00
|
|
|
|
|
|
|
let imageLink = [...html.matchAll(imageRegex)]
|
|
|
|
.map(([, link]) => link)
|
|
|
|
.find(a => a.endsWith('.jpg') || a.endsWith('.gif'));
|
2024-08-03 10:47:13 +02:00
|
|
|
|
2024-05-15 13:56:10 +02:00
|
|
|
if (imageLink) return {
|
|
|
|
urls: imageLink,
|
|
|
|
isPhoto: true
|
|
|
|
}
|
|
|
|
|
|
|
|
return { error: 'ErrorEmptyDownload' };
|
2023-05-24 19:32:41 +02:00
|
|
|
}
|