@@ -66,43 +66,43 @@ func getGoogleImage(gameName string, artStyleExtensions []string) (string, error
66
66
}
67
67
68
68
// https://www.steamgriddb.com/api/v2
69
- type SteamGridDBResponse struct {
69
+ type steamGridDBResponse struct {
70
70
Success bool
71
- Data []struct {
72
- Id int
73
- Score int
74
- Style string
75
- Url string
76
- Thumb string
77
- Tags []string
71
+ Data []struct {
72
+ ID int
73
+ Score int
74
+ Style string
75
+ URL string
76
+ Thumb string
77
+ Tags []string
78
78
Author struct {
79
- Name string
79
+ Name string
80
80
Steam64 string
81
- Avatar string
81
+ Avatar string
82
82
}
83
83
}
84
84
}
85
85
86
- type SteamGridDBSearchResponse struct {
86
+ type steamGridDBSearchResponse struct {
87
87
Success bool
88
- Data []struct {
89
- Id int
90
- Name string
91
- Types []string
88
+ Data []struct {
89
+ ID int
90
+ Name string
91
+ Types []string
92
92
Verified bool
93
93
}
94
94
}
95
95
96
96
// Search SteamGridDB for cover image
97
- const SteamGridDBBaseURL = "https://www.steamgriddb.com/api/v2"
97
+ const steamGridDBBaseURL = "https://www.steamgriddb.com/api/v2"
98
98
99
- func SteamGridDBGetRequest (url string , steamGridDBApiKey string ) ([]byte , error ) {
99
+ func steamGridDBGetRequest (url string , steamGridDBApiKey string ) ([]byte , error ) {
100
100
client := & http.Client {}
101
101
req , err := http .NewRequest ("GET" , url , nil )
102
102
if err != nil {
103
103
return nil , err
104
104
}
105
- req .Header .Add ("Authorization" , "Bearer " + steamGridDBApiKey )
105
+ req .Header .Add ("Authorization" , "Bearer " + steamGridDBApiKey )
106
106
107
107
response , err := client .Do (req )
108
108
if err != nil {
@@ -130,67 +130,66 @@ func getSteamGridDBImage(game *Game, artStyleExtensions []string, steamGridDBApi
130
130
// Try for HQ, then for LQ
131
131
// It's possible to request both dimensions in one go but that'll give us scrambled results with no indicator which result has which size.
132
132
for i := 0 ; i < 3 ; i += 2 {
133
- filter := steamGridFilter + "&dimensions=" + artStyleExtensions [3 + i ] + "x" + artStyleExtensions [4 + i ]
133
+ filter := steamGridFilter + "&dimensions=" + artStyleExtensions [3 + i ] + "x" + artStyleExtensions [4 + i ]
134
134
135
135
// Try with game.ID which is probably steams appID
136
- var baseUrl string
136
+ var baseURL string
137
137
switch artStyleExtensions [1 ] {
138
138
case ".banner" :
139
- baseUrl = SteamGridDBBaseURL + "/grids"
139
+ baseURL = steamGridDBBaseURL + "/grids"
140
140
case ".cover" :
141
- baseUrl = SteamGridDBBaseURL + "/grids"
141
+ baseURL = steamGridDBBaseURL + "/grids"
142
142
case ".hero" :
143
- baseUrl = SteamGridDBBaseURL + "/heroes"
143
+ baseURL = steamGridDBBaseURL + "/heroes"
144
144
case ".logo" :
145
- baseUrl = SteamGridDBBaseURL + "/logos"
145
+ baseURL = steamGridDBBaseURL + "/logos"
146
146
}
147
- url := baseUrl + "/steam/" + game .ID + filter
147
+ url := baseURL + "/steam/" + game .ID + filter
148
148
149
- var jsonResponse SteamGridDBResponse
149
+ var jsonResponse steamGridDBResponse
150
150
var responseBytes []byte
151
151
var err error
152
152
153
153
// Skip requests with appID for custom games
154
154
if ! game .Custom {
155
- responseBytes , err = SteamGridDBGetRequest (url , steamGridDBApiKey )
155
+ responseBytes , err = steamGridDBGetRequest (url , steamGridDBApiKey )
156
156
} else {
157
157
err = errors .New ("404" )
158
158
}
159
159
160
160
// Authorization token is missing or invalid
161
- if err != nil && err .Error () == "401" {
161
+ if err != nil && err .Error () == "401" {
162
162
return "" , errors .New ("SteamGridDB authorization token is missing or invalid" )
163
- // Could not find game with that id
163
+ // Could not find game with that id
164
164
} else if err != nil && err .Error () == "404" {
165
165
// Try searching for the name…
166
- url = SteamGridDBBaseURL + "/search/autocomplete/" + game .Name + filter
167
- responseBytes , err = SteamGridDBGetRequest (url , steamGridDBApiKey )
166
+ url = steamGridDBBaseURL + "/search/autocomplete/" + game .Name + filter
167
+ responseBytes , err = steamGridDBGetRequest (url , steamGridDBApiKey )
168
168
if err != nil && err .Error () == "401" {
169
169
return "" , errors .New ("SteamGridDB authorization token is missing or invalid" )
170
170
} else if err != nil {
171
171
return "" , err
172
172
}
173
173
174
- var jsonSearchResponse SteamGridDBSearchResponse
174
+ var jsonSearchResponse steamGridDBSearchResponse
175
175
err = json .Unmarshal (responseBytes , & jsonSearchResponse )
176
176
if err != nil {
177
177
return "" , errors .New ("Best search match doesn't has a requested type or style" )
178
178
}
179
179
180
- SteamGridDBGameId := - 1
180
+ SteamGridDBGameID := - 1
181
181
if jsonSearchResponse .Success && len (jsonSearchResponse .Data ) >= 1 {
182
182
// First match should be the best one
183
- SteamGridDBGameId = jsonSearchResponse .Data [0 ].Id
183
+ SteamGridDBGameID = jsonSearchResponse .Data [0 ].ID
184
184
}
185
185
186
- if SteamGridDBGameId == - 1 {
186
+ if SteamGridDBGameID == - 1 {
187
187
return "" , nil
188
188
}
189
189
190
-
191
190
// …and get the url of the top result.
192
- url = baseUrl + "/game/" + strconv .Itoa (SteamGridDBGameId ) + filter
193
- responseBytes , err = SteamGridDBGetRequest (url , steamGridDBApiKey )
191
+ url = baseURL + "/game/" + strconv .Itoa (SteamGridDBGameID ) + filter
192
+ responseBytes , err = steamGridDBGetRequest (url , steamGridDBApiKey )
194
193
if err != nil {
195
194
return "" , err
196
195
}
@@ -204,31 +203,31 @@ func getSteamGridDBImage(game *Game, artStyleExtensions []string, steamGridDBApi
204
203
}
205
204
206
205
if jsonResponse .Success && len (jsonResponse .Data ) >= 1 {
207
- return jsonResponse .Data [0 ].Url , nil
206
+ return jsonResponse .Data [0 ].URL , nil
208
207
}
209
208
}
210
209
211
210
return "" , nil
212
211
}
213
212
214
- const IGDBImageURL = "https://images.igdb.com/igdb/image/upload/t_720p/%v.jpg"
215
- const IGDBGameURL = "https://api-v3.igdb.com/games"
216
- const IGDBCoverURL = "https://api-v3.igdb.com/covers"
217
- const IGDBGameBody = `fields name,cover; search "%v";`
218
- const IGDBCoverBody = `fields image_id; where id = %v;`
213
+ const igdbImageURL = "https://images.igdb.com/igdb/image/upload/t_720p/%v.jpg"
214
+ const igdbGameURL = "https://api-v3.igdb.com/games"
215
+ const igdbCoverURL = "https://api-v3.igdb.com/covers"
216
+ const igdbGameBody = `fields name,cover; search "%v";`
217
+ const igdbCoverBody = `fields image_id; where id = %v;`
219
218
220
- type IGDBGame struct {
221
- Id int
219
+ type igdbGame struct {
220
+ ID int
222
221
Cover int
223
- Name string
222
+ Name string
224
223
}
225
224
226
- type IGDBCover struct {
227
- Id int
228
- Image_id string
225
+ type igdbCover struct {
226
+ ID int
227
+ Image_ID string
229
228
}
230
229
231
- func IGDBPostRequest (url string , body string , IGDBApiKey string ) ([]byte , error ) {
230
+ func igdbPostRequest (url string , body string , IGDBApiKey string ) ([]byte , error ) {
232
231
client := & http.Client {}
233
232
req , err := http .NewRequest ("POST" , url , strings .NewReader (body ))
234
233
req .Header .Add ("user-key" , IGDBApiKey )
@@ -252,12 +251,12 @@ func IGDBPostRequest(url string, body string, IGDBApiKey string) ([]byte, error)
252
251
}
253
252
254
253
func getIGDBImage (gameName string , IGDBApiKey string ) (string , error ) {
255
- responseBytes , err := IGDBPostRequest ( IGDBGameURL , fmt .Sprintf (IGDBGameBody , gameName ), IGDBApiKey )
254
+ responseBytes , err := igdbPostRequest ( igdbGameURL , fmt .Sprintf (igdbGameBody , gameName ), IGDBApiKey )
256
255
if err != nil {
257
256
return "" , err
258
257
}
259
258
260
- var jsonGameResponse []IGDBGame
259
+ var jsonGameResponse []igdbGame
261
260
err = json .Unmarshal (responseBytes , & jsonGameResponse )
262
261
if err != nil {
263
262
return "" , nil
@@ -267,19 +266,19 @@ func getIGDBImage(gameName string, IGDBApiKey string) (string, error) {
267
266
return "" , nil
268
267
}
269
268
270
- responseBytes , err = IGDBPostRequest ( IGDBCoverURL , fmt .Sprintf (IGDBCoverBody , jsonGameResponse [0 ].Cover ), IGDBApiKey )
269
+ responseBytes , err = igdbPostRequest ( igdbCoverURL , fmt .Sprintf (igdbCoverBody , jsonGameResponse [0 ].Cover ), IGDBApiKey )
271
270
if err != nil {
272
271
return "" , err
273
272
}
274
273
275
- var jsonCoverResponse []IGDBCover
274
+ var jsonCoverResponse []igdbCover
276
275
err = json .Unmarshal (responseBytes , & jsonCoverResponse )
277
276
if err != nil {
278
277
return "" , nil
279
278
}
280
279
281
280
if len (jsonCoverResponse ) >= 1 {
282
- return fmt .Sprintf (IGDBImageURL , jsonCoverResponse [0 ].Image_id ), nil
281
+ return fmt .Sprintf (igdbImageURL , jsonCoverResponse [0 ].Image_ID ), nil
283
282
}
284
283
285
284
return "" , nil
@@ -317,12 +316,12 @@ const steamCdnURLFormat = `cdn.akamai.steamstatic.com/steam/apps/%v/`
317
316
func getImageAlternatives (game * Game , artStyle string , artStyleExtensions []string , skipSteam bool , steamGridDBApiKey string , steamGridFilter string , IGDBApiKey string , skipGoogle bool ) (response * http.Response , from string , err error ) {
318
317
from = "steam server"
319
318
if ! skipSteam {
320
- response , err = tryDownload (fmt .Sprintf (akamaiURLFormat + artStyleExtensions [2 ], game .ID ))
319
+ response , err = tryDownload (fmt .Sprintf (akamaiURLFormat + artStyleExtensions [2 ], game .ID ))
321
320
if err == nil && response != nil {
322
321
return
323
322
}
324
323
325
- response , err = tryDownload (fmt .Sprintf (steamCdnURLFormat + artStyleExtensions [2 ], game .ID ))
324
+ response , err = tryDownload (fmt .Sprintf (steamCdnURLFormat + artStyleExtensions [2 ], game .ID ))
326
325
if err == nil && response != nil {
327
326
return
328
327
}
@@ -400,13 +399,13 @@ func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensio
400
399
return "" , err
401
400
}
402
401
imageSize := image .Bounds ().Max
403
- if ( artStyle == "Banner" && imageSize .X < imageSize .Y ) {
402
+ if artStyle == "Banner" && imageSize .X < imageSize .Y {
404
403
return "" , nil
405
- } else if ( artStyle == "Cover" && imageSize .X > imageSize .Y ) {
404
+ } else if artStyle == "Cover" && imageSize .X > imageSize .Y {
406
405
return "" , nil
407
406
}
408
407
409
- game .ImageSource = from ;
408
+ game .ImageSource = from
410
409
411
410
game .CleanImageBytes = imageBytes
412
411
return from , nil
@@ -415,8 +414,8 @@ func DownloadImage(gridDir string, game *Game, artStyle string, artStyleExtensio
415
414
// Get game name from SteamDB as last resort.
416
415
const steamDBFormat = `https://steamdb.info/app/%v`
417
416
418
- func GetGameName ( gameId string ) string {
419
- response , err := tryDownload (fmt .Sprintf (steamDBFormat , gameId ))
417
+ func getGameName ( gameID string ) string {
418
+ response , err := tryDownload (fmt .Sprintf (steamDBFormat , gameID ))
420
419
if err != nil || response == nil {
421
420
return ""
422
421
}
@@ -430,7 +429,7 @@ func GetGameName(gameId string) string {
430
429
match := pattern .FindStringSubmatch (string (page ))
431
430
if match == nil || len (match ) == 0 {
432
431
return ""
433
- } else {
434
- return match [1 ]
435
432
}
433
+
434
+ return match [1 ]
436
435
}
0 commit comments