A Web-Based Windows Spotlight Scraper

Translated from Simplified Chinese by AI.Read the original

Yep! The header image is Aperture Science _(:3 」∠ )_

I couldn't figure out how to word the title so it's clearer — basically it's a scraper for the Windows Spotlight API.

Personally I feel Windows Spotlight's pictures look a bit nicer.

import requests
import json
import os
import hashlib

JSON_URL = "https://arc.msn.com/v3/Delivery/Cache?&pid=279978&fmt=json&ctry=US&lc=en-US&pl=en-US"

def main():
    img_json = requests.get(JSON_URL, headers={'User-Agent': "WindowsShellClient/9.0.40929.0 (Windows)"}).json()
    for img_order in range(len(img_json['batchrsp']['itemorder']) - 1):
        url = json.loads(img_json['batchrsp']['items'][img_order]['item'])["ad"]["image_fullscreen_001_landscape"]["u"]
        img_binary = requests.get(url).content
        file_obj = open(
            os.path.join(
                os.path.split(
                    os.path.realpath(__file__)
                    )[0],
                hashlib.md5(img_binary).hexdigest() + '.jpg'
                ),
            'wb'
            )
        file_obj.write(img_binary)

    return 0

if __name__ == "__main__":
    main()

Also, why do the downloaded ones look uglier than they do on the lock screen?

Known issue: the JSON doesn't contain all the images, so you might need a for loop to fetch the JSON.

I'll make an API when I have time.