71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package steamimmich
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
type Config struct {
|
|
BaseURL string
|
|
APIKey string
|
|
UserdataDir string
|
|
DeiveID string
|
|
Album string
|
|
}
|
|
|
|
func Run(config Config) {
|
|
screenshotFiles, err := listScreenshots(config.UserdataDir)
|
|
|
|
if err != nil {
|
|
log.Fatalf("Failed to scan for screenshots: %s", err)
|
|
return
|
|
}
|
|
|
|
if len(screenshotFiles) == 0 {
|
|
log.Println("No screenshots found.")
|
|
return
|
|
}
|
|
|
|
immichClient := newImmichHttpClient(config.APIKey)
|
|
|
|
gameNameCache := make(map[string]string)
|
|
|
|
for appid, files := range screenshotFiles {
|
|
gameName := getGameName(appid, gameNameCache)
|
|
assetsInGame := make([]string, 0)
|
|
|
|
for _, filepath := range files {
|
|
res, err := uploadToImmich(filepath, appid, config.BaseURL, config.DeiveID, &immichClient)
|
|
|
|
if err != nil {
|
|
log.Fatalf("Failed to upload to immich: %s", err)
|
|
return
|
|
}
|
|
|
|
log.Printf("Assest uploaded: %s (%s) %s with ID: %s", gameName, appid, filepath, res.ID)
|
|
|
|
return
|
|
|
|
assetsInGame = append(assetsInGame, res.ID)
|
|
}
|
|
|
|
err := setAssetMetadata(assetsInGame, fmt.Sprintf("Game: %s", gameName), config.BaseURL, immichClient)
|
|
if err != nil {
|
|
log.Fatalf("Failed to set asset metadata: %s", err)
|
|
return
|
|
}
|
|
|
|
if config.Album != "" {
|
|
err = addAssetsToAlbum(assetsInGame, config.Album, config.BaseURL, immichClient)
|
|
if err != nil {
|
|
log.Fatalf("Failed to add assets to album: %s", err)
|
|
return
|
|
}
|
|
|
|
log.Printf("Added %d assets to album %s", len(assetsInGame), config.Album)
|
|
}
|
|
}
|
|
|
|
log.Println("Finished uploading screenshots")
|
|
}
|