diff --git a/go.mod b/go.mod index ffa2b83..19c78ac 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/fmartingr/games-screenshot-mananger go 1.15 + +require github.com/gosimple/slug v1.9.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d4f1369 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs= +github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg= +github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ= +github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q= diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 5daa859..7dbee49 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -14,6 +14,7 @@ import ( "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/steam" + "github.com/gosimple/slug" ) var allowedProviders = [...]string{"steam", "minecraft", "nintendo-switch"} @@ -51,7 +52,7 @@ func getGamesFromProvider(provider string, inputPath string, downloadCovers bool case "minecraft": games = append(games, minecraft.GetGames()...) case "nintendo-switch": - games = append(games, nintendo_switch.GetGames(inputPath)...) + games = append(games, nintendo_switch.GetGames(inputPath, downloadCovers)...) } return games } @@ -68,7 +69,12 @@ func processGames(games []games.Game, outputPath string, dryRun bool, downloadCo // Check if folder exists if _, err := os.Stat(destinationPath); os.IsNotExist(err) && !dryRun { - os.MkdirAll(destinationPath, 0711) + mkdirErr := os.MkdirAll(destinationPath, 0711) + if mkdirErr != nil { + log.Printf("[ERROR] Couldn't create directory with name %s, falling back to %s", game.Name, slug.Make(game.Name)) + destinationPath = filepath.Join(helpers.ExpandUser(outputPath), game.Platform, slug.Make(game.Name)) + os.MkdirAll(destinationPath, 0711) + } } if downloadCovers && !dryRun {