From bc26e6e787971761be0827323fcce76546525031 Mon Sep 17 00:00:00 2001 From: Felipe Martin Date: Thu, 12 Nov 2020 20:46:05 +0100 Subject: [PATCH] Allow setting custom screenshot filename on struct --- pkg/cli/cli.go | 9 ++------- pkg/games/structs.go | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 3d13677..1be86c9 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -57,14 +57,9 @@ func processGames(games []games.Game, outputPath string, dryRun bool) { os.MkdirAll(destinationPath, 0711) } - log.Printf("=> Proceesing screenshots for %s", game.Name) + log.Printf("=> Proceesing screenshots for %s %s", game.Name, game.Notes) for _, screenshot := range game.Screenshots { - fileStat, statErr := os.Stat(screenshot.Path) - if statErr != nil { - log.Fatal(statErr) - } - - destinationPath := path.Join(destinationPath, fileStat.ModTime().Format("2006-01-02_15-04-05")+path.Ext(screenshot.Path)) + destinationPath := path.Join(destinationPath, screenshot.GetDestinationName()) if _, err := os.Stat(destinationPath); !os.IsNotExist(err) { sourceMd5, err := helpers.Md5File(screenshot.Path) diff --git a/pkg/games/structs.go b/pkg/games/structs.go index d63ee80..52337de 100644 --- a/pkg/games/structs.go +++ b/pkg/games/structs.go @@ -1,13 +1,32 @@ package games +import ( + "log" + "os" + "path" +) + type Game struct { ID uint64 Name string Platform string Provider string Screenshots []Screenshot + Notes string } type Screenshot struct { - Path string + Path string + DestinationName string +} + +func (screenshot Screenshot) GetDestinationName() string { + if screenshot.DestinationName != "" { + return screenshot.DestinationName + } + fileStat, statErr := os.Stat(screenshot.Path) + if statErr != nil { + log.Fatal(statErr) + } + return fileStat.ModTime().Format("2006-01-02_15-04-05") + path.Ext(screenshot.Path) }