From be108028b88bb922dcf4f4f284ed84a658c63d38 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 21 Aug 2024 18:24:26 +0200 Subject: [PATCH] Add new AutoArchive option (#450) * Add new AutoArchive option to autoarchive images which are also archived in google images * Update documentation to add new option * Update logic for autoarchive * Remove dead code Resolve #448 --- cmd/upload/upload.go | 9 ++++++++- immich/asset.go | 5 ++++- readme.md | 23 ++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/cmd/upload/upload.go b/cmd/upload/upload.go index f446ca65..b2ae29fc 100644 --- a/cmd/upload/upload.go +++ b/cmd/upload/upload.go @@ -57,6 +57,7 @@ type UpCmd struct { StackJpgRaws bool // Stack jpg/raw (Default: TRUE) StackBurst bool // Stack burst (Default: TRUE) DiscardArchived bool // Don't import archived assets (Default: FALSE) + AutoArchive bool // Automatically archive photos that are also archived in google photos (Default: TRUE) WhenNoDate string // When the date can't be determined use the FILE's date or NOW (default: FILE) ForceUploadWhenNoJSON bool // Some takeout don't supplies all JSON. When true, files are uploaded without any additional metadata BannedFiles namematcher.List // List of banned file name patterns @@ -161,6 +162,10 @@ func newCommand(ctx context.Context, common *cmd.SharedFlags, args []string, fsO "discard-archived", " google-photos only: Do not import archived photos (default FALSE)", myflag.BoolFlagFn(&app.DiscardArchived, false)) + cmd.BoolFunc( + "auto-archive", + " google-photos only: Automatically archive photos that are also archived in google photos (default FALSE)", myflag.BoolFlagFn(&app.AutoArchive, true)) + cmd.BoolFunc( "create-stacks", "Stack jpg/raw or bursts (default FALSE)", myflag.BoolFlagFn(&app.CreateStacks, false)) @@ -618,10 +623,12 @@ func (app *UpCmd) ExploreLocalFolder(ctx context.Context, fsyss []fs.FS) (browse // UploadAsset upload the asset on the server // Add the assets into listed albums // return ID of the asset - func (app *UpCmd) UploadAsset(ctx context.Context, a *browser.LocalAssetFile) (string, error) { var resp, liveResp immich.AssetResponse var err error + if !app.AutoArchive && a.Archived { + a.Archived = false + } if !app.DryRun { if a.LivePhoto != nil { liveResp, err = app.Immich.AssetUpload(ctx, a.LivePhoto) diff --git a/immich/asset.go b/immich/asset.go index c5801733..21090f5f 100644 --- a/immich/asset.go +++ b/immich/asset.go @@ -116,6 +116,10 @@ func (ic *ImmichClient) AssetUpload(ctx context.Context, la *browser.LocalAssetF if err != nil { return } + err := m.WriteField("isArchived", myBool(la.Archived).String()) + if err != nil { + return + } if la.LivePhotoID != "" { err = m.WriteField("livePhotoVideoId", la.LivePhotoID) if err != nil { @@ -123,7 +127,6 @@ func (ic *ImmichClient) AssetUpload(ctx context.Context, la *browser.LocalAssetF } } - // m.WriteField("isArchived", myBool(la.Archived).String()) // Not supported by the api h := textproto.MIMEHeader{} h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, diff --git a/readme.md b/readme.md index 1a83d568..707ddc08 100644 --- a/readme.md +++ b/readme.md @@ -141,17 +141,18 @@ immich-go -server=xxxxx -key=yyyyy upload -exclude-files=backup/ -exclude-files= ### Google photos options: Specialized options for Google Photos management: -| **Parameter** | **Description** | **Default value** | -| ---------------------------------- | -------------------------------------------------------------------------------- | ----------------- | -| `-google-photos` | import from a Google Photos structured archive, recreating corresponding albums. | | -| `-from-album="GP Album"` | Create the album in `immich` and import album's assets. | | -| `-create-albums` | Controls creation of Google Photos albums in Immich. | `TRUE` | -| `-keep-untitled-albums` | Untitled albums are imported into `immich` with the name of the folder as title. | `FALSE` | -| `-use-album-folder-as-name` | Use the folder's name instead of the album title. | `FALSE` | -| `-keep-partner` | Specifies inclusion or exclusion of partner-taken photos. | `TRUE` | -| `-partner-album="partner's album"` | import assets from partner into given album. | | -| `-discard-archived` | don't import archived assets. | `FALSE` | -| `-upload-when-missing-JSON` | Upload photos not associated with a JSON metadata file | `FALSE` | +| **Parameter** | **Description** | **Default value** | +|-------------------------------------|----------------------------------------------------------------------------------|-------------------| +| `-google-photos` | import from a Google Photos structured archive, recreating corresponding albums. | | +| `-from-album="GP Album"` | Create the album in `immich` and import album's assets. | | +| `-create-albums` | Controls creation of Google Photos albums in Immich. | `TRUE` | +| `-keep-untitled-albums` | Untitled albums are imported into `immich` with the name of the folder as title. | `FALSE` | +| `-use-album-folder-as-name` | Use the folder's name instead of the album title. | `FALSE` | +| `-keep-partner` | Specifies inclusion or exclusion of partner-taken photos. | `TRUE` | +| `-partner-album="partner's album"` | import assets from partner into given album. | | +| `-discard-archived` | don't import archived assets. | `FALSE` | +| `-auto-archive` | Automatically archive photos that are also archived in google photos | `TRUE` | +| `-upload-when-missing-JSON` | Upload photos not associated with a JSON metadata file | `FALSE` | Read [here](docs/google-takeout.md) to understand how Google Photos takeout isn't easy to handle.