mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-22 20:15:06 +00:00
extract image names from urls
This commit is contained in:
parent
ac781c36f6
commit
5ca589bd54
12
mkbsd.js
12
mkbsd.js
@ -40,6 +40,15 @@ const printAscii = () => {
|
|||||||
🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`)
|
🤑 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
|
// ACTIONS
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -88,8 +97,7 @@ const downloadImages = (data, downloadDirectory) =>
|
|||||||
Object.values(data)
|
Object.values(data)
|
||||||
.filter((assetMap) => !!assetMap.dhd)
|
.filter((assetMap) => !!assetMap.dhd)
|
||||||
.map(({ dhd: url }, i) => {
|
.map(({ dhd: url }, i) => {
|
||||||
// TODO extract actual image name past /content to first ?
|
const fileName = `[${i + 1}] - ${extractImageName(url)}`
|
||||||
const fileName = `${i + 1}${extname(new URL(url).pathname) || '.jpg'}`
|
|
||||||
const filePath = join(downloadDirectory, fileName)
|
const filePath = join(downloadDirectory, fileName)
|
||||||
|
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
|
Loading…
Reference in New Issue
Block a user