Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def run(appid):

@plugin.route('/delete_cache')
def delete_cache():
steam.delete_cache()
arts.delete_cache()


Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<setting id="steam-args" type="text" label="Arguments to pass to your Steam executable"/>
<setting id="version" type="text" label="Internal version number, do not modify" visible="false"/>
<setting id="enable-art-fallback" type="bool" default="true" label="Fallback to another art type if a game has missing art. First launch may be longer for large libraries."/>
<setting id="games-expire-after-minutes" type="number" default="4320" label="Number of minutes before expiration of the games lists cache"/>
<setting id="arts-expire-after-months" type="number" default="2" label="Number of months before expiration of the arts availability cache"/>
<setting id="delete-cache" type="action" label="Clean available games and arts cache" action="RunPlugin(plugin://plugin.program.steam.library/delete_cache)"/>
</settings>
37 changes: 30 additions & 7 deletions resources/steam.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import os
import sys
import shlex
import subprocess

import xbmc
import xbmcaddon
import xbmcplugin

import requests
import requests_cache

from util import log

__addon__ = xbmcaddon.Addon()
# define the cache file to reside in the ..\Kodi\userdata\addon_data\(your addon)
addonUserDataFolder = xbmc.translatePath(__addon__.getAddonInfo('profile'))
STEAM_GAMES_CACHE_FILE = xbmc.translatePath(os.path.join(addonUserDataFolder, 'requests_cache_games'))
minutesBeforeGamesListsExpiration = int(xbmcplugin.getSetting(int(sys.argv[1]), "games-expire-after-minutes")) # Default is 3 days

# cache expires after: 86400=1 day 604800=7 days
cached_requests = requests_cache.core.CachedSession(STEAM_GAMES_CACHE_FILE, backend='sqlite',
expire_after=60 * minutesBeforeGamesListsExpiration,
old_data_on_error=True)


def install(steam_exe_path, appid):
"""
Expand All @@ -29,7 +48,7 @@ def run(steam_exe_path, steam_launch_args, appid):
log('executing ' + steam_exe_path + ' ' + steam_launch_args + ' steam://rungameid/' + appid)

# https://developer.valvesoftware.com/wiki/Steam_browser_protocol
subprocess.call([steam_exe_path] + user_args + ['steam://rungameid/' + appid]) #Concatenate the arrays into one
subprocess.call([steam_exe_path] + user_args + ['steam://rungameid/' + appid]) # Concatenate the arrays into one


def get_user_games(steam_api_key, steam_user_id, recent_only=False):
Expand Down Expand Up @@ -73,13 +92,17 @@ def get_user_games(steam_api_key, steam_user_id, recent_only=False):
api_url = 'https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/'

# We send a request to the API, including needed parameters and "include_appinfo" so that game details are returned with the response.
response = requests.get(url=api_url,
params={'key': steam_api_key,
'steamid': steam_user_id,
'include_appinfo': 1,
'format': 'json'},
timeout=10)
response = cached_requests.get(url=api_url,
params={'key': steam_api_key,
'steamid': steam_user_id,
'include_appinfo': 1,
'format': 'json'},
timeout=5)

response.raise_for_status() # If the status code indicates an error, raise a HTTPError, which is itself a RequestException, based on the builtin IOError
response_data = response.json().get('response', {})
return response_data.get('games', {})


def delete_cache():
os.remove(STEAM_GAMES_CACHE_FILE + ".sqlite")