-2

Basically I have been trying to find a nice simple way to automate grabbing lots of steam header images for use as Windows tile icons

All of the headers are stored here

http://cdn.akamai.steamstatic.com/steam/apps/10/header.jpg

With the number being the game's ID

I've seen a bit about scraping, but I am unsure how to do something that basically downloads all images from

/apps/10/header.jpg

to

/apps/500000/header.jpg

And etc

Flerp
  • 1
  • 1

1 Answers1

2

I built a small script to do this in Python (version 2, but it should run fine in using 3). This utilizes the requests library, so if you don't have that installed you'd need that too.

Set up:

  • Copy this script into a file and save with a python extension. Example: download_headers.py
  • In the same directory that download_headers.py was saved, create a directory named game_headers

Script:

import requests
import os

save_location = "game_headers"

base_url = "http://store.steampowered.com/api/appdetails/?appids=%s&filters=basic"

header_images = []
full_path = os.path.abspath(save_location)

for x in [440,65980,281690,1]:
    r = requests.get(base_url % (x)).json()
    try:
        header_images.append((x, r[unicode(x)]['data']['header_image']))
    except KeyError:
        print "AppID {} => Did not return data".format(x)

# Download the images

for i in header_images:
    print "Downloading header image for AppID {}".format(i[0])
    r = requests.get(i[1], stream=True)
    if r.status_code == 200:
        with open(os.path.join(full_path, "{}_header.jpg".format(unicode(i[0]))), 'wb') as f:
            for chunk in r.iter_content():
                f.write(chunk)

Output:

> python headers.py
AppID 1 => Did not return data
Downloading header image for AppID 440
Downloading header image for AppID 65980
Downloading header image for AppID 281690

And there are now three images in my game_headers directory.

Modifications

As it is currently written, the script only looks for images for App IDs 440, 65980, 281690 and 1. If you want to make it a full range of IDs, modify the following line:

for x in [440,65980,281690,1]:

to be a range of integers:

for x in range(420,450):

This will result in a lot of App IDs not existing, but as was seen above with App ID 1, these are skipped:

AppID 421 => Did not return data
AppID 422 => Did not return data
AppID 423 => Did not return data
AppID 424 => Did not return data
AppID 425 => Did not return data
AppID 426 => Did not return data
AppID 427 => Did not return data
AppID 428 => Did not return data
AppID 429 => Did not return data
AppID 430 => Did not return data
AppID 431 => Did not return data
AppID 432 => Did not return data
AppID 433 => Did not return data
AppID 434 => Did not return data
AppID 435 => Did not return data
AppID 436 => Did not return data
AppID 437 => Did not return data
AppID 438 => Did not return data
AppID 439 => Did not return data
AppID 441 => Did not return data
AppID 442 => Did not return data
AppID 443 => Did not return data
AppID 444 => Did not return data
AppID 445 => Did not return data
AppID 446 => Did not return data
AppID 447 => Did not return data
AppID 448 => Did not return data
AppID 449 => Did not return data
Downloading header image for AppID 420
Downloading header image for AppID 440

Notes

This utilizes the appdetails, unofficial Steam Storefront API. With that bit of knowledge, that means that if Valve modifies it they probably aren't going to announce it ahead of time. It passes the basic filter, to reduce the amount of data that is returned (the header_image is part of this filter).

You could improve performance by passing a comma separated string of appids to the base_url. In general, Valve allows 100 at a time in these types of API calls. I haven't tested that with this specific call. If you do this, you will have to iterate through the response to check each returned application.

Andy
  • 49,085
  • 60
  • 166
  • 233