diff --git a/README.md b/README.md index e2d6467..ec2b133 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ env CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" github.com/RoyXiang/putc * `REMOTE_SRC` and `REMOTE_DEST` (default: `src:` and `dest:`) * If something like `rclone move putio: drive:Downloads/` is wanted, set `REMOTE_SRC` to `putio:` and `REMOTE_DEST` to `drive:Downloads/` + * `MAX_TRANSFERS` (default: the maximum number of simultaneous tasks allowed by your Put.io subscription) * `DELAY_BEFORE_TRANSFER` (default: `0s`) * Delay before moving files to the destination so that you can manipulate files on Put.io first * `EXCLUDE_FILETYPES` (e.g. `exe,log`) diff --git a/putio/main.go b/putio/main.go index 8f0d709..ee711a3 100644 --- a/putio/main.go +++ b/putio/main.go @@ -9,7 +9,7 @@ import ( "golang.org/x/oauth2" ) -func New(token string) *Put { +func New(token string, maxTransfers int) *Put { ctx := context.Background() tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) oauthClient := oauth2.NewClient(ctx, tokenSource) @@ -19,10 +19,13 @@ func New(token string) *Put { if err != nil || !info.AccountActive { log.Fatal("You must have an active Put.io subscription") } + if maxTransfers <= 0 || maxTransfers > info.SimultaneousDownloadLimit { + maxTransfers = info.SimultaneousDownloadLimit + } result := &Put{ Client: client, - MaxTransfers: info.SimultaneousDownloadLimit, + MaxTransfers: maxTransfers, DefaultDownloadFolder: "", } if settings, err := client.Account.Settings(ctx); err == nil && settings.DefaultDownloadFolder != RootFolderId { diff --git a/rclone/main.go b/rclone/main.go index faf993d..87ddbce 100644 --- a/rclone/main.go +++ b/rclone/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "strconv" "strings" "sync" "time" @@ -43,9 +44,6 @@ var ( ) func init() { - accessToken := parseRCloneConfig() - Put = putio.New(accessToken) - rcGlobalConfig := fs.GetConfig(nil) argMultiThreadCutoff = int64(rcGlobalConfig.MultiThreadCutoff) argLargeFileTransfers = rcGlobalConfig.Transfers @@ -69,9 +67,14 @@ func init() { } osEnv := os.Environ() + maxTransfers := 0 for _, env := range osEnv { pair := strings.SplitN(env, "=", 2) switch pair[0] { + case "MAX_TRANSFERS": + if maxTransfersInEnv, err := strconv.Atoi(pair[1]); err == nil { + maxTransfers = maxTransfersInEnv + } case "RENAMING_STYLE": styleInEnv := strings.ToLower(pair[1]) switch styleInEnv { @@ -101,6 +104,9 @@ func init() { } } + accessToken := parseRCloneConfig() + Put = putio.New(accessToken, maxTransfers) + taskChan = make(chan *putio.FileInfo, 1) transferQueue = make(chan struct{}, argMaxTransfers) }