Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust code to new ScreenScraper API #265

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 27 additions & 43 deletions ds/ss.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,64 +230,38 @@ func (s *SS) GetGame(ctx context.Context, path string) (*Game, error) {

ret := NewGame()
var screen, box, cart, wheel Image
if game.Media.Screenshot != "" {
screen = HTTPImageSS{game.Media.Screenshot, s.Limit}
ret.Images[ImgScreen] = screen
ret.Thumbs[ImgScreen] = screen
}
if imgURL, ok := game.Media.Box2D(regions); ok {
ret.Images[ImgBoxart] = HTTPImageSS{imgURL, s.Limit}
ret.Thumbs[ImgBoxart] = HTTPImageSS{imgURL, s.Limit}
}
if imgURL, ok := game.Media.Box3D(regions); ok {
box = HTTPImageSS{imgURL, s.Limit}
ret.Images[ImgBoxart3D] = box
ret.Thumbs[ImgBoxart3D] = box
}
if imgURL, ok := game.Media.Wheel(regions); ok {
wheel = HTTPImageSS{imgURL, s.Limit}
ret.Images[ImgMarquee] = wheel
ret.Thumbs[ImgMarquee] = wheel
}
if imgURL, ok := game.Media.Support2D(regions); ok {
cart = HTTPImageSS{imgURL, s.Limit}
ret.Images[ImgCart] = cart
ret.Thumbs[ImgCart] = cart
}
if imgURL, ok := game.Media.SupportLabel(regions); ok {
label := HTTPImageSS{imgURL, s.Limit}
ret.Images[ImgCartLabel] = label
ret.Thumbs[ImgCartLabel] = label
}
if vidURL := game.Media.Video; vidURL != "" {
if u, err := url.Parse(vidURL); err == nil {
ext := u.Query().Get("mediaformat")
ret.Videos[VidStandard] = HTTPVideoSS{vidURL, "." + ext, s.Limit}
}
screen = addImageToGame(ret, game, ss.Screenshot, ImgScreen, regions, s)
addImageToGame(ret, game, ss.Box2D, ImgBoxart, regions, s)
box = addImageToGame(ret, game, ss.Box3D, ImgBoxart3D, regions, s)
wheel = addImageToGame(ret, game, ss.Wheel, ImgMarquee, regions, s)
cart = addImageToGame(ret, game, ss.Support2D, ImgCart, regions, s)
addImageToGame(ret, game, ss.SupportLabel, ImgCartLabel, regions, s)
if vidURL, format, ok := game.MediaWithFormat(ss.Video, regions); ok {
ret.Videos[VidStandard] = HTTPVideoSS{vidURL, "." + format, s.Limit}
}
ret.Images[ImgMix3] = MixImage{StandardThree(screen, box, wheel)}
ret.Thumbs[ImgMix3] = MixImage{StandardThree(screen, box, wheel)}
ret.Images[ImgMix4] = MixImage{StandardFour(screen, box, cart, wheel)}
ret.Thumbs[ImgMix4] = MixImage{StandardFour(screen, box, cart, wheel)}
ret.ID = game.ID
ret.Source = "screenscraper.fr"
ret.GameTitle = game.Name
ret.GameTitle, _ = game.Name(s.Region)
ret.Overview, _ = game.Desc(s.Lang)
game.Rating = strings.TrimSuffix(game.Rating, "/20")
if r, err := strconv.ParseFloat(game.Rating, 64); err == nil {
game.Rating.Text = strings.TrimSuffix(game.Rating.Text, "/20")
if r, err := strconv.ParseFloat(game.Rating.Text, 64); err == nil {
ret.Rating = r / 20.0
}
ret.Developer = game.Developer
ret.Publisher = game.Publisher
ret.Developer = game.Developer.Text
ret.Publisher = game.Publisher.Text
ret.Genre, _ = game.Genre(s.Lang)
if r, ok := game.Date(s.Region); ok {
ret.ReleaseDate = ssXMLDate(r)
}
if strings.ContainsRune(game.Players, '-') {
x := strings.Split(game.Players, "-")
game.Players = x[len(x)-1]
if strings.ContainsRune(game.Players.Text, '-') {
x := strings.Split(game.Players.Text, "-")
game.Players.Text = x[len(x)-1]
}
p, err := strconv.ParseInt(strings.TrimRight(game.Players, "+"), 10, 32)
p, err := strconv.ParseInt(strings.TrimRight(game.Players.Text, "+"), 10, 32)
if err == nil {
ret.Players = p
}
Expand All @@ -297,6 +271,16 @@ func (s *SS) GetGame(ctx context.Context, path string) (*Game, error) {
return ret, nil
}

func addImageToGame(ret *Game, game ss.Game, mediaType ss.MediaType, imgType ImgType, regions []string, s *SS) HTTPImageSS {
var gameImage HTTPImageSS
if imgURL, ok := game.Media(mediaType, regions); ok {
gameImage = HTTPImageSS{imgURL, s.Limit}
ret.Images[imgType] = gameImage
ret.Thumbs[imgType] = gameImage
}
return gameImage
}

// ssImgURL parses the URL and adds the maxwidth.
func ssImgURL(img string, width int, height int) string {
if width <= 0 && height <= 0 {
Expand Down
66 changes: 27 additions & 39 deletions ds/ss_mame.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ds

import (
"context"
"net/url"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -54,55 +53,34 @@ func (s *SSMAME) GetGame(ctx context.Context, path string) (*Game, error) {
regions = append(regions, s.Region...)

ret := NewGame()
if game.Media.Screenshot != "" {
ret.Images[ImgScreen] = HTTPImageSS{game.Media.Screenshot, s.Limit}
ret.Thumbs[ImgScreen] = HTTPImageSS{game.Media.Screenshot, s.Limit}
}
if game.Media.ScreenMarquee != "" {
ret.Images[ImgTitle] = HTTPImageSS{game.Media.ScreenMarquee, s.Limit}
ret.Thumbs[ImgTitle] = HTTPImageSS{game.Media.ScreenMarquee, s.Limit}
}
if game.Media.Marquee != "" {
ret.Images[ImgMarquee] = HTTPImageSS{game.Media.Marquee, s.Limit}
ret.Thumbs[ImgMarquee] = HTTPImageSS{game.Media.Marquee, s.Limit}
}
if imgURL, ok := game.Media.Box2D(regions); ok {
ret.Images[ImgBoxart] = HTTPImageSS{imgURL, s.Limit}
ret.Thumbs[ImgBoxart] = HTTPImageSS{imgURL, s.Limit}
}
if imgURL, ok := game.Media.Box3D(regions); ok {
ret.Images[ImgBoxart3D] = HTTPImageSS{imgURL, s.Limit}
ret.Thumbs[ImgBoxart3D] = HTTPImageSS{imgURL, s.Limit}
}
if imgURL, ok := game.Media.Flyer(regions); ok {
ret.Images[ImgFlyer] = HTTPImageSS{imgURL, s.Limit}
ret.Thumbs[ImgFlyer] = HTTPImageSS{imgURL, s.Limit}
}
if vidURL := game.Media.Video; vidURL != "" {
if u, err := url.Parse(vidURL); err == nil {
ext := u.Query().Get("mediaformat")
ret.Videos[VidStandard] = HTTPVideoSS{vidURL, "." + ext, s.Limit}
}
addImageToMameGame(ret, game, ss.Screenshot, ImgScreen, regions, s)
addImageToMameGame(ret, game, ss.ScreenMarquee, ImgTitle, regions, s)
addImageToMameGame(ret, game, ss.Marquee, ImgMarquee, regions, s)
addImageToMameGame(ret, game, ss.Box2D, ImgBoxart, regions, s)
addImageToMameGame(ret, game, ss.Box3D, ImgBoxart3D, regions, s)
addImageToMameGame(ret, game, ss.Flyer, ImgFlyer, regions, s)
if vidURL, format, ok := game.MediaWithFormat(ss.Video, regions); ok {
ret.Videos[VidStandard] = HTTPVideoSS{vidURL, "." + format, s.Limit}
}
ret.ID = game.ID
ret.Source = "screenscraper.fr"
ret.GameTitle = game.Name
ret.GameTitle, _ = game.Name(s.Region)
ret.Overview, _ = game.Desc(s.Lang)
game.Rating = strings.TrimSuffix(game.Rating, "/20")
if r, err := strconv.ParseFloat(game.Rating, 64); err == nil {
game.Rating.Text = strings.TrimSuffix(game.Rating.Text, "/20")
if r, err := strconv.ParseFloat(game.Rating.Text, 64); err == nil {
ret.Rating = r / 20.0
}
ret.Developer = game.Developer
ret.Publisher = game.Publisher
ret.Developer = game.Developer.Text
ret.Publisher = game.Publisher.Text
ret.Genre, _ = game.Genre(s.Lang)
if r, ok := game.Date(s.Region); ok {
ret.ReleaseDate = ssXMLDate(r)
}
if strings.ContainsRune(game.Players, '-') {
x := strings.Split(game.Players, "-")
game.Players = x[len(x)-1]
if strings.ContainsRune(game.Players.Text, '-') {
x := strings.Split(game.Players.Text, "-")
game.Players.Text = x[len(x)-1]
}
p, err := strconv.ParseInt(strings.TrimRight(game.Players, "+"), 10, 32)
p, err := strconv.ParseInt(strings.TrimRight(game.Players.Text, "+"), 10, 32)
if err == nil {
ret.Players = p
}
Expand All @@ -111,3 +89,13 @@ func (s *SSMAME) GetGame(ctx context.Context, path string) (*Game, error) {
}
return ret, nil
}

func addImageToMameGame(ret *Game, game ss.Game, mediaType ss.MediaType, imgType ImgType, regions []string, s *SSMAME) HTTPImageSS {
var gameImage HTTPImageSS
if imgURL, ok := game.Media(mediaType, regions); ok {
gameImage = HTTPImageSS{imgURL, s.Limit}
ret.Images[imgType] = gameImage
ret.Thumbs[imgType] = gameImage
}
return gameImage
}
Loading