improved logging in main function
This commit is contained in:
@@ -2,7 +2,7 @@ package steamimmich
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -10,18 +10,19 @@ type Config struct {
|
|||||||
APIKey string
|
APIKey string
|
||||||
UserdataDir string
|
UserdataDir string
|
||||||
DeiveID string
|
DeiveID string
|
||||||
|
Album string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(config Config) {
|
func Run(config Config) {
|
||||||
screenshotFiles, err := listScreenshots(config.UserdataDir)
|
screenshotFiles, err := listScreenshots(config.UserdataDir)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to scan for screenshots")
|
log.Fatalf("Failed to scan for screenshots: %s", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(screenshotFiles) == 0 {
|
if len(screenshotFiles) == 0 {
|
||||||
fmt.Println("No screenshots found.")
|
log.Println("No screenshots found.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,38 +30,37 @@ func Run(config Config) {
|
|||||||
|
|
||||||
for appid, files := range screenshotFiles {
|
for appid, files := range screenshotFiles {
|
||||||
gameName := getGameName(appid, gameNameCache)
|
gameName := getGameName(appid, gameNameCache)
|
||||||
fmt.Printf("AppID: %s → %s\n", appid, gameName)
|
|
||||||
|
|
||||||
assetsInGame := make([]string, 0)
|
assetsInGame := make([]string, 0)
|
||||||
|
|
||||||
for _, f := range files {
|
for _, filepath := range files {
|
||||||
fmt.Printf(" %s\n", f)
|
res, err := uploadToImmich(filepath, appid, config.BaseURL, config.APIKey, config.DeiveID)
|
||||||
|
|
||||||
res, err := uploadToImmich(f, appid, config.BaseURL, config.APIKey, config.DeiveID)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to upload to immich: %s", err)
|
log.Fatalf("Failed to upload to immich: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Done. ID: %s", res.ID)
|
log.Printf("Assest uploaded: %s (%s) %s with ID: %s", gameName, appid, filepath, res.ID)
|
||||||
|
|
||||||
assetsInGame = append(assetsInGame, res.ID)
|
assetsInGame = append(assetsInGame, res.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := setAssetMetadata(assetsInGame, fmt.Sprintf("Game: %s", gameName), config.BaseURL, config.APIKey)
|
err := setAssetMetadata(assetsInGame, fmt.Sprintf("Game: %s", gameName), config.BaseURL, config.APIKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Stopped: %s", err)
|
log.Fatalf("Failed to set asset metadata: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Album != "" {
|
if config.Album != "" {
|
||||||
err = addAssetsToAlbum(assetsInGame, config.Album, config.BaseURL, config.APIKey)
|
err = addAssetsToAlbum(assetsInGame, config.Album, config.BaseURL, config.APIKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Stopped: %s", err)
|
log.Fatalf("Failed to add assets to album: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Added %d assets to album %s", len(assetsInGame), config.Album)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
log.Println("Finished uploading screenshots")
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user