59
homelab/scripts/steam-library-to-json.py
Normal file
59
homelab/scripts/steam-library-to-json.py
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Выгрузка списка игр из Steam-библиотеки в JSON через Steam Web API.
|
||||
Нужны: API key (https://steamcommunity.com/dev/apikey) и 64-битный Steam ID.
|
||||
"""
|
||||
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
|
||||
# Подставь свои данные
|
||||
STEAM_API_KEY = "CB3A546C47CBADB5CAB3FA6D60B6DE4C" # https://steamcommunity.com/dev/apikey
|
||||
STEAM_ID_64 = "76561198113489815" # 64-битный ID, например из https://steamid.io/
|
||||
|
||||
OUTPUT_FILE = "steam_library.json"
|
||||
|
||||
|
||||
def get_owned_games(api_key: str, steam_id: str) -> list[dict]:
|
||||
url = "https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/"
|
||||
params = {
|
||||
"key": api_key,
|
||||
"steamid": steam_id,
|
||||
"include_appinfo": 1,
|
||||
"include_played_free_games": 1,
|
||||
}
|
||||
req = urllib.request.Request(
|
||||
f"{url}?{urllib.parse.urlencode(params)}",
|
||||
headers={"Accept": "application/json"},
|
||||
)
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
data = json.loads(resp.read().decode())
|
||||
if "response" not in data or "games" not in data["response"]:
|
||||
raise RuntimeError(data.get("response", data))
|
||||
return data["response"]["games"]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if not STEAM_API_KEY or not STEAM_ID_64:
|
||||
print("Заполни STEAM_API_KEY и STEAM_ID_64 в начале скрипта.")
|
||||
return
|
||||
games = get_owned_games(STEAM_API_KEY, STEAM_ID_64)
|
||||
out = [
|
||||
{
|
||||
"appid": g["appid"],
|
||||
"name": g.get("name", ""),
|
||||
"playtime_forever_min": g.get("playtime_forever", 0),
|
||||
"img_icon_url": g.get("img_icon_url", ""),
|
||||
"img_logo_url": g.get("img_logo_url", ""),
|
||||
}
|
||||
for g in games
|
||||
]
|
||||
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(out, f, ensure_ascii=False, indent=2)
|
||||
print(f"Записано {len(out)} игр в {OUTPUT_FILE}")
|
||||
print("Дальше: python3 steam_library_size.py — посчитает размеры и суммарный объём.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user