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:
parent
1a29fb3c78
commit
f5991dfd21
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue