Skip to content

Commit

Permalink
Add new AutoArchive option (#450)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Alex1607 authored Aug 21, 2024
1 parent d58d266 commit be10802
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
9 changes: 8 additions & 1 deletion cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion immich/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ 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 {
return
}
}

// 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"`,
Expand Down
23 changes: 12 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit be10802

Please sign in to comment.