nadimkobeissi / mkbsd

Download all the wallpapers in MKBHD's "Panels" app
Do What The F*ck You Want To Public License
3.65k stars 445 forks source link

Download All Image Sizes & Formats #13

Open markwinap opened 2 months ago

markwinap commented 2 months ago

More image sizes and formats are available. The request is to archive all formats and image sizes.

const apiVersion = '20240916';

const image_list = { "content": "https://storage.googleapis.com/panels-api/data/20240916/content-1a", "search": "https://storage.googleapis.com/panels-api/data/20240916/content-metadata-1a", "media": { "root": "https://storage.googleapis.com/panels-api/data/20240916/media-1a", "p": [ "i",// jpg format // Example https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~uhd "c"// webp format // Example https://storage.googleapis.com/panels-api/data/20240916/media-1a-c-p~uhd ], "b": [ "p~s",//data/20240916/media-1a-c-p~s "p~five0",//data/20240916/media-1a-i-p~five0 "p~a~n", "p~a~xl", "p~uhd",//4k Resolution - Example //data/20240916/media-1a-i-p~uhd "f~fo", "t~s",//data/20240916/media-1a-i-t~s "t~m",//data/20240916/media-1a-i-t~m "t~l"//data/20240916/media-1a-i-t~l ] } };

osenoah commented 2 months ago

You should probably write a script that iterates over the available formats (p) and sizes (b) in the image_list object and construct the download links for the images.

const fs = require('fs');
const https = require('https');

const image_list = {
  content: "https://storage.googleapis.com/panels-api/data/20240916/content-1a",
  search: "https://storage.googleapis.com/panels-api/data/20240916/content-metadata-1a",
  media: {
    root: "https://storage.googleapis.com/panels-api/data/20240916/media-1a",
    p: [
      "i", // jpg format
      "c"  // webp format
    ],
    b: [
      "ps",
      "pfive0",
      "pan",
      "paxl",
      "puhd", // 4k Resolution
      "ffo",
      "ts",
      "tm",
      "tl"
    ]
  }
};

// Function to generate download links
function generateAllImageUrls() {
  const { root, p: formats, b: resolutions } = image_list.media;
  let urls = [];

  // Loop through all formats and resolutions to make download links
  for (const format of formats) {
    for (const resolution of resolutions) {
      const imageUrl = `${root}-${format}-${resolution}`;
      urls.push(imageUrl);
    }
  }

  return urls;
}

// Function to download an image from a link
function downloadImage(url, filename) {
  https.get(url, (res) => {
    // Set the encoding and check if response is successful
    if (res.statusCode === 200) {
      const file = fs.createWriteStream(filename);
      res.pipe(file);

      file.on('finish', () => {
        file.close();
        console.log(`Downloaded: ${filename}`);
      });
    } else {
      console.log(`Failed to download ${filename}: ${res.statusCode}`);
    }
  }).on('error', (err) => {
    console.error(`Error downloading ${filename}: ${err.message}`);
  });
}

// Generate links and download images
const imageUrls = generateAllImageUrls();
imageUrls.forEach((url) => {
  const filename = url.split('/').pop(); // Use the last part of the URL as filename
  downloadImage(url, filename);
});

Could work 🤷🏾‍♂️