Last active
September 28, 2024 04:05
-
-
Save nosoop/e5dbd37e20c4e037c283a79142c46288 to your computer and use it in GitHub Desktop.
Steam file downloading tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DEFAULT] | |
basedir = gamefiles/%(appid)s | |
info_file = %(basedir)s/%(gamedir)s/steam.inf | |
[Team Fortress 2] | |
gamedir = tf | |
appid = 232250 | |
files = server_srv.so | |
engine_srv.so | |
server.dll | |
engine.dll | |
steam.inf | |
command = cmd /C echo bepis | |
[Counter Strike: Global Offensive] | |
gamedir = csgo | |
appid = 740 | |
files = server.so | |
engine.so | |
server.dll | |
engine.dll | |
steam.inf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import configparser | |
import itertools | |
import json | |
import os | |
import pathlib | |
import shlex | |
import shutil | |
import string | |
import subprocess | |
import urllib.request | |
# This requires a version of steam[client] newer than 1.2.0 | |
# current version on pypi is unable to access dedicated server files (e.g. depotid 232250) | |
# make sure pip / wheel are both updated from their default versions in venv | |
import steam | |
import steam.client | |
import steam.client.cdn | |
import steam.webapi | |
def read_steam_inf(steam_info): | |
if os.path.exists(steam_info): | |
with open(steam_info, 'rt') as c: | |
return dict(line.strip().split('=', maxsplit = 1) for line in c.readlines()) | |
return {} | |
if __name__ == "__main__": | |
config = configparser.ConfigParser(converters = { | |
'path': pathlib.Path, | |
'lines': lambda x: x.splitlines(), | |
'template': string.Template | |
}) | |
config.read('config.ini', encoding = 'utf8') | |
webapi_client = steam.webapi.WebAPI(key = None) | |
for section, proxy in config.items(): | |
if section == configparser.DEFAULTSECT: | |
continue | |
entries = read_steam_inf(proxy.get('info_file')) | |
if entries: | |
result = webapi_client.ISteamApps.UpToDateCheck( | |
appid = entries.get('appID'), | |
version = entries.get('PatchVersion') | |
) | |
if result.get('response', {}).get('up_to_date', False): | |
continue | |
steamclient = steam.client.SteamClient() | |
steamclient.anonymous_login() | |
cdnclient = steam.client.cdn.CDNClient(steamclient) | |
download_files = proxy.getlines('files') | |
for bin in itertools.chain.from_iterable( | |
cdnclient.iter_files(proxy.getint('appid'), filt) | |
for filt in [ '*.so', '*.dll', '*.inf' ] | |
): | |
bin_path = pathlib.Path(bin.filename) | |
if any(bin_path.name == f for f in download_files): | |
target = proxy.getpath('basedir') / bin_path | |
target.parent.mkdir(parents = True, exist_ok = True) | |
with target.open('wb') as dst: | |
shutil.copyfileobj(bin, dst) | |
steamclient.logout() | |
# run command specified if we've updated | |
postupdate_cmd = proxy.gettemplate("command") | |
if postupdate_cmd: | |
command_args = shlex.split(postupdate_cmd.substitute(dict())) | |
subprocess.run(command_args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment