mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-23 03:05:31 +00:00
Added a prompt to choose the number of images
This commit is contained in:
parent
82e50c64f0
commit
b3032dc640
|
@ -1,12 +1,12 @@
|
|||
```
|
||||
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
||||
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
||||
| $$$ /$$$| $$ /$$/| $$__ $$ /$$__ $$| $$__ $$
|
||||
| $$$$ /$$$$| $$ /$$/ | $$ \ $$| $$ \__/| $$ \ $$
|
||||
| $$ $$/$$ $$| $$$$$/ | $$$$$$$ | $$$$$$ | $$ | $$
|
||||
| $$ $$$| $$| $$ $$ | $$__ $$ \____ $$| $$ | $$
|
||||
| $$\ $ | $$| $$\ $$ | $$ \ $$ /$$ \ $$| $$ | $$
|
||||
| $$ \/ | $$| $$ \ $$| $$$$$$$/| $$$$$$/| $$$$$$$/
|
||||
|__/ |__/|__/ \__/|_______/ \______/ |_______/
|
||||
|__/ |__/|__/ \__/|_______/ \______/ |_______/
|
||||
```
|
||||
|
||||
_Because selling out is bad_
|
||||
|
|
63
mkbsd.js
63
mkbsd.js
|
@ -1,14 +1,12 @@
|
|||
// Copyright 2024 Nadim Kobeissi
|
||||
// Licensed under the WTFPL License
|
||||
|
||||
const fs = require(`fs`);
|
||||
const path = require(`path`);
|
||||
const readline = require('readline');
|
||||
|
||||
async function main() {
|
||||
async function main(imageCount) {
|
||||
const url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s';
|
||||
const delay = (ms) => {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
|
@ -19,13 +17,24 @@ async function main() {
|
|||
if (!data) {
|
||||
throw new Error('⛔ JSON does not have a "data" property at its root.');
|
||||
}
|
||||
|
||||
const totalFiles = Object.keys(data).length; // Count total available files
|
||||
console.info(`📦 Total available files: ${totalFiles}`);
|
||||
|
||||
if (imageCount > totalFiles) {
|
||||
console.warn(`⚠️ You requested ${imageCount} files, but only ${totalFiles} are available. Downloading all available files instead.`);
|
||||
imageCount = totalFiles; // Limit to available files
|
||||
}
|
||||
|
||||
const downloadDir = path.join(__dirname, 'downloads');
|
||||
if (!fs.existsSync(downloadDir)) {
|
||||
fs.mkdirSync(downloadDir);
|
||||
console.info(`📁 Created directory: ${downloadDir}`);
|
||||
}
|
||||
|
||||
let fileIndex = 1;
|
||||
for (const key in data) {
|
||||
if (fileIndex > imageCount) break; // Stop if we've reached the desired count
|
||||
const subproperty = data[key];
|
||||
if (subproperty && subproperty.dhd) {
|
||||
const imageUrl = subproperty.dhd;
|
||||
|
@ -69,7 +78,41 @@ function asciiArt() {
|
|||
console.info(`🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`);
|
||||
}
|
||||
|
||||
(() => {
|
||||
asciiArt();
|
||||
setTimeout(main, 5000);
|
||||
})();
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
// Function to start the download process
|
||||
async function startDownload() {
|
||||
const url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s';
|
||||
const response = await fetch(url);
|
||||
const jsonData = await response.json();
|
||||
const data = jsonData.data;
|
||||
|
||||
const totalFiles = Object.keys(data).length; // Count total available files
|
||||
console.info(`📦 Total available files: ${totalFiles}`);
|
||||
|
||||
rl.question('How many images would you like to download? ', (answer) => {
|
||||
let imageCount = parseInt(answer, 10);
|
||||
if (isNaN(imageCount) || imageCount <= 0) {
|
||||
console.error('Please enter a valid positive number.');
|
||||
rl.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (imageCount > totalFiles) {
|
||||
console.warn(`⚠️ You requested ${imageCount} files, but only ${totalFiles} are available. Downloading all available files instead.`);
|
||||
imageCount = totalFiles; // Limit to available files
|
||||
}
|
||||
|
||||
asciiArt();
|
||||
setTimeout(() => {
|
||||
main(imageCount).finally(() => rl.close());
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
// Start the download process
|
||||
startDownload();
|
||||
|
||||
|
|
Loading…
Reference in a new issue