Skip to content

Commit

Permalink
Add support for .daphne folder.
Browse files Browse the repository at this point in the history
Updates #93
  • Loading branch information
sselph committed Jun 5, 2016
1 parent 155c3eb commit d4b5bfa
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
89 changes: 89 additions & 0 deletions ds/daphne.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package ds

import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/sselph/scraper/gdb"
)

// Daphne is a data source using GDB for Daphne games.
type Daphne struct {
HM *HashMap
}

func (d *Daphne) GetID(p string) (string, error) {
if filepath.Ext(p) != ".daphne" {
return "", NotFoundErr
}
gameID := filepath.Base(p)
id, ok := d.HM.GetID(gameID)
if !ok {
return "", NotFoundErr
}
return id, nil
}

func (d *Daphne) GetName(p string) string {
gameID := filepath.Base(p)
n, ok := d.HM.GetName(gameID)
if !ok {
return ""
}
return n
}

func (d *Daphne) 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
}
6 changes: 5 additions & 1 deletion scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ func CrawlROMs(gl *rom.GameListXML, sources []ds.DS, xmlOpts *rom.XMLOpts, gameO
walker.SkipDir()
continue
}
if filepath.Ext(f) == ".daphne" {
walker.SkipDir()
}
if _, ok := existing[f]; !*refreshOut && ok {
log.Printf("INFO: Skipping %s, already in gamelist.", f)
continue
Expand All @@ -379,7 +382,7 @@ func CrawlROMs(gl *rom.GameListXML, sources []ds.DS, xmlOpts *rom.XMLOpts, gameO
continue
}
_, ok := bins[f]
if !ok && (rh.KnownExt(r.Ext) || r.Ext == ".svm" || isExtra) {
if !ok && (rh.KnownExt(r.Ext) || r.Ext == ".svm" || isExtra || r.Ext == ".daphne") {
roms <- r
}
}
Expand Down Expand Up @@ -596,6 +599,7 @@ func main() {
consoleSources = append(consoleSources, o)
}
consoleSources = append(consoleSources, &ds.ScummVM{HM: hm})
consoleSources = append(consoleSources, &ds.Daphne{HM: hm})
if !*scrapeAll {
var sources []ds.DS
if *mame {
Expand Down

0 comments on commit d4b5bfa

Please sign in to comment.