From 5ca589bd545a0ce83b73d86041fe81e370987412 Mon Sep 17 00:00:00 2001 From: optionallychained <6907442+optionallychained@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:05:10 +0100 Subject: [PATCH] extract image names from urls --- mkbsd.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mkbsd.js b/mkbsd.js index 54dee5a..0a5b696 100644 --- a/mkbsd.js +++ b/mkbsd.js @@ -40,6 +40,15 @@ const printAscii = () => { 🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`) } +const extractImageName = (url) => + decodeURIComponent( + (new RegExp(/^https:\/\/.*\/content\/(.*.[a-zA-Z])\?/).exec(url)[1] || '') + .replace(`a~`, '') + .replace(/(_[a-z0-9]+)\//, ' - ') + .replace('/', ' - ') + .replace(/~+/g, ' ') + ) + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ACTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -88,8 +97,7 @@ const downloadImages = (data, downloadDirectory) => Object.values(data) .filter((assetMap) => !!assetMap.dhd) .map(({ dhd: url }, i) => { - // TODO extract actual image name past /content to first ? - const fileName = `${i + 1}${extname(new URL(url).pathname) || '.jpg'}` + const fileName = `[${i + 1}] - ${extractImageName(url)}` const filePath = join(downloadDirectory, fileName) return fetch(url)