diff --git a/src/modules/processing/services/pinterest.js b/src/modules/processing/services/pinterest.js index 2364b729..a75a82c3 100644 --- a/src/modules/processing/services/pinterest.js +++ b/src/modules/processing/services/pinterest.js @@ -1,6 +1,7 @@ import { genericUserAgent } from "../../config.js"; -const linkRegex = /"url":"(https:\/\/v1.pinimg.com\/videos\/.*?)"/g; +const videoRegex = /"url":"(https:\/\/v1.pinimg.com\/videos\/.*?)"/g; +const imageRegex = /src="(https:\/\/i\.pinimg\.com\/.*\.(jpg|gif))"/g; export default async function(o) { let id = o.id; @@ -19,15 +20,24 @@ export default async function(o) { if (!html) return { error: 'ErrorCouldntFetch' }; - let videoLink = [...html.matchAll(linkRegex)] + let videoLink = [...html.matchAll(videoRegex)] .map(([, link]) => link) .filter(a => a.endsWith('.mp4') && a.includes('720p'))[0]; - if (!videoLink) return { error: 'ErrorEmptyDownload' }; - - return { + if (videoLink) return { urls: videoLink, filename: `pinterest_${o.id}.mp4`, audioFilename: `pinterest_${o.id}_audio` } + + let imageLink = [...html.matchAll(imageRegex)] + .map(([, link]) => link) + .filter(a => a.endsWith('.jpg') || a.endsWith('.gif'))[0]; + + if (imageLink) return { + urls: imageLink, + isPhoto: true + } + + return { error: 'ErrorEmptyDownload' }; } diff --git a/src/test/tests.json b/src/test/tests.json index 95c95a65..a0ef8e6b 100644 --- a/src/test/tests.json +++ b/src/test/tests.json @@ -976,6 +976,38 @@ "code": 200, "status": "redirect" } + }, { + "name": "regular picture", + "url": "https://www.pinterest.com/pin/412994228343400946/", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } + }, { + "name": "regular picture (.ca TLD)", + "url": "https://www.pinterest.ca/pin/412994228343400946/", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } + }, { + "name": "regular gif", + "url": "https://www.pinterest.com/pin/814447913881127862/", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } + }, { + "name": "regular gif (.ca TLD)", + "url": "https://www.pinterest.ca/pin/814447913881127862/", + "params": {}, + "expected": { + "code": 200, + "status": "redirect" + } }], "streamable": [{ "name": "regular video",