-
Notifications
You must be signed in to change notification settings - Fork 88
/
neogeo.go
59 lines (53 loc) · 1.17 KB
/
neogeo.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
package ds
import (
"fmt"
"path/filepath"
"github.com/sselph/scraper/gdb"
)
// NeoGeo is a data source using GDB for Daphne games.
type NeoGeo struct {
HM *HashMap
}
// GetID implements DS.
func (n *NeoGeo) GetID(p string) (string, error) {
if filepath.Ext(p) == ".7z" {
p = p[:len(p)-3] + ".zip"
}
if filepath.Ext(p) != ".zip" {
return "", ErrNotFound
}
gameID := filepath.Base(p)
id, ok := n.HM.ID(gameID)
if !ok {
return "", ErrNotFound
}
return id, nil
}
// GetName implements DS.
func (n *NeoGeo) GetName(p string) string {
gameID := filepath.Base(p)
name, ok := n.HM.Name(gameID)
if !ok {
return ""
}
return name
}
// GetGame implements DS.
func (n *NeoGeo) 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 := ParseGDBGame(game, resp.ImageURL)
ret.ID = id
ret.Images[ImgTitle] = ret.Images[ImgBoxart]
ret.Thumbs[ImgTitle] = ret.Thumbs[ImgBoxart]
ret.Images[ImgMarquee] = ret.Images[ImgLogo]
ret.Thumbs[ImgMarquee] = ret.Thumbs[ImgLogo]
return ret, nil
}