-
-
Notifications
You must be signed in to change notification settings - Fork 222
SteamGridDB integration #960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
180c373
steamgridDB integration added
zurdi15 c8f9015
Merge branch 'master' into feature/steamgriddb
zurdi15 9f93623
fixed aspect ratio
zurdi15 7dfbcc9
dinamic ratio for small artwork
zurdi15 b314799
fixed info details on xs
zurdi15 32e0850
force aspect ratio for all covers
zurdi15 542cc6a
added updated_at column to tables
zurdi15 24d6770
added cover image reactivity
zurdi15 d3324b6
added created_at column
zurdi15 9a86df5
reactivity added to all images
zurdi15 3758982
added ipykernel to dev dependencies
zurdi15 a07133d
added filter for static/animated cover
zurdi15 0f1db6b
Update frontend/src/components/common/Game/AdminMenu.vue
zurdi15 d2fe08f
added update_at and created_at to base model
zurdi15 818872e
fixed migrations
zurdi15 dc479b2
fixes from trunk
zurdi15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,63 @@ | ||
from typing import Final | ||
|
||
import requests | ||
from config import STEAMGRIDDB_API_KEY | ||
from logger.logger import log | ||
|
||
# Used to display the Mobygames API status in the frontend | ||
STEAMGRIDDB_API_ENABLED: Final = bool(STEAMGRIDDB_API_KEY) | ||
|
||
# SteamGridDB dimensions | ||
STEAMVERTICAL = "600x900" | ||
GALAXY342 = "342x482" | ||
GALAXY660 = "660x930" | ||
SQUARE512 = "512x512" | ||
SQUARE1024 = "1024x1024" | ||
|
||
|
||
class SGDBBaseHandler: | ||
def __init__(self) -> None: | ||
self.BASE_URL = "https://www.steamgriddb.com/api/v2" | ||
self.search_endpoint = f"{self.BASE_URL}/search/autocomplete" | ||
self.grid_endpoint = f"{self.BASE_URL}/grids/game" | ||
self.headers = { | ||
"Authorization": f"Bearer {STEAMGRIDDB_API_KEY}", | ||
"Accept": "*/*", | ||
} | ||
self.BASE_URL = "https://www.steamgriddb.com/api/v2" | ||
self.DEFAULT_IMAGE_URL = "https://www.steamgriddb.com/static/img/logo-512.png" | ||
|
||
def get_details(self, term): | ||
def get_details(self, search_term): | ||
search_response = requests.get( | ||
f"{self.BASE_URL}/search/autocomplete/{term}", | ||
f"{self.search_endpoint}/{search_term}", | ||
headers=self.headers, | ||
timeout=120, | ||
).json() | ||
|
||
if len(search_response["data"]) == 0: | ||
log.info(f"Could not find {term} on SteamGridDB") | ||
return ("", "", self.DEFAULT_IMAGE_URL) | ||
|
||
game_id = search_response["data"][0]["id"] | ||
game_name = search_response["data"][0]["name"] | ||
|
||
game_response = requests.get( | ||
f"{self.BASE_URL}/grid/game/{game_id}", headers=self.headers, timeout=120 | ||
).json() | ||
|
||
if len(game_response["data"]) == 0: | ||
log.info(f"Could not find {game_name} image on SteamGridDB") | ||
return (game_id, game_name, self.DEFAULT_IMAGE_URL) | ||
|
||
game_image_url = game_response["data"][0]["url"] | ||
|
||
return (game_id, game_name, game_image_url) | ||
log.warning(f"Could not find '{search_term}' on SteamGridDB") | ||
return "" | ||
|
||
games = [] | ||
for game in search_response["data"]: | ||
covers_response = requests.get( | ||
f"{self.grid_endpoint}/{game['id']}", | ||
headers=self.headers, | ||
timeout=120, | ||
params={ | ||
"dimensions": f"{STEAMVERTICAL},{GALAXY342},{GALAXY660},{SQUARE512},{SQUARE1024}", | ||
}, | ||
).json() | ||
|
||
games.append( | ||
{ | ||
"name": game["name"], | ||
"resources": [ | ||
{"thumb": cover["thumb"], "url": cover["url"]} | ||
for cover in covers_response["data"] | ||
], | ||
} | ||
) | ||
|
||
return games | ||
|
||
|
||
sgdb_handler = SGDBBaseHandler() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.