steam: Unpack named tuples early

This commit is contained in:
kramo
2025-12-07 15:47:42 +01:00
parent bfa58bc1b3
commit ecda080d80

View File

@@ -7,6 +7,7 @@ import logging
import re import re
import struct import struct
import time import time
from collections import defaultdict
from collections.abc import Generator, Iterable, Sequence from collections.abc import Generator, Iterable, Sequence
from contextlib import suppress from contextlib import suppress
from gettext import gettext as _ from gettext import gettext as _
@@ -112,41 +113,39 @@ def get_games(*, skip_ids: Iterable[str]) -> Generator[Game]:
librarycache = _data_dir() / "appcache" / "librarycache" librarycache = _data_dir() / "appcache" / "librarycache"
with (_data_dir() / "appcache" / "appinfo.vdf").open("rb") as fp: with (_data_dir() / "appcache" / "appinfo.vdf").open("rb") as fp:
appinfo = dict(_parse_appinfo_vdf(fp)) appinfo = defaultdict(_AppInfo, _parse_appinfo_vdf(fp))
appids = {i.rsplit("_", 1)[-1] for i in skip_ids if i.startswith(f"{ID}_")} appids = {i.rsplit("_", 1)[-1] for i in skip_ids if i.startswith(f"{ID}_")}
for manifest in _manifests(): for manifest in _manifests():
try: try:
app = _App.from_manifest(manifest) name, appid, stateflags, lastplayed = _App.from_manifest(manifest)
except ValueError: except ValueError:
continue continue
duplicate = app.appid in appids duplicate = appid in appids
installed = ( installed = (
int(app.stateflags) & _MANIFEST_INSTALLED_MASK int(stateflags) & _MANIFEST_INSTALLED_MASK
if app.stateflags and app.stateflags.isdigit() if stateflags and stateflags.isdigit()
else True else True
) )
if duplicate or not installed: if duplicate or not installed:
continue continue
info = appinfo.get(app.appid) type_, developer, capsule = appinfo[appid]
if info and info.type and (info.type.lower() not in _RELEVANT_TYPES): if type_ and (type_.lower() not in _RELEVANT_TYPES):
continue continue
appids.add(app.appid) appids.add(appid)
yield Game( yield Game(
added=added, added=added,
executable=f"{OPEN} steam://rungameid/{app.appid}", executable=f"{OPEN} steam://rungameid/{appid}",
game_id=f"{ID}_{app.appid}", game_id=f"{ID}_{appid}",
source=ID, source=ID,
last_played=int(app.lastplayed) last_played=int(lastplayed) if lastplayed and lastplayed.isdigit() else 0,
if app.lastplayed and app.lastplayed.isdigit() name=name,
else 0, developer=developer,
name=app.name, cover=_find_cover(librarycache / appid, capsule),
developer=info.developer if info else None,
cover=_find_cover(librarycache / app.appid, info.capsule if info else None),
) )