feat: added playstation 5 provider (#16)

* replaced goefix with a fork

* feat: playstation-5 provider

* Updated README
This commit is contained in:
Felipe Martin 2023-03-05 20:37:38 +01:00 committed by GitHub
parent d8469d4eea
commit 2debcd8468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 36 deletions

View File

@ -8,28 +8,33 @@ A simple tool to collect and sort games screenshots from different platforms.
Use the appropriate ID with the `-provider` flag. [See examples below](#Usage)
| Name | ID | Linux | Windows | macOS | Covers | Notes |
| --------------- | ----------------- | ----- | ------- | ----- | ------ | --------------------------------------------------- |
| Minecraft | `minecraft` | Yes | Yes | Yes | No |
| PlayStation 4 | `playstation-4` | - | - | - | No | Requires `-input-path` pointing to PS4 folder |
| RetroArch | `retroarch` | - | - | - | Yes | Requires `-input-path` pointing to Playlists folder |
| Steam | `steam` | Yes | Yes | Yes | Yes |
| Xbox Game Bar | `xbox-game-bar` | - | - | - | No | Requires `-input-path` pointing to the folder holding the captures |
| Name | ID | Linux | Windows | macOS | Covers | Notes |
| ------------- | --------------- | ----- | ------- | ----- | ------ | ------------------------------------------------------------------ |
| Minecraft | `minecraft` | Yes | Yes | Yes | No |
| PlayStation 4 | `playstation-4` | - | - | - | No | Requires `-input-path` pointing to `PS4` folder |
| PlayStation 5 | `playstation-5` | - | - | - | No | Requires `-input-path` pointing to `PS5` folder |
| RetroArch | `retroarch` | - | - | - | Yes | Requires `-input-path` pointing to Playlists folder |
| Steam | `steam` | Yes | Yes | Yes | Yes |
| Xbox Game Bar | `xbox-game-bar` | - | - | - | No | Requires `-input-path` pointing to the folder holding the captures |
## Requirements
- [exiftool](https://exiftool.org/) to parse EXIF data from files.
- [exiftool](https://exiftool.org/) to parse EXIF data from files. (Using [cozy/goexif2 library](https://github.com/cozy/goexif2))
## How it works
Each provider has it's own way of finding the screenshots, but ideally the screenshots folder for games are known to us users so we only need to traverse them and find image files except for installations that may vary (like Retroarch) or systems outside of the PC ecosystem (Playstation, Nintendo Switch).
Each provider has it's own way of finding the screenshots, but ideally the screenshots folder for games are known to us users so we only need to traverse them and find image files except for installations that may vary (like Retroarch) or systems outside of the PC ecosystem (Playstation).
In some cases to have all the information for a particular provider we need to retrieve more data from the internet, for example the Steam game list to associate names to the IDs or in Nintendo Switch's case a community provided list to associate the internal ID with the Game's name.
In some cases to have all the information for a particular provider we need to retrieve more data from the internet, for example the Steam game list to associate names to the IDs ~~or in Nintendo Switch's case a community provided list to associate the internal ID with the Game's name~~.
For more details, you can check out [the source code for all providers](https://github.com/fmartingr/games-screenshot-manager/tree/master/pkg/providers)
Optionally a cover image for a game can be downloaded and placed under a `.cover` file in the game path. For this to work use the `-download-cover` flag. Check above for provider support for this feature.
## Nintendo Switch notice
This project initially started as a Nintendo Switch helper to import and properly organize screenshots, but Nintendo improved this over the years and now we can use Android File Transfer to easily get the screenshots from a Nintendo Switch with the proper game name as folder name. For more information [read this issue](https://github.com/RenanGreca/Switch-Screenshots/issues/46)
## Installation
```

2
go.mod
View File

@ -4,8 +4,8 @@ go 1.19
require (
github.com/barasher/go-exiftool v1.8.0
github.com/cozy/goexif2 v1.2.0
github.com/gosimple/slug v1.13.1
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
github.com/sirupsen/logrus v1.9.0
)

4
go.sum
View File

@ -1,5 +1,7 @@
github.com/barasher/go-exiftool v1.8.0 h1:u8bEi1mhLtpVC5aG/ZJlRS/r+SkK+rcgbZQwcKUb424=
github.com/barasher/go-exiftool v1.8.0/go.mod h1:F9s/a3uHSM8YniVfwF+sbQUtP8Gmh9nyzigNF+8vsWo=
github.com/cozy/goexif2 v1.2.0 h1:cBPS+7niEtwehOYBcDBSyvo+x6LPcaFVvm7Nsu6fxeM=
github.com/cozy/goexif2 v1.2.0/go.mod h1:mBLIra4pwtUmAakLxbwF8v94QD5PdluAW1i7pisBk3w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -9,8 +11,6 @@ github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK3dcGsnCnO41eRBOnY12zwkn5qVwgc=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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),
}
}