feat: link DLC and soundtracks to parent games
CI / test (push) Successful in 32s

Add games.parent_appid (schema v9), parse appinfo parent links, show addons and parent game in the card, and add import_steam.py --refresh-parents for existing databases.
This commit is contained in:
strsv committed 2026-11-07 01:36:26 +03:00
1 parent 376a2ee7a0
commit 528fcb7474
18 files changed
+135 -11

No files matched your search

+8 -1
View File
@@ -8,7 +8,7 @@ from datetime import datetime, timezone
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEFAULT_DB = os.path.join(BASE_DIR, "steam.db")
SCHEMA_PATH = os.path.join(BASE_DIR, "tools", "schema.sql")
SCHEMA_VERSION = 8
SCHEMA_VERSION = 9
MOOD_PRESETS = {
"adventure-rpg-party": {
@@ -581,6 +581,12 @@ def _migration_8(con):
"ON hltb_cache(fetched_at)")
def _migration_9(con):
"""Link DLC, soundtracks and tools to their parent app."""
_ensure_column(con, "games", "parent_appid", "INTEGER")
con.execute("CREATE INDEX IF NOT EXISTS idx_games_parent ON games(parent_appid)")
MIGRATIONS = {
1: _migration_1,
2: _migration_2,
@@ -590,6 +596,7 @@ MIGRATIONS = {
6: _migration_6,
7: _migration_7,
8: _migration_8,
9: _migration_9,
}
+23 -3
View File
@@ -49,6 +49,8 @@ def main():
ap.add_argument("--incremental", action="store_true",
help="only add new apps; update install/playtime for existing")
ap.add_argument("--no-network", action="store_true", help="never download tag names")
ap.add_argument("--refresh-parents", action="store_true",
help="update games.parent_appid from appinfo and exit")
args = ap.parse_args()
root = args.steam_root or steam_source.find_steam_root()
@@ -80,6 +82,21 @@ def main():
db.init(con)
db.seed_moods(con)
if args.refresh_parents:
updated = 0
for appid, info in appinfo.items():
parent = info.get("parent")
if not parent:
continue
cursor = con.execute(
"UPDATE games SET parent_appid = ? WHERE appid = ? AND "
"COALESCE(parent_appid, 0) <> ?", (parent, appid, parent))
updated += max(0, cursor.rowcount)
con.commit()
print(f"Parents updated: {updated}")
con.close()
return
existing_tags = {r["tag_id"]: r["name"] for r in con.execute("SELECT tag_id, name FROM tag_names")}
new_tags = {}
if not args.no_network and (args.refresh_tags or len(existing_tags) < 50):
@@ -93,12 +110,14 @@ def main():
def upsert_game(row):
con.execute(
"""INSERT INTO games (appid, name, type, release_date, metacritic, review_pct, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
"""INSERT INTO games (appid, name, type, release_date, metacritic, review_pct,
parent_appid, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(appid) DO UPDATE SET
name = excluded.name, type = excluded.type,
release_date = COALESCE(excluded.release_date, games.release_date),
metacritic = excluded.metacritic, review_pct = excluded.review_pct,
parent_appid = COALESCE(excluded.parent_appid, games.parent_appid),
updated_at = excluded.updated_at""",
row,
)
@@ -150,7 +169,8 @@ def main():
info = appinfo.get(appid, {})
name = info.get("name") or installed.get(appid, {}).get("name") or f"App {appid}"
upsert_game((appid, name, info.get("type"), iso_from_unix(info.get("release")),
info.get("metacritic"), info.get("review_pct"), now))
info.get("metacritic"), info.get("review_pct"),
info.get("parent"), now))
genre_ids = info.get("genres") or {}
con.execute("DELETE FROM game_genres WHERE appid = ?", (appid,))
+1
View File
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS games (
release_date TEXT,
metacritic INTEGER,
review_pct INTEGER,
parent_appid INTEGER,
estimated_hours REAL,
hltb_main REAL,
hltb_extra REAL,
+1
View File
@@ -251,6 +251,7 @@ def read_appinfo(root):
"metacritic": common.get("metacritic_score"),
"review_pct": common.get("review_percentage"),
"release": common.get("steam_release_date"),
"parent": common.get("parent"),
}
except Exception:
pass