Skip to content

Conversation

@EmoonX
Copy link
Contributor

@EmoonX EmoonX commented Jan 4, 2025

Description

(reopening #3543)

As of now, when using the "Add to Steam" feature, games are added to Steam in a barebones state. This PR improves upon that by fuzzy-searching the game title (program name) on SteamGridDB and, when available, downloading the respective assets and saving them to the designated user directory (.../steam/userdata/<user_id>/config/grid); in a similar vein to what happens when using Steam ROM Manager.

Since Steam relies on appIDs for game identification, one is now generated by a hash method (for uniqueness) and saved to shortcuts.vdf. Same appID is then used for naming downloaded assets.

Makes use of steamgrid-proxy, in particular the changes introduced by bottlesdevs/steamgrid-proxy#1 and bottlesdevs/steamgrid-proxy#2. However, these don't seem to be in production (https://steamgrid.usebottles.com/api) yet, so the only way to currently test it is by running the API webserver locally.

Further improvements?

SteamGridDB search can occasionally fail or even return the wrong match. Perhaps one way to solve that would be adding a Custom SteamGridDB Game ID setting for individual programs. Will wait for further feedback.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

First of all, make sure steamgrid-proxy is running, on the correct port and with the right SteamGridDB API key.

Add a game executable to a bottle, renaming it if needed. Then right click -> Add to Steam. Open (or restart) Steam as needed. All the available assets (grid, hgrid, hero, logo and icon) should be loaded as expected.

You can check for match correctness by comparing it to the Add to Library option: if the latter produces a nonempty grid for Bottles's library, then likewise both it and its sibling assets should be visible on Steam.

  • before:
    image
    image

  • after:
    image
    image

@EmoonX EmoonX changed the title Fetch steam assets Fetch SteamGridDB assets when adding game to Steam Jan 4, 2025
Comment on lines +546 to +548
except:
# Unreachable host or issue saving files, nothing we can do
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it'll be better to specify which exception(s).

cmd = "xdg-open"
args = "bottles:run/'{0}'/'{1}'"
args = f"bottles:run/'{self.config.Name}'/'{program_name}'"
appid = crc32(str.encode(self.config.Name + program_name)) | 0x80000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x80000000 should have an accompanying source/context


confs = glob(os.path.join(self.userdata_path, "*/config/"))
shortcut = {
"appid": appid - 0x100000000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x100000000 should have an accompanying source/context

res = requests.get(f"https://steamgrid.usebottles.com/api/search/{name}")
except:
return
# url = f"https://steamgrid.usebottles.com/api/search/{program_name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this is commented?

Comment on lines +63 to +68
res = requests.get(url)
res.raise_for_status()
ext = os.path.splitext(url)[-1]
asset_path += ext
with open(asset_path, "wb") as img:
img.write(res.content)
Copy link
Member

@TheEvilSkeleton TheEvilSkeleton Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For increased readability, I'd avoid abbreviating variable names, i.e. use result as opposed to res, etc.

program_name, asset_path, asset_type, reraise_exceptions=True
)
except HTTPError:
# Usually missing asset (404), keep trying for the rest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed

@orowith2os
Copy link
Contributor

SteamGridDB search can occasionally fail or even return the wrong match. Perhaps one way to solve that would be adding a Custom SteamGridDB Game ID setting for individual programs. Will wait for further feedback.

This would be a good idea. I'll convert this to a draft until it's deemed "good to go".

@orowith2os orowith2os marked this pull request as draft February 3, 2025 21:40
@orowith2os orowith2os added this to the 52.0 milestone Feb 3, 2025
@EmoonX
Copy link
Contributor Author

EmoonX commented Feb 4, 2025

SteamGridDB search can occasionally fail or even return the wrong match. Perhaps one way to solve that would be adding a Custom SteamGridDB Game ID setting for individual programs. Will wait for further feedback.

This would be a good idea. I'll convert this to a draft until it's deemed "good to go".

Keep in mind that it isn't exclusive to this PR. The same system is used for the Add to Library feature; if you try to add a program named X and the fuzzy search fails for X, then you'll also get a blank/placeholder grid for it in the Library tab. So not a blocking issue, and I prefer to deal with that in a separate PR further on.

Either way, this one isn't going anywhere until https://steamgrid.usebottles.com/api is finally updated (I beg of you, @francescomasala... you're our only hope).

@mirkobrombin
Copy link
Member

I would keep this MR open even if old because the changes were good, just need a few changes. @EmoonX are you still interested or should I jump in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants