From 8c0951fbd3e52c6c29a77ae8375a7865facf1165 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Wed, 10 Jan 2024 18:47:00 -0800 Subject: [PATCH] Sync Steam games playtime to Lutris --- lutris/services/base.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lutris/services/base.py b/lutris/services/base.py index 1fb1e927d..7cb1c94ac 100644 --- a/lutris/services/base.py +++ b/lutris/services/base.py @@ -1,4 +1,5 @@ """Generic service utilities""" +import json import os import shutil from gettext import gettext as _ @@ -194,19 +195,19 @@ class BaseService(GObject.Object): extra installer script steps to move the extras in.""" return [], [] - def match_game(self, service_game, api_game): + def match_game(self, service_game, lutris_game): """Match a service game to a lutris game referenced by its slug""" if not service_game: return sql.db_update( PGA_DB, "service_games", - {"lutris_slug": api_game["slug"]}, + {"lutris_slug": lutris_game["slug"]}, conditions={"appid": service_game["appid"], "service": self.id} ) unmatched_lutris_games = get_games( searches={"installer_slug": self.matcher}, - filters={"slug": api_game["slug"]}, + filters={"slug": lutris_game["slug"]}, excludes={"service": self.id} ) for game in unmatched_lutris_games: @@ -218,6 +219,12 @@ class BaseService(GObject.Object): conditions={"id": game["id"]} ) + # Copy playtimes from Steam's data + for game in get_games(filters={"service": self.id, "service_id": service_game["appid"]}): + steam_game_playtime = json.loads(service_game["details"]).get("playtime_forever") + playtime = steam_game_playtime / 60 + sql.db_update(PGA_DB, "games", {"playtime": playtime}, conditions={"id": game["id"]}) + def match_games(self): """Matching of service games to lutris games""" service_games = {