Exemplo n.º 1
0
func (g *GDB) 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
}
Exemplo n.º 2
0
func GetGDBGame(r *ROM, ds *datasources) (*GameXML, error) {
	id, ok := ds.HM.GetID(r.Hash)
	if !ok {
		return nil, NotFound
	}
	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]
	imageURL := resp.ImageURL
	imgPriority := strings.Split(*gdbImg, ",")
	var iURL, tURL string
Loop:
	for _, i := range imgPriority {
		switch i {
		case "s":
			if len(game.Screenshot) != 0 {
				iURL = game.Screenshot[0].Original.URL
				tURL = game.Screenshot[0].Thumb
				break Loop
			}
		case "b":
			front := GetFront(game)
			if front != nil {
				iURL = front.URL
				tURL = front.Thumb
				break Loop
			}
		case "f":
			if len(game.FanArt) != 0 {
				iURL = game.FanArt[0].Original.URL
				tURL = game.FanArt[0].Thumb
				break Loop
			}
		case "a":
			if len(game.Banner) != 0 {
				iURL = game.Banner[0].URL
				tURL = game.Banner[0].URL
				break Loop
			}
		case "l":
			if len(game.ClearLogo) != 0 {
				iURL = game.ClearLogo[0].URL
				tURL = game.ClearLogo[0].URL
				break Loop
			}
		}
	}
	iPath, tPath := GetImgPaths(r)

	if iURL != "" && *downloadImages {
		switch {
		case !*thumbOnly && !*noThumb:
			err = getImage(imageURL+iURL, iPath)
			if err != nil {
				return nil, err
			}
			err = getImage(imageURL+tURL, tPath)
			if err != nil {
				return nil, err
			}
		case *thumbOnly && !*noThumb:
			err = getImage(imageURL+tURL, tPath)
			if err != nil {
				return nil, err
			}
			iPath = tPath
		case !*thumbOnly && *noThumb:
			err = getImage(imageURL+iURL, iPath)
			if err != nil {
				return nil, err
			}
			tPath = ""
		case *thumbOnly && *noThumb:
			err = getImage(imageURL+tURL, tPath)
			if err != nil {
				return nil, err
			}
			iPath = tPath
			tPath = ""
		}
	} else {
		iPath = ""
		tPath = ""
	}

	var genre string
	if len(game.Genres) >= 1 {
		genre = game.Genres[0]
	}
	gxml := &GameXML{
		Path:        fixPath(*romPath + "/" + strings.TrimPrefix(r.Path, *romDir)),
		ID:          game.ID,
		GameTitle:   game.GameTitle,
		Overview:    game.Overview,
		Rating:      game.Rating / 10.0,
		ReleaseDate: ToXMLDate(game.ReleaseDate),
		Developer:   game.Developer,
		Publisher:   game.Publisher,
		Genre:       genre,
		Source:      "theGamesDB.net",
	}
	if iPath != "" {
		gxml.Image = fixPath(*imagePath + "/" + strings.TrimPrefix(iPath, *imageDir))
	}
	if tPath != "" {
		gxml.Thumb = fixPath(*imagePath + "/" + strings.TrimPrefix(tPath, *imageDir))
	}
	if *useNoIntroName {
		n, ok := ds.HM.GetName(r.Hash)
		if ok {
			gxml.GameTitle = n
		}
	}
	p, err := strconv.ParseInt(strings.TrimRight(game.Players, "+"), 10, 32)
	if err == nil {
		gxml.Players = p
	}
	return gxml, nil
}