mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-22 18:55:33 +00:00
Merge e38f3de6c8
into 82e50c64f0
This commit is contained in:
commit
70fdb5965e
48
mkbsd.js
48
mkbsd.js
|
@ -1,14 +1,10 @@
|
|||
// Copyright 2024 Nadim Kobeissi
|
||||
// Licensed under the WTFPL License
|
||||
|
||||
const fs = require(`fs`);
|
||||
const path = require(`path`);
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function main() {
|
||||
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,25 +15,33 @@ async function main() {
|
|||
if (!data) {
|
||||
throw new Error('⛔ JSON does not have a "data" property at its root.');
|
||||
}
|
||||
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) {
|
||||
const subproperty = data[key];
|
||||
if (subproperty && subproperty.dhd) {
|
||||
const imageUrl = subproperty.dhd;
|
||||
console.info(`🔍 Found image URL!`);
|
||||
await delay(100);
|
||||
const ext = path.extname(new URL(imageUrl).pathname) || '.jpg';
|
||||
const filename = `${fileIndex}${ext}`;
|
||||
const filePath = path.join(downloadDir, filename);
|
||||
|
||||
// Extract the artist name before the underscore
|
||||
const artistNameMatch = imageUrl.match(/a~([^_/]+)/);
|
||||
const artistName = artistNameMatch ? artistNameMatch[1] : 'unknown_artist';
|
||||
const artistDir = path.join(__dirname, 'downloads', artistName);
|
||||
|
||||
// Create artist directory if it doesn't exist
|
||||
if (!fs.existsSync(artistDir)) {
|
||||
fs.mkdirSync(artistDir, { recursive: true });
|
||||
console.info(`📁 Created directory: ${artistDir}`);
|
||||
}
|
||||
|
||||
// Extract the filename and extension
|
||||
const urlPath = new URL(imageUrl).pathname;
|
||||
const fileName = path.basename(urlPath); // Filename including extension (e.g. .jpg or .png)
|
||||
const filePath = path.join(artistDir, fileName);
|
||||
|
||||
// Download the image and save it to the specified path
|
||||
await downloadImage(imageUrl, filePath);
|
||||
console.info(`🖼️ Saved image to ${filePath}`);
|
||||
fileIndex++;
|
||||
await delay(250);
|
||||
await delay(250); // Delay between downloads
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -45,6 +49,7 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Function to download the image from the provided URL
|
||||
async function downloadImage(url, filePath) {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
|
@ -55,6 +60,7 @@ async function downloadImage(url, filePath) {
|
|||
await fs.promises.writeFile(filePath, buffer);
|
||||
}
|
||||
|
||||
// ASCII art function (optional)
|
||||
function asciiArt() {
|
||||
console.info(`
|
||||
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
||||
|
@ -65,10 +71,10 @@ function asciiArt() {
|
|||
| $$\\ $ | $$| $$\\ $$ | $$ \\ $$ /$$ \\ $$| $$ | $$
|
||||
| $$ \\/ | $$| $$ \\ $$| $$$$$$$/| $$$$$$/| $$$$$$$/
|
||||
|__/ |__/|__/ \\__/|_______/ \\______/ |_______/`);
|
||||
console.info(``);
|
||||
console.info(`🤑 Starting downloads from your favorite sellout grifter's wallpaper app...`);
|
||||
}
|
||||
|
||||
// Start program with ASCII art and delay
|
||||
(() => {
|
||||
asciiArt();
|
||||
setTimeout(main, 5000);
|
||||
|
|
25
mkbsd.py
25
mkbsd.py
|
@ -1,10 +1,9 @@
|
|||
# Licensed under the WTFPL License
|
||||
|
||||
import os
|
||||
import time
|
||||
import aiohttp
|
||||
import asyncio
|
||||
from urllib.parse import urlparse
|
||||
|
||||
url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
|
||||
|
||||
async def delay(ms):
|
||||
|
@ -33,25 +32,27 @@ async def main():
|
|||
if not data:
|
||||
raise Exception('⛔ JSON does not have a "data" property at its root.')
|
||||
|
||||
download_dir = os.path.join(os.getcwd(), 'downloads')
|
||||
if not os.path.exists(download_dir):
|
||||
os.makedirs(download_dir)
|
||||
print(f"📁 Created directory: {download_dir}")
|
||||
|
||||
file_index = 1
|
||||
for key, subproperty in data.items():
|
||||
if subproperty and subproperty.get('dhd'):
|
||||
image_url = subproperty['dhd']
|
||||
print(f"🔍 Found image URL!")
|
||||
|
||||
# Extrahiere den Künstlernamen vor dem Unterstrich
|
||||
parsed_url = urlparse(image_url)
|
||||
ext = os.path.splitext(parsed_url.path)[-1] or '.jpg'
|
||||
filename = f"{file_index}{ext}"
|
||||
file_path = os.path.join(download_dir, filename)
|
||||
artist_name = image_url.split('a~')[1].split('_')[0]
|
||||
artist_dir = os.path.join(os.getcwd(), 'downloads', artist_name)
|
||||
|
||||
if not os.path.exists(artist_dir):
|
||||
os.makedirs(artist_dir)
|
||||
print(f"📁 Created directory: {artist_dir}")
|
||||
|
||||
# Extrahiere den Dateinamen und die Endung
|
||||
filename = os.path.basename(parsed_url.path) # Name inklusive Endung
|
||||
file_path = os.path.join(artist_dir, filename)
|
||||
|
||||
await download_image(session, image_url, file_path)
|
||||
print(f"🖼️ Saved image to {file_path}")
|
||||
|
||||
file_index += 1
|
||||
await delay(250)
|
||||
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in a new issue