mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-04 16:57:47 -05:00
downloads are sorted based on artist name (js)
This commit is contained in:
parent
4f62717019
commit
ebbb5520ef
1 changed files with 25 additions and 9 deletions
34
mkbsd.js
34
mkbsd.js
|
@ -24,20 +24,36 @@ async function main() {
|
|||
fs.mkdirSync(downloadDir);
|
||||
console.info(`📁 Created directory: ${downloadDir}`);
|
||||
}
|
||||
let fileIndex = 1;
|
||||
for (const key in data) {
|
||||
const subproperty = data[key];
|
||||
if (subproperty && subproperty.dhd) {
|
||||
const imageUrl = subproperty.dhd;
|
||||
console.info(`🔍 Found image URL!`);
|
||||
console.info(`🔍 Found image URL!`, imageUrl);
|
||||
await delay(100);
|
||||
const ext = path.extname(new URL(imageUrl).pathname) || '.jpg';
|
||||
const filename = `${fileIndex}${ext}`;
|
||||
const filePath = path.join(downloadDir, filename);
|
||||
await downloadImage(imageUrl, filePath);
|
||||
console.info(`🖼️ Saved image to ${filePath}`);
|
||||
fileIndex++;
|
||||
await delay(250);
|
||||
|
||||
const match = imageUrl.match(/\/content\/([^/]+)\//);
|
||||
let artistName = match[1];
|
||||
artistName = artistName.replace(/^[a~]+|_[^_]+$/g, '');
|
||||
// Create folder with artist's name
|
||||
const artistDir = path.join(downloadDir, artistName);
|
||||
if (!fs.existsSync(artistDir)) {
|
||||
fs.mkdirSync(artistDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Extract and clean file name
|
||||
const fileNameMatch = imageUrl.match(/\/([^/]+)\?/);
|
||||
let cleanFileName = '';
|
||||
|
||||
if (fileNameMatch) {
|
||||
let cleanFileName = fileNameMatch[1].replace(/~/g, ' ');
|
||||
const filePath = path.join(artistDir, cleanFileName);
|
||||
|
||||
console.info('📂', filePath);
|
||||
|
||||
await downloadImage(imageUrl, filePath);
|
||||
console.info(`🖼️ Saved image to ${filePath}`);
|
||||
await delay(250);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in a new issue