Skip to content

Commit

Permalink
Merge pull request #192 from matthewkeller36/dedupe-no-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot authored Mar 22, 2024
2 parents 607c29d + 52bb5dd commit c70d665
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cmd/duplicate/duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (

type DuplicateCmd struct {
*cmd.SharedFlags
AssumeYes bool // When true, doesn't ask to the user
DateRange immich.DateRange // Set capture date range
IgnoreTZErrors bool // Enable TZ error tolerance
AssumeYes bool // When true, doesn't ask to the user
DateRange immich.DateRange // Set capture date range
IgnoreTZErrors bool // Enable TZ error tolerance
IgnoreExtension bool // Ignore file extensions when checking for duplicates

assetsByID map[string]*immich.Asset
assetsByBaseAndDate map[duplicateKey][]*immich.Asset
Expand All @@ -32,6 +33,7 @@ type DuplicateCmd struct {
type duplicateKey struct {
Date time.Time
Name string
Type string
}

func NewDuplicateCmd(ctx context.Context, common *cmd.SharedFlags, args []string) (*DuplicateCmd, error) {
Expand All @@ -50,6 +52,7 @@ func NewDuplicateCmd(ctx context.Context, common *cmd.SharedFlags, args []string
cmd.BoolFunc("ignore-tz-errors", "Ignore timezone difference to check duplicates (default: FALSE).", myflag.BoolFlagFn(&app.IgnoreTZErrors, false))
cmd.BoolFunc("yes", "When true, assume Yes to all actions", myflag.BoolFlagFn(&app.AssumeYes, false))
cmd.Var(&app.DateRange, "date", "Process only documents having a capture date in that range.")
cmd.BoolFunc("ignore-extension", "When true, ignores extensions when checking for duplicates (default: FALSE)", myflag.BoolFlagFn(&app.IgnoreExtension, false))
err := cmd.Parse(args)
if err != nil {
return nil, err
Expand Down Expand Up @@ -84,8 +87,12 @@ func DuplicateCommand(ctx context.Context, common *cmd.SharedFlags, args []strin
k := duplicateKey{
Date: d,
Name: strings.ToUpper(a.OriginalFileName + path.Ext(a.OriginalPath)),
Type: a.Type,
}

if app.IgnoreExtension {
k.Name = strings.TrimSuffix(k.Name, path.Ext(a.OriginalPath))
}
l := app.assetsByBaseAndDate[k]
if len(l) > 0 {
dupCount++
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Before deleting the inferior copies, the system get all albums they belong to, a
| `-yes` | Assume Yes to all questions | `FALSE` |
| `-date` | Check only assets have a date of capture in the given range | `1850-01-04,2030-01-01` |
| `-ignore-tz-errors <bool>` | Ignore timezone difference when searching for duplicates | `FALSE` |
| `-ignore-extension` | Ignore filetype extensions when searching for duplicates | `FALSE` |

### Example Usage: clean the `immich` server after having merged a google photo archive and original files

Expand Down

0 comments on commit c70d665

Please sign in to comment.