feat: playstation-5 provider
This commit is contained in:
parent
cd15123dd3
commit
272ed61d83
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/fmartingr/games-screenshot-manager/pkg/processor"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/minecraft"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/playstation4"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/playstation5"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/retroarch"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/steam"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/xbox_game_bar"
|
||||
|
@ -33,6 +34,7 @@ func Start() {
|
|||
registry := registry.NewProviderRegistry(logger, cache)
|
||||
registry.Register(minecraft.Name, minecraft.NewMinecraftProvider)
|
||||
registry.Register(playstation4.Name, playstation4.NewPlaystation4Provider)
|
||||
registry.Register(playstation5.Name, playstation5.NewPlaystation5Provider)
|
||||
registry.Register(xbox_game_bar.Name, xbox_game_bar.NewXboxGameGarProvider)
|
||||
registry.Register(steam.Name, steam.NewSteamProvider)
|
||||
registry.Register(retroarch.Name, retroarch.NewRetroArchProvider)
|
||||
|
|
|
@ -55,3 +55,21 @@ func NewScreenshotWithoutDestination(path string) Screenshot {
|
|||
Path: path,
|
||||
}
|
||||
}
|
||||
|
||||
func AddScreenshotToGame(platform string, userGames []*Game, gameName string, screenshot Screenshot) []*Game {
|
||||
var foundGame *Game
|
||||
for gameIndex, game := range userGames {
|
||||
if game.Name == gameName {
|
||||
foundGame = game
|
||||
userGames[gameIndex].Screenshots = append(userGames[gameIndex].Screenshots, screenshot)
|
||||
}
|
||||
}
|
||||
|
||||
if foundGame == nil {
|
||||
foundGame := Game{Name: gameName, ID: gameName, Platform: platform, Provider: platform}
|
||||
foundGame.Screenshots = append(foundGame.Screenshots, screenshot)
|
||||
userGames = append(userGames, &foundGame)
|
||||
}
|
||||
|
||||
return userGames
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package playstation4
|
||||
|
||||
import "github.com/fmartingr/games-screenshot-manager/internal/models"
|
||||
|
||||
func addScreenshotToGame(userGames []*models.Game, gameName string, screenshot models.Screenshot) []*models.Game {
|
||||
var foundGame *models.Game
|
||||
for gameIndex, game := range userGames {
|
||||
if game.Name == gameName {
|
||||
foundGame = game
|
||||
userGames[gameIndex].Screenshots = append(userGames[gameIndex].Screenshots, screenshot)
|
||||
}
|
||||
}
|
||||
|
||||
if foundGame == nil {
|
||||
foundGame := models.Game{Name: gameName, ID: gameName, Platform: platformName, Provider: platformName}
|
||||
foundGame.Screenshots = append(foundGame.Screenshots, screenshot)
|
||||
userGames = append(userGames, &foundGame)
|
||||
}
|
||||
|
||||
return userGames
|
||||
}
|
|
@ -5,8 +5,8 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/cozy/goexif2/exif"
|
||||
"github.com/fmartingr/games-screenshot-manager/internal/models"
|
||||
"github.com/rwcarlsen/goexif/exif"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -67,7 +67,7 @@ func (p *Playstation4Provider) FindGames(options models.ProviderOptions) ([]*mod
|
|||
}
|
||||
|
||||
screenshot := models.Screenshot{Path: filePath, DestinationName: destinationName + extension}
|
||||
userGames = addScreenshotToGame(userGames, gameName, screenshot)
|
||||
userGames = models.AddScreenshotToGame(Name, userGames, gameName, screenshot)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package playstation5
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fmartingr/games-screenshot-manager/internal/models"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
Name = "playstation-5"
|
||||
platformName = "PlayStation 5"
|
||||
filenameDatetimeLayout = "20060102150405"
|
||||
)
|
||||
|
||||
type Playstation5Provider struct {
|
||||
logger *logrus.Entry
|
||||
}
|
||||
|
||||
func (p *Playstation5Provider) FindGames(options models.ProviderOptions) ([]*models.Game, error) {
|
||||
var userGames []*models.Game
|
||||
|
||||
err := filepath.Walk(options.InputPath,
|
||||
func(filePath string, info os.FileInfo, err error) error {
|
||||
log := p.logger.WithField("file_path", filePath)
|
||||
if err != nil {
|
||||
log.WithError(err).Error()
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
var destinationName string
|
||||
gameName := filepath.Base(filepath.Dir(filePath))
|
||||
filename := filepath.Base(filePath)
|
||||
extension := filepath.Ext(filepath.Base(filePath))
|
||||
|
||||
// Ignore hidden files
|
||||
if strings.HasPrefix(filename, ".") {
|
||||
return nil
|
||||
}
|
||||
|
||||
if extension == ".jpg" || extension == ".webm" {
|
||||
parts := strings.Split(strings.TrimSuffix(filename, extension), "_")
|
||||
datetime, err := time.Parse(filenameDatetimeLayout, parts[1])
|
||||
if err != nil {
|
||||
log.WithError(err).Warn("error parsing datetime from filename")
|
||||
return nil
|
||||
}
|
||||
|
||||
destinationName = datetime.Format(models.DatetimeFormat)
|
||||
}
|
||||
|
||||
screenshot := models.Screenshot{Path: filePath, DestinationName: destinationName + extension}
|
||||
userGames = models.AddScreenshotToGame(platformName, userGames, gameName, screenshot)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userGames, nil
|
||||
}
|
||||
|
||||
func NewPlaystation5Provider(logger *logrus.Logger, cache models.Cache) models.Provider {
|
||||
return &Playstation5Provider{
|
||||
logger: logger.WithField("from", "provider."+Name),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue