From f5af7614663065efb323f7124c38aea06afc03dc Mon Sep 17 00:00:00 2001 From: Nicolas Rueff Date: Thu, 28 Jan 2021 17:51:31 +0100 Subject: [PATCH] gphotos: new flag --gphotos-include-archived - fixes #4728 New flag --gphotos-include-archived to download and view archived media when needed. --- backend/googlephotos/googlephotos.go | 34 +++++++++++++++++++++++++--- backend/googlephotos/pattern.go | 1 + backend/googlephotos/pattern_test.go | 5 ++++ docs/content/googlephotos.md | 21 +++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/backend/googlephotos/googlephotos.go b/backend/googlephotos/googlephotos.go index 94df3fb33..4dc958593 100644 --- a/backend/googlephotos/googlephotos.go +++ b/backend/googlephotos/googlephotos.go @@ -132,15 +132,33 @@ you want to read the media.`, Default: 2000, Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`, Advanced: true, + }, { + Name: "include_archived", + Default: false, + Help: `Also view and download archived media. + +By default rclone does not request archived media. Thus, when syncing, +archived media is not visible in directory listings or transferred. + +Note that media in albums is always visible and synced, no matter +their archive status. + +With this flag, archived media are always visible in directory +listings and transferred. + +Without this flag, archived media will not be visible in directory +listings and won't be transferred.`, + Advanced: true, }}...), }) } // Options defines the configuration for this backend type Options struct { - ReadOnly bool `config:"read_only"` - ReadSize bool `config:"read_size"` - StartYear int `config:"start_year"` + ReadOnly bool `config:"read_only"` + ReadSize bool `config:"read_size"` + StartYear int `config:"start_year"` + IncludeArchived bool `config:"include_archived"` } // Fs represents a remote storage server @@ -206,6 +224,10 @@ func (f *Fs) startYear() int { return f.opt.StartYear } +func (f *Fs) includeArchived() bool { + return f.opt.IncludeArchived +} + // retryErrorCodes is a slice of error codes that we will retry var retryErrorCodes = []int{ 429, // Too Many Requests. @@ -497,6 +519,12 @@ func (f *Fs) list(ctx context.Context, filter api.SearchFilter, fn listFn) (err } filter.PageSize = listChunks filter.PageToken = "" + if filter.AlbumID == "" { // album ID and filters cannot be set together, else error 400 INVALID_ARGUMENT + if filter.Filters == nil { + filter.Filters = &api.Filters{} + } + filter.Filters.IncludeArchivedMedia = &f.opt.IncludeArchived + } lastID := "" for { var result api.MediaItems diff --git a/backend/googlephotos/pattern.go b/backend/googlephotos/pattern.go index 2cb5a0d3b..a0e5f695e 100644 --- a/backend/googlephotos/pattern.go +++ b/backend/googlephotos/pattern.go @@ -24,6 +24,7 @@ type lister interface { listUploads(ctx context.Context, dir string) (entries fs.DirEntries, err error) dirTime() time.Time startYear() int + includeArchived() bool } // dirPattern describes a single directory pattern diff --git a/backend/googlephotos/pattern_test.go b/backend/googlephotos/pattern_test.go index 8c9d535c6..6d58e5475 100644 --- a/backend/googlephotos/pattern_test.go +++ b/backend/googlephotos/pattern_test.go @@ -64,6 +64,11 @@ func (f *testLister) startYear() int { return 2000 } +// mock includeArchived for testing +func (f *testLister) includeArchived() bool { + return false +} + func TestPatternMatch(t *testing.T) { for testNumber, test := range []struct { // input diff --git a/docs/content/googlephotos.md b/docs/content/googlephotos.md index 1b75fafad..5667841a1 100644 --- a/docs/content/googlephotos.md +++ b/docs/content/googlephotos.md @@ -410,4 +410,25 @@ Year limits the photos to be downloaded to those which were uploaded after the g - Type: int - Default: 2000 +#### --gphotos-include-archived + +Also view and download archived media. + +By default rclone does not request archived media. Thus, when syncing, +archived media is not visible in directory listings or transferred. + +Note that media in albums is always visible and synced, no matter +their archive status. + +With this flag, archived media are always visible in directory +listings and transferred. + +Without this flag, archived media will not be visible in directory +listings and won't be transferred. + +- Config: include_archived +- Env Var: RCLONE_GPHOTOS_INCLUDE_ARCHIVED +- Type: bool +- Default: false + {{< rem autogenerated options stop >}}