Skip to content

Instantly share code, notes, and snippets.

@buxel
Last active October 21, 2020 05:21
Show Gist options
  • Save buxel/fa710969bbc650447d924cf8f7d15204 to your computer and use it in GitHub Desktop.
Save buxel/fa710969bbc650447d924cf8f7d15204 to your computer and use it in GitHub Desktop.
# This script will create steam shortcuts for all lutris games and add them to the "lutris" category
import os
import shutil
import vdf # from https://pypi.org/project/vdf/
from lutris import pga
import lutris.util.resources as rs
shortcut_path = "/home/buxel/.local/share/Steam/userdata/67626145/config/shortcuts.vdf"
steam_tag = "Lutris"
games = pga.get_games(filter_installed=True)
no_steam = [g for g in games if g['runner'] != 'steam']
# Grid: /home/buxel/.local/share/Steam/userdata/67626145/config/grid/
def do_it():
with open(shortcut_path, "rb") as shortcut_file:
shortcuts = vdf.binary_loads(shortcut_file.read())[
'shortcuts'].values()
other_shortcuts = [
s for s in shortcuts
if steam_tag not in s['tags'].values()
]
lutris_shortcuts = list(map(generate_shortcut, no_steam))
new_shortcuts = {
'shortcuts': list_todict(other_shortcuts + lutris_shortcuts)
}
with open(shortcut_path, "wb") as shortcut_file:
shortcut_file.write(vdf.binary_dumps(new_shortcuts))
def list_todict(l):
return {str(i): l[i] for i in range(0, len(l))}
def generate_shortcut(game):
name = game['name']
slug = game['slug']
icon = rs.get_icon_path(slug)
banner = rs.get_banner_path(slug)
lutris_binary = shutil.which("lutris")
start_dir = os.path.dirname(lutris_binary)
shortcut_dict = {
'AllowDesktopConfig': 1,
'AllowOverlay': 1,
'AppName': name,
'Devkit': 0,
'DevkitGameID': '',
'Exe': f'"{lutris_binary}"',
'IsHidden': 0,
'LastPlayTime': 0,
'LaunchOptions': f'lutris:rungame/{slug}',
'OpenVR': 0,
'ShortcutPath': '',
'StartDir': f'"{start_dir}"',
'icon': icon,
'tags': {
'0': steam_tag # to identify generated shortcuts
}
}
return shortcut_dict
do_it()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment