Skip to content

Instantly share code, notes, and snippets.

@bnrubin
Last active December 11, 2024 20:58
Show Gist options
  • Save bnrubin/4cd7569cc4d28d83d8f11801ab827327 to your computer and use it in GitHub Desktop.
Save bnrubin/4cd7569cc4d28d83d8f11801ab827327 to your computer and use it in GitHub Desktop.
Steam Screenshot Archiver
import requests
import pathlib
import string
import shutil
import os
import datetime
import json
# This probably is broken in weird ways. I've only run it on my own computer.
apikey = 'YOUR STEAM API KEY'
archive = pathlib.Path('C:/where_you_want_the_files_to_go')
# look for wherever your screenshots are in a path that looks like this.
# The numbers are probably your numeric steam ID, but I haven't looked into it
sdir = pathlib.Path('C:/Program Files (x86)/Steam/userdata/###/###/remote')
with open('steam_archive.json') as jsonfile:
jdata = json.load(jsonfile)
lastrun = datetime.datetime.fromisoformat(jdata['lastrun'])
apps = jdata['apps']
appurl = 'https://api.steampowered.com/ISteamApps/GetAppList/v2/?key={}'.format(apikey)
r = requests.get(appurl)
apps.update({app['appid']:app['name'] for app in r.json()['applist']['apps'] if app['name']})
games = [x.name for x in sdir.iterdir() if x.is_dir()]
def to_windows_filename(fname):
valid_chars = '-_.() {}{}'.format(string.ascii_letters, string.digits)
return ''.join(c for c in fname if c in valid_chars)
gamedict = {}
for game in games:
try:
info = to_windows_filename(apps[int(game)])
gamedict[int(game)] = info
except KeyError:
print('Error: {}'.format(game))
except ValueError:
print('Error: {}'.format(game))
with open('steam_archive.json') as jsonfile:
jdata = json.load(jsonfile)
lastrun = datetime.datetime.fromisoformat(jdata['lastrun'])
apps = jdata['apps']
for game in sdir.glob('*/screenshots'):
try:
name = gamedict[int(game.parent.name)].strip()
except KeyError:
continue
archive_path = archive.joinpath(name)
for shot in game.iterdir():
if datetime.datetime.fromtimestamp(shot.stat().st_mtime) > lastrun:
if not shot.is_dir():
try:
os.mkdir(archive_path)
except FileExistsError:
pass
shutil.copyfile(shot, archive_path.joinpath(shot.name))
now = datetime.datetime.now()
with open('steam_archive.json', 'w') as jsonfile:
json.dump({'lastrun': now.isoformat(), 'apps': apps}, jsonfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment