Last active
February 1, 2022 13:16
-
-
Save vanaf1979/17fe8adad0b6cbfd8a14e1187b0772ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: shoes | |
import "@johnlindquist/kit"; | |
let Jimp = await npm("jimp") | |
let text = await editor(` | |
## Enter a url per line | |
## Hit cmd+s to "continue" | |
https://grotemaatschoenen.nl/jana-2230-20-154.html | |
`.trim()) | |
let urls = text.split("\n").filter(line => line.startsWith("http")) | |
setDescription(`Set download folder`) | |
//let folderPath = await path(); | |
let folderPath = await selectFolder(); | |
// If there are no more prompts, clear prompt | |
setChoices(null) | |
setInput(``) | |
setPlaceholder(`🙏 Please hold`) | |
setIgnoreBlur(true) //Prevents losing focus from terminating the process | |
let dots = `` | |
let id = setInterval(()=> { | |
dots = dots === "..." ? "." : dots + "." | |
setHint(`Scraping${dots}`) | |
}, 250) | |
for await (let url of urls){ | |
// Destructure for first, get `src`, alias as imageUrl :) | |
setDescription(url) | |
let [{src:imageUrl}] = await scrapeSelector( | |
url, | |
".fotorama__active > .fotorama__img", //adding the > | |
el => ({ | |
src: el.src, | |
}) | |
); | |
// `download` is part of the API: https://www.npmjs.com/package/download | |
await download( | |
imageUrl, | |
folderPath, | |
) | |
.catch(error => { | |
console.log(error) | |
}) | |
let imagePath = path.resolve(folderPath, path.basename(imageUrl)) | |
// // Create a path for image with selected folder path. | |
let ext = path.extname(imageUrl) | |
let resizedImageName = imagePath.replace(new RegExp(`${ext}$`), `-resized${ext}`) | |
// Resize image and save to taget folder. | |
let image = await Jimp.read(imagePath) | |
await image.resize(300, 225).write(resizedImageName) | |
} | |
await exec(`open ${folderPath}`) | |
clearInterval(id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment