Skip to content

Commit

Permalink
Add takeout tagging support and update related documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Nov 22, 2024
1 parent 72d0fdb commit 7d0d333
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adapters/googlePhotos/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ func (to *Takeout) handleDir(ctx context.Context, dir string, gOut chan *assets.
a.AddTag(tag)
}
}
if to.flags.TakeoutTag {
a.AddTag(to.flags.TakeoutName)
}
}

select {
Expand Down Expand Up @@ -551,7 +554,7 @@ func (to *Takeout) makeAsset(_ context.Context, dir string, f *assetFile, md *as
title = strings.TrimSuffix(title, titleExt) + fileExt
}
}
a.FromSideCar = a.UseMetadata(md)
a.FromApplication = a.UseMetadata(md)
a.OriginalFileName = title
}
a.FromApplication = a.UseMetadata(md)
Expand Down
5 changes: 5 additions & 0 deletions adapters/googlePhotos/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type ImportFlags struct {
// SessionTag indicates whether to add a session tag to the imported assets.
SessionTag bool
session string // Session tag value

// Add the takeout file name as tag
TakeoutTag bool
TakeoutName string
}

func (o *ImportFlags) AddFromGooglePhotosFlags(cmd *cobra.Command, parent *cobra.Command) {
Expand All @@ -97,6 +101,7 @@ func (o *ImportFlags) AddFromGooglePhotosFlags(cmd *cobra.Command, parent *cobra
cmd.Flags().Var(&o.BannedFiles, "ban-file", "Exclude a file based on a pattern (case-insensitive). Can be specified multiple times.")
cmd.Flags().StringSliceVar(&o.Tags, "tag", nil, "Add tags to the imported assets. Can be specified multiple times. Hierarchy is supported using a / separator (e.g. 'tag1/subtag1')")
cmd.Flags().BoolVar(&o.SessionTag, "session-tag", false, "Tag uploaded photos with a tag \"{immich-go}/YYYY-MM-DD HH-MM-SS\"")
cmd.Flags().BoolVar(&o.TakeoutTag, "takeout-tag", true, "Tag uploaded photos with a tag \"{takeout}/takeout-YYYYMMDDTHHMMSSZ\"")

cliflags.AddInclusionFlags(cmd, &o.InclusionFlags)
exif.AddExifToolFlags(cmd, &o.ExifToolFlags)
Expand Down
20 changes: 20 additions & 0 deletions commands/upload/fromGooglePhotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package upload
import (
"context"
"errors"
"path/filepath"
"strings"

gp "github.com/simulot/immich-go/adapters/googlePhotos"
Expand Down Expand Up @@ -35,6 +36,25 @@ func NewFromGooglePhotosCommand(ctx context.Context, parent *cobra.Command, app
log.Message("No file found matching the pattern: %s", strings.Join(args, ","))
return errors.New("No file found matching the pattern: " + strings.Join(args, ","))
}

if options.TakeoutTag {
gotIt := false
for _, a := range args {
if filepath.Ext(a) == ".zip" {
options.TakeoutName = filepath.Base(a)
if len(options.TakeoutName) > 4+4 {
options.TakeoutName = "{takeout}/" + options.TakeoutName[:len(options.TakeoutName)-4-4]
gotIt = true
break
}
}
}
if !gotIt {
log.Message("Can't set the takeout tag: no .zip file in the arguments")
options.TakeoutTag = false
}
}

upOptions.Filters = append(upOptions.Filters, options.ManageBurst.GroupFilter(), options.ManageRawJPG.GroupFilter(), options.ManageHEICJPG.GroupFilter())

options.SupportedMedia = client.Immich.SupportedMedia()
Expand Down
1 change: 1 addition & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The session tag is useful to identify all photos imported at the same time. It's
**Google photos import tags**

```sh
--takeout-tag Tag uploaded photos with the takeout file name: "{takeout}/takeout-YYYYMMDDTHHMMSSZ"
--session-tag Tag uploaded photos with a tag "{immich-go}/YYYY-MM-DD HH-MM-SS"
--tag strings Add tags to the imported assets. Can be specified multiple times. Hierarchy is supported using a / separator (e.g. 'tag1/subtag1')
```
Expand Down

0 comments on commit 7d0d333

Please sign in to comment.