mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2025-06-08 09:47:18 -04:00
Merge 78d5f231c6
into 82e50c64f0
This commit is contained in:
commit
034e42643b
2 changed files with 79 additions and 3 deletions
47
mkbsd.js
47
mkbsd.js
|
@ -3,8 +3,21 @@
|
||||||
|
|
||||||
const fs = require(`fs`);
|
const fs = require(`fs`);
|
||||||
const path = require(`path`);
|
const path = require(`path`);
|
||||||
|
const readline = require(`readline`);
|
||||||
|
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
|
||||||
|
const MAX_IMAGES = 380;
|
||||||
|
const MIN_AMOUNT_OF_IMAGES = 1;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
// Get user input for the number of pictures and the starting index
|
||||||
|
const numPictures = await askForValidNumber('How many pictures would you like to download? (Max: 380) ', MIN_AMOUNT_OF_IMAGES, MAX_IMAGES);
|
||||||
|
const startIndex = await askForValidNumber('From which picture (index) would you like to start? ', MIN_AMOUNT_OF_IMAGES, MAX_IMAGES);
|
||||||
|
|
||||||
const url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s';
|
const url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s';
|
||||||
const delay = (ms) => {
|
const delay = (ms) => {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
@ -24,8 +37,15 @@ async function main() {
|
||||||
fs.mkdirSync(downloadDir);
|
fs.mkdirSync(downloadDir);
|
||||||
console.info(`📁 Created directory: ${downloadDir}`);
|
console.info(`📁 Created directory: ${downloadDir}`);
|
||||||
}
|
}
|
||||||
let fileIndex = 1;
|
|
||||||
|
let fileIndex = parseInt(startIndex); // Start from the user-provided index
|
||||||
|
let downloadedCount = 0;
|
||||||
|
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
|
if (downloadedCount >= parseInt(numPictures)) {
|
||||||
|
break; // Stop after downloading the requested number of pictures
|
||||||
|
}
|
||||||
|
|
||||||
const subproperty = data[key];
|
const subproperty = data[key];
|
||||||
if (subproperty && subproperty.dhd) {
|
if (subproperty && subproperty.dhd) {
|
||||||
const imageUrl = subproperty.dhd;
|
const imageUrl = subproperty.dhd;
|
||||||
|
@ -37,12 +57,14 @@ async function main() {
|
||||||
await downloadImage(imageUrl, filePath);
|
await downloadImage(imageUrl, filePath);
|
||||||
console.info(`🖼️ Saved image to ${filePath}`);
|
console.info(`🖼️ Saved image to ${filePath}`);
|
||||||
fileIndex++;
|
fileIndex++;
|
||||||
|
downloadedCount++;
|
||||||
await delay(250);
|
await delay(250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error: ${error.message}`);
|
console.error(`Error: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
rl.close(); // Close the readline interface when done
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadImage(url, filePath) {
|
async function downloadImage(url, filePath) {
|
||||||
|
@ -69,6 +91,29 @@ function asciiArt() {
|
||||||
console.info(`🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`);
|
console.info(`🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function askQuestion(query) {
|
||||||
|
return new Promise(resolve => rl.question(query, resolve));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to validate that the input is a valid number within range
|
||||||
|
async function askForValidNumber(query, minValue = MIN_AMOUNT_OF_IMAGES, maxValue = MAX_IMAGES) {
|
||||||
|
let valid = false;
|
||||||
|
let value;
|
||||||
|
|
||||||
|
while (!valid) {
|
||||||
|
const answer = await askQuestion(query);
|
||||||
|
value = parseInt(answer);
|
||||||
|
|
||||||
|
if (!isNaN(value) && value >= minValue && value <= maxValue) {
|
||||||
|
valid = true;
|
||||||
|
} else {
|
||||||
|
console.error(`🚫 Invalid input. Please enter a number between ${minValue} and ${maxValue}.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
asciiArt();
|
asciiArt();
|
||||||
setTimeout(main, 5000);
|
setTimeout(main, 5000);
|
||||||
|
|
33
mkbsd.py
33
mkbsd.py
|
@ -5,11 +5,15 @@ import time
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
|
url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
|
||||||
|
MAX_IMAGES = 380
|
||||||
|
MIN_AMOUNT_OF_IMAGES = 1
|
||||||
|
|
||||||
async def delay(ms):
|
async def delay(ms):
|
||||||
await asyncio.sleep(ms / 1000)
|
await asyncio.sleep(ms / 1000)
|
||||||
|
|
||||||
|
|
||||||
async def download_image(session, image_url, file_path):
|
async def download_image(session, image_url, file_path):
|
||||||
try:
|
try:
|
||||||
async with session.get(image_url) as response:
|
async with session.get(image_url) as response:
|
||||||
|
@ -21,7 +25,14 @@ async def download_image(session, image_url, file_path):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error downloading image: {str(e)}")
|
print(f"Error downloading image: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
# Get user input for number of pictures and starting index
|
||||||
|
num_pictures = await ask_for_valid_number(f'How many pictures would you like to download? (Max: {MAX_IMAGES}) ',
|
||||||
|
MIN_AMOUNT_OF_IMAGES, MAX_IMAGES)
|
||||||
|
start_index = await ask_for_valid_number(f'From which picture (index) would you like to start? ',
|
||||||
|
MIN_AMOUNT_OF_IMAGES, MAX_IMAGES)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(url) as response:
|
async with session.get(url) as response:
|
||||||
|
@ -38,8 +49,13 @@ async def main():
|
||||||
os.makedirs(download_dir)
|
os.makedirs(download_dir)
|
||||||
print(f"📁 Created directory: {download_dir}")
|
print(f"📁 Created directory: {download_dir}")
|
||||||
|
|
||||||
file_index = 1
|
file_index = start_index
|
||||||
|
downloaded_count = 0
|
||||||
|
|
||||||
for key, subproperty in data.items():
|
for key, subproperty in data.items():
|
||||||
|
if downloaded_count >= num_pictures:
|
||||||
|
break # Stop after downloading the requested number of pictures
|
||||||
|
|
||||||
if subproperty and subproperty.get('dhd'):
|
if subproperty and subproperty.get('dhd'):
|
||||||
image_url = subproperty['dhd']
|
image_url = subproperty['dhd']
|
||||||
print(f"🔍 Found image URL!")
|
print(f"🔍 Found image URL!")
|
||||||
|
@ -52,11 +68,25 @@ async def main():
|
||||||
print(f"🖼️ Saved image to {file_path}")
|
print(f"🖼️ Saved image to {file_path}")
|
||||||
|
|
||||||
file_index += 1
|
file_index += 1
|
||||||
|
downloaded_count += 1
|
||||||
await delay(250)
|
await delay(250)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {str(e)}")
|
print(f"Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
async def ask_for_valid_number(prompt, min_value, max_value):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
value = int(input(prompt))
|
||||||
|
if min_value <= value <= max_value:
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
print(f"🚫 Please enter a number between {min_value} and {max_value}.")
|
||||||
|
except ValueError:
|
||||||
|
print("🚫 Invalid input. Please enter a valid number.")
|
||||||
|
|
||||||
|
|
||||||
def ascii_art():
|
def ascii_art():
|
||||||
print("""
|
print("""
|
||||||
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
||||||
|
@ -70,6 +100,7 @@ def ascii_art():
|
||||||
print("")
|
print("")
|
||||||
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...")
|
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ascii_art()
|
ascii_art()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
Loading…
Add table
Reference in a new issue