Skip to content

Instantly share code, notes, and snippets.

@eXhumer
Last active September 28, 2024 08:20
Show Gist options
  • Save eXhumer/a1bbd5004932bd0d0a4b9bcffcb38184 to your computer and use it in GitHub Desktop.
Save eXhumer/a1bbd5004932bd0d0a4b9bcffcb38184 to your computer and use it in GitHub Desktop.
Download all wallpaper assets from MKBHD's Panels app
import { createWriteStream } from 'fs';
import { mkdir } from 'fs/promises';
import { pipeline } from 'stream/promises';
// https://stackoverflow.com/a/47767860/13157538
const getURLExtension = url => {
return url.split(/[#?]/)[0].split('.').pop().trim();
}
/**
* Download MKBHD's Panels images
* @property {string} dlPath Path to download asset files to
*
* @typedef {Object} PanelJSON
* @property {number} version
* @property {Object.<string, string>} data
*/
const dlMKBHDPanels = async (dlPath = 'mkbhd-panels') => {
const panelsRes = await fetch('https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s');
if (!panelsRes.ok)
throw new Error('Failed to fetch panels data');
/** @type {PanelJSON} */
const panelsJson = await panelsRes.json();
for (const [key, data] of Object.entries(panelsJson.data)) {
await mkdir(`./${dlPath}/`, { recursive: true });
for (const [key2, url] of Object.entries(data)) {
const fileName = `./${dlPath}/${key}_${key2}.${getURLExtension(url)}`;
const fileRes = await fetch(url);
if (!fileRes.ok)
throw new Error(`Failed to fetch ${fileName}`);
const fileStream = createWriteStream(fileName);
await pipeline(fileRes.body, fileStream);
}
}
};
dlMKBHDPanels();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment