Allow setting custom screenshot filename on struct

This commit is contained in:
Felipe Martin 2020-11-12 20:46:05 +01:00
parent 0e4bfcdb91
commit bc26e6e787
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
2 changed files with 22 additions and 8 deletions

View File

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

View File

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