using image names instead of index

This commit is contained in:
jihad 2024-09-25 04:34:26 +03:00
parent 6c6add0f1e
commit 64c99e8e6f

View file

@ -24,19 +24,18 @@ 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!`);
await delay(100); await delay(100);
const ext = path.extname(new URL(imageUrl).pathname) || '.jpg'; // Extract the actual filename from the URL
const filename = `${fileIndex}${ext}`; const filename = path.basename(new URL(imageUrl).pathname);
const filePath = path.join(downloadDir, filename); const filePath = path.join(downloadDir, filename);
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);
} }
} }