Skip to content

Commit 081da04

Browse files
authored
Merge branch 'master' into patch-1
2 parents 582d4aa + 3cd50bf commit 081da04

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ again when you get more games or want to update the category overlays.
2828
* Add the extension `.logo`/`_hero` before the image extension for logo art `Psychonauts.logo.png`, `3830_logo.png`
2929
4. *(optional)* Generate a some API Keys to enhance the automatic search:
3030
* [SteamGridDB API Key](https://www.steamgriddb.com/profile/preferences)
31-
* [IGDB API Key](https://api.igdb.com/signup)
31+
* [IGDB API Client/Secret](https://api-docs.igdb.com/#about)
3232
5. Run `steamgrid` and wait. No, really, it's all automatic. Not a single key press required.
3333
* *(optional)* Append `--steamgriddb <api key>` if you've generated one before.
34-
* *(optional)* Append `--igdb <api key>` if you've generated one before.
34+
* *(optional)* Append `--igdbclient <igdb client>` if you've genereated one before.
35+
* *(optional)* Append `--igdbsecret <igdb secret>` if you've genereated one before.
3536
* *(optional)* Append `--types <preference>` to choose your preferences between animated steam covers or static ones Available choices : `animated`,`static`. Default : `static`. You can use `animated,static` to download both while preferring animated covers, and `static,animated` for preferring static covers.
3637
* *(optional)* Append `--styles <preference>` to choose your preferences between the different covers styles from steamgriddb. Available choices : `material`,`white_logo`,`alternate`,`blurred`,`no_logo`. Default: `alternate`. You can also input multiple comma-separated choices in the same manners of the `--types` argument.
3738
* *(optional)* Append `--appids <appid1,appid2>` to only process the specified appID(s)

download.go

+39-12
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ func getSteamGridDBImage(game *Game, artStyleExtensions []string, steamGridDBApi
227227
}
228228

229229
const igdbImageURL = "https://images.igdb.com/igdb/image/upload/t_720p/%v.jpg"
230-
const igdbGameURL = "https://api-v3.igdb.com/games"
231-
const igdbCoverURL = "https://api-v3.igdb.com/covers"
230+
const igdbGameURL = "https://api.igdb.com/v4/games"
231+
const igdbCoverURL = "https://api.igdb.com/v4/covers"
232232
const igdbGameBody = `fields name,cover; search "%v";`
233233
const igdbCoverBody = `fields image_id; where id = %v;`
234234

@@ -243,10 +243,37 @@ type igdbCover struct {
243243
Image_ID string
244244
}
245245

246-
func igdbPostRequest(url string, body string, IGDBApiKey string) ([]byte, error) {
246+
func igdbPostRequest(url string, body string, IGDBSecret string, IGDBClient string) ([]byte, error) {
247+
248+
tokenClient := &http.Client{}
249+
reqq, err := http.NewRequest("POST", "https://id.twitch.tv/oauth2/token?client_id="+IGDBClient+"&client_secret="+IGDBSecret+"&grant_type=client_credentials", strings.NewReader(body))
250+
tokenResponse, err := tokenClient.Do(reqq)
251+
if err != nil {
252+
return nil, err
253+
}
254+
255+
tokenBody, err := ioutil.ReadAll(tokenResponse.Body)
256+
257+
if err != nil {
258+
return nil, err
259+
}
260+
261+
type token struct {
262+
String string "json:\"access_token\""
263+
}
264+
265+
token1 := token{}
266+
267+
jsonErr := json.Unmarshal(tokenBody, &token1)
268+
269+
if jsonErr != nil {
270+
return nil, jsonErr
271+
}
272+
247273
client := &http.Client{}
248274
req, err := http.NewRequest("POST", url, strings.NewReader(body))
249-
req.Header.Add("user-key", IGDBApiKey)
275+
req.Header.Add("Client-ID", IGDBClient)
276+
req.Header.Add("Authorization", "Bearer "+token1.String)
250277
req.Header.Add("Accept", "application/json")
251278
if err != nil {
252279
return nil, err
@@ -266,8 +293,8 @@ func igdbPostRequest(url string, body string, IGDBApiKey string) ([]byte, error)
266293
return responseBytes, nil
267294
}
268295

269-
func getIGDBImage(gameName string, IGDBApiKey string) (string, error) {
270-
responseBytes, err := igdbPostRequest(igdbGameURL, fmt.Sprintf(igdbGameBody, gameName), IGDBApiKey)
296+
func getIGDBImage(gameName string, IGDBSecret string, IGDBClient string) (string, error) {
297+
responseBytes, err := igdbPostRequest(igdbGameURL, fmt.Sprintf(igdbGameBody, gameName), IGDBSecret, IGDBClient)
271298
if err != nil {
272299
return "", err
273300
}
@@ -282,7 +309,7 @@ func getIGDBImage(gameName string, IGDBApiKey string) (string, error) {
282309
return "", nil
283310
}
284311

285-
responseBytes, err = igdbPostRequest(igdbCoverURL, fmt.Sprintf(igdbCoverBody, jsonGameResponse[0].Cover), IGDBApiKey)
312+
responseBytes, err = igdbPostRequest(igdbCoverURL, fmt.Sprintf(igdbCoverBody, jsonGameResponse[0].Cover), IGDBSecret, IGDBClient)
286313
if err != nil {
287314
return "", err
288315
}
@@ -329,7 +356,7 @@ const steamCdnURLFormat = `cdn.akamai.steamstatic.com/steam/apps/%v/`
329356
// sources. Returns the final response received and a flag indicating if it was
330357
// from a Google search (useful because we want to log the lower quality
331358
// images).
332-
func getImageAlternatives(game *Game, artStyle string, artStyleExtensions []string, skipSteam bool, steamGridDBApiKey string, IGDBApiKey string, skipGoogle bool, onlyMissingArtwork bool) (response *http.Response, from string, err error) {
359+
func getImageAlternatives(game *Game, artStyle string, artStyleExtensions []string, skipSteam bool, steamGridDBApiKey string, IGDBSecret string, IGDBClient string, skipGoogle bool, onlyMissingArtwork bool) (response *http.Response, from string, err error) {
333360
from = "steam server"
334361
if !skipSteam {
335362
response, err = tryDownload(fmt.Sprintf(akamaiURLFormat+artStyleExtensions[2], game.ID))
@@ -361,9 +388,9 @@ func getImageAlternatives(game *Game, artStyle string, artStyleExtensions []stri
361388
}
362389

363390
// IGDB has mostly cover styles
364-
if artStyle == "Cover" && IGDBApiKey != "" && url == "" {
391+
if artStyle == "Cover" && IGDBClient != "" && IGDBSecret != "" && url == "" {
365392
from = "IGDB"
366-
url, err = getIGDBImage(game.Name, IGDBApiKey)
393+
url, err = getIGDBImage(game.Name, IGDBSecret, IGDBClient)
367394
if err != nil {
368395
return
369396
}
@@ -389,8 +416,8 @@ func getImageAlternatives(game *Game, artStyle string, artStyleExtensions []stri
389416
// DownloadImage tries to download the game images, saving it in game.ImageBytes. Returns
390417
// flags indicating if the operation succeeded and if the image downloaded was
391418
// from a search.
392-
func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensions []string, skipSteam bool, steamGridDBApiKey string, IGDBApiKey string, skipGoogle bool, onlyMissingArtwork bool) (string, error) {
393-
response, from, err := getImageAlternatives(game, artStyle, artStyleExtensions, skipSteam, steamGridDBApiKey, IGDBApiKey, skipGoogle, onlyMissingArtwork)
419+
func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensions []string, skipSteam bool, steamGridDBApiKey string, IGDBSecret string, IGDBClient string, skipGoogle bool, onlyMissingArtwork bool) (string, error) {
420+
response, from, err := getImageAlternatives(game, artStyle, artStyleExtensions, skipSteam, steamGridDBApiKey, IGDBSecret, IGDBClient, skipGoogle, onlyMissingArtwork)
394421
if response == nil || err != nil {
395422
return "", err
396423
}

steamgrid.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func main() {
2929

3030
func startApplication() {
3131
steamGridDBApiKey := flag.String("steamgriddb", "", "Your personal SteamGridDB api key, get one here: https://www.steamgriddb.com/profile/preferences")
32-
IGDBApiKey := flag.String("igdb", "", "Your personal IGDB api key, get one here: https://api.igdb.com/signup")
32+
IGDBSecret := flag.String("igdbsecret", "", "Your personal IGDB api key, get one here: https://api.igdb.com/signup")
33+
IGDBClient := flag.String("igdbclient", "", "Your personal IGDB api key, get one here: https://api.igdb.com/signup")
3334
steamDir := flag.String("steamdir", "", "Path to your steam installation")
3435
// "alternate" "blurred" "white_logo" "material" "no_logo"
3536
steamGridDBStyles := flag.String("styles", "alternate", "Comma separated list of styles to download from SteamGridDB.\nExample: \"white_logo,material\"")
@@ -200,7 +201,7 @@ func startApplication() {
200201
// Download if missing.
201202
///////////////////////
202203
if game.ImageSource == "" {
203-
from, err := DownloadImage(gridDir, game, artStyle, artStyleExtensions, *skipSteam, *steamGridDBApiKey, *IGDBApiKey, *skipGoogle, *onlyMissingArtwork)
204+
from, err := DownloadImage(gridDir, game, artStyle, artStyleExtensions, *skipSteam, *steamGridDBApiKey, *IGDBSecret, *IGDBClient, *skipGoogle, *onlyMissingArtwork)
204205
if err != nil && err.Error() == "SteamGridDB authorization token is missing or invalid" {
205206
// Wrong api key
206207
*steamGridDBApiKey = ""

0 commit comments

Comments
 (0)