[game-data-packager] 01/01: Steam: compare locally found games with http://steamcommunity.com/profiles/<SteamID>/

Alexandre Detiste detiste-guest at moszumanska.debian.org
Wed Sep 9 09:11:41 UTC 2015


This is an automated email from the git hooks/post-receive script.

detiste-guest pushed a commit to branch master
in repository game-data-packager.

commit 47f9deb5b37c12ee432fb255ac3de9764f194ec4
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Wed Sep 9 11:10:54 2015 +0200

    Steam: compare locally found games with http://steamcommunity.com/profiles/<SteamID>/
---
 game_data_packager/__init__.py | 32 +++++++++++++++++++++++++-------
 game_data_packager/steam.py    | 15 +++++++++++++--
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/game_data_packager/__init__.py b/game_data_packager/__init__.py
index cf11e5a..8419c25 100644
--- a/game_data_packager/__init__.py
+++ b/game_data_packager/__init__.py
@@ -54,6 +54,7 @@ from .util import (MEBIBYTE,
         lang_score,
         ascii_safe,
         which)
+from .steam import get_steam_id, owned_steam_games
 from .version import GAME_PACKAGE_VERSION
 
 AGENT = ('Debian Game-Data-Packager/%s (%s %s;'
@@ -3087,26 +3088,40 @@ def load_games(workdir=None,game='*'):
     return games
 
 def run_steam_meta_mode(parsed, games):
-    logging.info('Searching for Steam games...')
+    owned = set()
+    if parsed.download:
+        steam_id = get_steam_id()
+        if steam_id is None:
+            logger.error("Couldn't read SteamID from ~/.steam/config/loginusers.vdf")
+        else:
+            logger.info('Getting list of owned games from '
+                        'http://steamcommunity.com/profiles/' + steam_id)
+            owned = set(g[0] for g in owned_steam_games(steam_id))
+
+    logging.info('Searching for locally installed Steam games...')
     found_games = []
     found_packages = []
     for game, gamedata in games.items():
         for package in gamedata.packages.values():
+            id = package.steam.get('id') or gamedata.steam.get('id')
+            if not id:
+                continue
+
             if package.type == 'demo':
                 continue
             # ignore other translations for "I Have No Mouth"
             if lang_score(package.lang) == 0:
                 continue
 
+            installed = PACKAGE_CACHE.is_installed(package.name)
+            if parsed.new and installed:
+                continue
+
             paths = []
             for path in gamedata.iter_steam_paths((package,)):
                 if path not in paths:
                     paths.append(path)
-            if not paths:
-                continue
-
-            installed = PACKAGE_CACHE.is_installed(package.name)
-            if parsed.new and installed:
+            if not paths and id not in owned:
                 continue
 
             if game not in found_games:
@@ -3133,7 +3148,10 @@ def run_steam_meta_mode(parsed, games):
                 continue
             print('[%s] %-42s    %s' % ('x' if p['installed'] else ' ',
                                         p['package'], ascii_safe(p['longname'])))
-            print('\n'.join(p['paths']))
+            for path in p['paths']:
+                print(path)
+            if not p['paths']:
+                print('<game owned but not installed/found>')
         print()
 
     if not parsed.new and not parsed.all:
diff --git a/game_data_packager/steam.py b/game_data_packager/steam.py
index 366a42a..d39be1b 100644
--- a/game_data_packager/steam.py
+++ b/game_data_packager/steam.py
@@ -16,6 +16,7 @@
 # /usr/share/common-licenses/GPL-2.
 
 import glob
+import os
 import xml.etree.ElementTree
 import urllib.request
 
@@ -43,7 +44,7 @@ def parse_acf(path):
             yield acf_struct
 
 def owned_steam_games(steam_id):
-    url = "http://steamcommunity.com/id/" + steam_id + "/games?xml=1"
+    url = "http://steamcommunity.com/profiles/" + steam_id + "/games?xml=1"
     html = urllib.request.urlopen(url)
     tree = xml.etree.ElementTree.ElementTree()
     tree.parse(html)
@@ -52,4 +53,14 @@ def owned_steam_games(steam_id):
         appid = int(game.find('appID').text)
         name = game.find('name').text
         #print(appid, name)
-        yield [appid, name]
+        yield (appid, name)
+
+def get_steam_id():
+    path = os.path.expanduser('~/.steam/config/loginusers.vdf')
+    if not os.path.isfile(path):
+        return None
+    with open(path, 'r', ) as data:
+        for line in data.readlines():
+            line = line.strip('\t\n "')
+            if line not in ('users', '{'):
+                return line

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list