forked from sselph/scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scumm.go
95 lines (86 loc) · 2.23 KB
/
scumm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package ds
import (
"fmt"
"path/filepath"
"strconv"
"strings"
"github.com/sselph/scraper/gdb"
)
// ScummVM is a data source using GDB for ScummVM games.
type ScummVM struct {
HM *HashMap
}
func (s *ScummVM) GetID(p string) (string, error) {
if filepath.Ext(p) != ".svm" {
return "", NotFoundErr
}
b := filepath.Base(p)
svm := b[:len(b)-len(filepath.Ext(b))]
gameID := strings.Split(svm, "-")[0]
id, ok := s.HM.GetID(gameID)
if !ok {
return "", NotFoundErr
}
return id, nil
}
func (s *ScummVM) GetName(p string) string {
b := filepath.Base(p)
svm := b[:len(b)-len(filepath.Ext(b))]
gameID := strings.Split(svm, "-")[0]
n, ok := s.HM.GetName(gameID)
if !ok {
return ""
}
return n
}
func (s *ScummVM) GetGame(id string) (*Game, error) {
req := gdb.GGReq{ID: id}
resp, err := gdb.GetGame(req)
if err != nil {
return nil, err
}
if len(resp.Game) == 0 {
return nil, fmt.Errorf("game with id (%s) not found", id)
}
game := resp.Game[0]
ret := NewGame()
if len(game.Screenshot) != 0 {
ret.Images[IMG_SCREEN] = resp.ImageURL + game.Screenshot[0].Original.URL
ret.Thumbs[IMG_SCREEN] = resp.ImageURL + game.Screenshot[0].Thumb
}
front := getFront(game)
if front != nil {
ret.Images[IMG_BOXART] = resp.ImageURL + front.URL
ret.Thumbs[IMG_BOXART] = resp.ImageURL + front.Thumb
}
if len(game.FanArt) != 0 {
ret.Images[IMG_FANART] = resp.ImageURL + game.FanArt[0].Original.URL
ret.Thumbs[IMG_FANART] = resp.ImageURL + game.FanArt[0].Thumb
}
if len(game.Banner) != 0 {
ret.Images[IMG_BANNER] = resp.ImageURL + game.Banner[0].URL
ret.Thumbs[IMG_BANNER] = resp.ImageURL + game.Banner[0].URL
}
if len(game.ClearLogo) != 0 {
ret.Images[IMG_LOGO] = resp.ImageURL + game.ClearLogo[0].URL
ret.Thumbs[IMG_LOGO] = resp.ImageURL + game.ClearLogo[0].URL
}
var genre string
if len(game.Genres) >= 1 {
genre = game.Genres[0]
}
ret.ID = id
ret.GameTitle = game.GameTitle
ret.Overview = game.Overview
ret.Rating = game.Rating / 10.0
ret.ReleaseDate = toXMLDate(game.ReleaseDate)
ret.Developer = game.Developer
ret.Publisher = game.Publisher
ret.Genre = genre
ret.Source = "theGamesDB.net"
p, err := strconv.ParseInt(strings.TrimRight(game.Players, "+"), 10, 32)
if err == nil {
ret.Players = p
}
return ret, nil
}