mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api/pinterest: add missing filenames to images & gifs
This commit is contained in:
parent
d0d0f16c5f
commit
4476ae0672
1 changed files with 7 additions and 4 deletions
|
@ -14,13 +14,13 @@ export default async function(o) {
|
||||||
if (id.includes("--")) id = id.split("--")[1];
|
if (id.includes("--")) id = id.split("--")[1];
|
||||||
if (!id) return { error: "fetch.fail" };
|
if (!id) return { error: "fetch.fail" };
|
||||||
|
|
||||||
let html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
const html = await fetch(`https://www.pinterest.com/pin/${id}/`, {
|
||||||
headers: { "user-agent": genericUserAgent }
|
headers: { "user-agent": genericUserAgent }
|
||||||
}).then(r => r.text()).catch(() => {});
|
}).then(r => r.text()).catch(() => {});
|
||||||
|
|
||||||
if (!html) return { error: "fetch.fail" };
|
if (!html) return { error: "fetch.fail" };
|
||||||
|
|
||||||
let videoLink = [...html.matchAll(videoRegex)]
|
const videoLink = [...html.matchAll(videoRegex)]
|
||||||
.map(([, link]) => link)
|
.map(([, link]) => link)
|
||||||
.find(a => a.endsWith('.mp4') && a.includes('720p'));
|
.find(a => a.endsWith('.mp4') && a.includes('720p'));
|
||||||
|
|
||||||
|
@ -30,13 +30,16 @@ export default async function(o) {
|
||||||
audioFilename: `pinterest_${o.id}_audio`
|
audioFilename: `pinterest_${o.id}_audio`
|
||||||
}
|
}
|
||||||
|
|
||||||
let imageLink = [...html.matchAll(imageRegex)]
|
const imageLink = [...html.matchAll(imageRegex)]
|
||||||
.map(([, link]) => link)
|
.map(([, link]) => link)
|
||||||
.find(a => a.endsWith('.jpg') || a.endsWith('.gif'));
|
.find(a => a.endsWith('.jpg') || a.endsWith('.gif'));
|
||||||
|
|
||||||
|
const imageType = imageLink.endsWith(".gif") ? "gif" : "jpg"
|
||||||
|
|
||||||
if (imageLink) return {
|
if (imageLink) return {
|
||||||
urls: imageLink,
|
urls: imageLink,
|
||||||
isPhoto: true
|
isPhoto: true,
|
||||||
|
filename: `pinterest_${o.id}.${imageType}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return { error: "fetch.empty" };
|
return { error: "fetch.empty" };
|
||||||
|
|
Loading…
Reference in a new issue