2023-05-24 19:32:41 +02:00
|
|
|
import { maxVideoDuration } from "../../config.js";
|
|
|
|
|
|
|
|
export default async function(obj) {
|
|
|
|
const pinId = obj.id.split('--').reverse()[0];
|
2023-06-05 07:27:43 +02:00
|
|
|
if (!(/^\d+$/.test(pinId))) return { error: 'ErrorCantGetID' };
|
2023-05-24 19:32:41 +02:00
|
|
|
let data = await fetch(`https://www.pinterest.com/resource/PinResource/get?data=${encodeURIComponent(JSON.stringify({
|
2023-06-05 07:27:43 +02:00
|
|
|
options: {
|
|
|
|
field_set_key: "unauth_react_main_pin",
|
|
|
|
id: pinId
|
|
|
|
}
|
2023-05-24 19:32:41 +02:00
|
|
|
}))}`).then((r) => { return r.json() }).catch(() => { return false });
|
|
|
|
if (!data) return { error: 'ErrorCouldntFetch' };
|
|
|
|
|
|
|
|
data = data["resource_response"]["data"];
|
|
|
|
|
|
|
|
let video = null;
|
|
|
|
|
|
|
|
if (data.videos !== null) video = data.videos.video_list.V_720P;
|
|
|
|
else if (data.story_pin_data !== null) video = data.story_pin_data.pages[0].blocks[0].video.video_list.V_EXP7;
|
|
|
|
|
|
|
|
if (!video) return { error: 'ErrorEmptyDownload' };
|
|
|
|
if (video.duration > maxVideoDuration) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
2023-10-12 19:14:54 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
urls: video.url,
|
|
|
|
filename: `pinterest_${pinId}.mp4`,
|
|
|
|
audioFilename: `pinterest_${pinId}_audio`
|
|
|
|
}
|
2023-05-24 19:32:41 +02:00
|
|
|
}
|