mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-22 18:55:33 +00:00
downloads are sorted based on artist name (js)
This commit is contained in:
parent
4f62717019
commit
ebbb5520ef
28
mkbsd.js
28
mkbsd.js
|
@ -24,22 +24,38 @@ async function main() {
|
||||||
fs.mkdirSync(downloadDir);
|
fs.mkdirSync(downloadDir);
|
||||||
console.info(`📁 Created directory: ${downloadDir}`);
|
console.info(`📁 Created directory: ${downloadDir}`);
|
||||||
}
|
}
|
||||||
let fileIndex = 1;
|
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
const subproperty = data[key];
|
const subproperty = data[key];
|
||||||
if (subproperty && subproperty.dhd) {
|
if (subproperty && subproperty.dhd) {
|
||||||
const imageUrl = subproperty.dhd;
|
const imageUrl = subproperty.dhd;
|
||||||
console.info(`🔍 Found image URL!`);
|
console.info(`🔍 Found image URL!`, imageUrl);
|
||||||
await delay(100);
|
await delay(100);
|
||||||
const ext = path.extname(new URL(imageUrl).pathname) || '.jpg';
|
|
||||||
const filename = `${fileIndex}${ext}`;
|
const match = imageUrl.match(/\/content\/([^/]+)\//);
|
||||||
const filePath = path.join(downloadDir, filename);
|
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);
|
await downloadImage(imageUrl, filePath);
|
||||||
console.info(`🖼️ Saved image to ${filePath}`);
|
console.info(`🖼️ Saved image to ${filePath}`);
|
||||||
fileIndex++;
|
|
||||||
await delay(250);
|
await delay(250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error: ${error.message}`);
|
console.error(`Error: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue