1
mirror of https://github.com/rclone/rclone synced 2024-10-04 11:17:51 +02:00

gphotos: new flag --gphotos-include-archived - fixes #4728

New flag --gphotos-include-archived to download and view archived media when needed.
This commit is contained in:
Nicolas Rueff 2021-01-28 17:51:31 +01:00 committed by GitHub
parent 06f1c0c61c
commit f5af761466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 3 deletions

View File

@ -132,6 +132,23 @@ you want to read the media.`,
Default: 2000, Default: 2000,
Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`, Help: `Year limits the photos to be downloaded to those which are uploaded after the given year`,
Advanced: true, 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,
}}...), }}...),
}) })
} }
@ -141,6 +158,7 @@ type Options struct {
ReadOnly bool `config:"read_only"` ReadOnly bool `config:"read_only"`
ReadSize bool `config:"read_size"` ReadSize bool `config:"read_size"`
StartYear int `config:"start_year"` StartYear int `config:"start_year"`
IncludeArchived bool `config:"include_archived"`
} }
// Fs represents a remote storage server // Fs represents a remote storage server
@ -206,6 +224,10 @@ func (f *Fs) startYear() int {
return f.opt.StartYear return f.opt.StartYear
} }
func (f *Fs) includeArchived() bool {
return f.opt.IncludeArchived
}
// retryErrorCodes is a slice of error codes that we will retry // retryErrorCodes is a slice of error codes that we will retry
var retryErrorCodes = []int{ var retryErrorCodes = []int{
429, // Too Many Requests. 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.PageSize = listChunks
filter.PageToken = "" 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 := "" lastID := ""
for { for {
var result api.MediaItems var result api.MediaItems

View File

@ -24,6 +24,7 @@ type lister interface {
listUploads(ctx context.Context, dir string) (entries fs.DirEntries, err error) listUploads(ctx context.Context, dir string) (entries fs.DirEntries, err error)
dirTime() time.Time dirTime() time.Time
startYear() int startYear() int
includeArchived() bool
} }
// dirPattern describes a single directory pattern // dirPattern describes a single directory pattern

View File

@ -64,6 +64,11 @@ func (f *testLister) startYear() int {
return 2000 return 2000
} }
// mock includeArchived for testing
func (f *testLister) includeArchived() bool {
return false
}
func TestPatternMatch(t *testing.T) { func TestPatternMatch(t *testing.T) {
for testNumber, test := range []struct { for testNumber, test := range []struct {
// input // input

View File

@ -410,4 +410,25 @@ Year limits the photos to be downloaded to those which were uploaded after the g
- Type: int - Type: int
- Default: 2000 - 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 >}} {{< rem autogenerated options stop >}}