Little Python program to download your images from your Steam gallery.

For each file it just downloads the images by its id and attempts to include some meta data about the image in a separate json file. For example:

{"Id": 1474149818, "Game": "Crypt of the NecroDancer", "Desc": "Bat out of hell", "Url": "https://steamuserimages-a.akamaihd.net/ugc/974353539926239721/3591AA940A42F9217105C02EEA90190796893CED/"}

Code uses requests and has been tested with Python 3.7 on Windows.

import requests
import re
from pathlib import Path
import json
from typing import List


# Because I'm lazy and probably the only person to ever run this
STEAM_ID = 'Ardren'
DOWNLOAD_DIRECTORY = r'c:\Users\Matthewd\Dropbox\Screenshots-Steam'


def scan_gallery(username):
    file_ids = []
    page = 1

    while True:
        url = f"https://steamcommunity.com/id/{username}/screenshots/?p={page}&sort=newestfirst&browsefilter=myfiles&view=grid&privacy=14"
        r = requests.get(url)

        matches = list(re.finditer(r'<a href="https://steamcommunity\.com/sharedfiles/filedetails/\?id=(\d+)"', r.text))

        if len(matches) == 0:
            print(f"No more files found on page {page}")
            break

        print(f"Found {len(matches)} images on page {page}")

        for match in matches:
            file_ids.append(int(match.group(1)))

        page += 1

    return file_ids


def download_file_ids(base_directory: Path, file_ids: List[int]):
    for file_id in file_ids:

        download_filename = base_directory / f"{file_id}.jpeg"
        metadata_filename = base_directory / f"{file_id}.json"

        if download_filename.exists():
            print(f"Already downloaded {download_filename}")
            continue

        url = f"https://steamcommunity.com/sharedfiles/filedetails/?id={file_id}"
        r = requests.get(url)

        match = re.search('<a href="(https://steamuserimages-a.akamaihd.net/ugc/[^/]+/[^/]+/)" target=', r.text)
        if match is None:
            print(f"Unable to find image_src for file_id {file_id}")
            continue

        create_metadata(metadata_filename, file_id, r.text)

        with download_filename.open('wb+') as f:
            r = requests.get(match.group(1))
            bytes_written = f.write(r.content)
            print(f"Downloaded {bytes_written} bytes to {download_filename}")


def create_metadata(metadata_filename: Path, file_id: int, html_detail_contents: str):
    game_name_match = re.search('<h3 class="ellipsis apphub_responsive_menu_title">([^<]+)</h3>', html_detail_contents)
    game_desc_match = re.search('<textarea class="descField" name="description" id="description" class="dynInput" maxlength="140">([^<]*)</textarea>', html_detail_contents)
    image_url_match = re.search('<a href="(https://steamuserimages-a.akamaihd.net/ugc/[^/]+/[^/]+/)" target="_blank">', html_detail_contents)

    data = {
        'Id': file_id,
        'Game': game_name_match.group(1),
        'Desc': game_desc_match.group(1),
        'Url': image_url_match.group(1)
    }

    with metadata_filename.open('w+') as f:
        json.dump(data, f)


if __name__ == '__main__':
    download_file_ids(Path(DOWNLOAD_DIRECTORY), scan_gallery(STEAM_ID))