Base PlayStation 4 support

This only add support for those screenshots that contain
a datetime in their name, skipping otherwise.

Closes #7
This commit is contained in:
Felipe M 2021-01-05 23:17:36 +01:00
parent 1a29fb3c78
commit f5991dfd21
3 changed files with 74 additions and 1 deletions

View File

@ -11,6 +11,7 @@ Use the appropriate ID with the `-provider` flag. [See examples below](#Usage)
| Steam | `steam` | Linux, macOS, Windows | Yes [Example](https://steamcdn-a.akamaihd.net/steam/apps/377840/header.jpg) |
| Minecraft | `minecraft` | Linux, Linux Flatpak, macOS, Windows | No |
| Nintendo Switch | `nintendo-switch` | Requires `-input-path` | No |
| PlayStation 4 | `playstation-4` | Requires `-input-path` | No |
## How it works

View File

@ -13,11 +13,12 @@ import (
"github.com/fmartingr/games-screenshot-mananger/pkg/helpers"
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/minecraft"
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/nintendo_switch"
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/playstation4"
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/steam"
"github.com/gosimple/slug"
)
var allowedProviders = [...]string{"steam", "minecraft", "nintendo-switch"}
var allowedProviders = [...]string{"steam", "minecraft", "nintendo-switch", "playstation-4"}
const defaultOutputPath string = "./Output"
@ -53,6 +54,8 @@ func getGamesFromProvider(provider string, inputPath string, downloadCovers bool
games = append(games, minecraft.GetGames()...)
case "nintendo-switch":
games = append(games, nintendo_switch.GetGames(inputPath)...)
case "playstation-4":
games = append(games, playstation4.GetGames(inputPath)...)
}
return games
}

View File

@ -0,0 +1,69 @@
package playstation4
import (
"log"
"os"
"path/filepath"
"time"
"github.com/fmartingr/games-screenshot-mananger/pkg/games"
)
const providerName = "playstation-4"
const platformName = "PlayStation 4"
func addScreenshotToGame(userGames []games.Game, gameName string, screenshot games.Screenshot) []games.Game {
var foundGame games.Game
for gameIndex, game := range userGames {
if game.Name == gameName {
foundGame = game
userGames[gameIndex].Screenshots = append(userGames[gameIndex].Screenshots, screenshot)
}
}
// Game not found
if foundGame.Name == "" {
foundGame := games.Game{Name: gameName, ID: gameName, Platform: platformName, Provider: providerName}
foundGame.Screenshots = append(foundGame.Screenshots, screenshot)
userGames = append(userGames, foundGame)
}
return userGames
}
func GetGames(inputPath string) []games.Game {
var userGames []games.Game
err := filepath.Walk(inputPath,
func(filePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
gameName := filepath.Base(filepath.Dir(filePath))
fileName := filepath.Base(filePath)
extension := filepath.Ext(filepath.Base(filePath))
layout := "20060102150405"
if len(fileName) >= len(layout)+len(extension) {
destinationName, err := time.Parse(layout, fileName[len(fileName)-len(extension)-len(layout):len(fileName)-len(extension)])
if err == nil {
screenshot := games.Screenshot{Path: filePath, DestinationName: destinationName.Format(games.DatetimeFormat) + extension}
userGames = addScreenshotToGame(userGames, gameName, screenshot)
} else {
log.Printf("File doesn't follow datetime convention: %s. (%s) skipping...", filePath, err)
}
} else {
log.Printf("File doesn't follow datetime convention: %s, skipping...", filePath)
}
}
return nil
})
if err != nil {
log.Panic(err)
}
return userGames
}