Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
--cooldown flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler committed Aug 18, 2023
1 parent 5bd818e commit f26facd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ As a note, the structure of "downloadcmd.timeout" has changed, its now an int vs
},
"outputdir": string,
"quality": int,
"timeout": int
"timeout": int,
"cooldown": int
}
}
```
Expand Down
16 changes: 16 additions & 0 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ var downloadCmd = &cobra.Command{
return fmt.Errorf("total timeout is 0, unable to continue")
}

// optional
cooldown, err := flags.GetInt("cooldown")
if err != nil {
return fmt.Errorf("unknown error when getting '--cooldown'")
}

if cooldown == 0 {
cooldown = viper.GetInt("downloadcmd.cooldown")
}

// optional
ignoreCover, err := flags.GetBool("ignoreCover")
if err != nil {
Expand Down Expand Up @@ -140,6 +150,7 @@ var downloadCmd = &cobra.Command{
}

timeoutTime := time.Now().Add(time.Second * time.Duration(timeout))
cooldownDuration := time.Second * time.Duration(cooldown)

for _, link := range args {
// randomly select a session token to avoid using the same account all the time
Expand Down Expand Up @@ -236,6 +247,10 @@ var downloadCmd = &cobra.Command{
}

fmt.Println("\nDone!")

if link != args[len(args)-1] {
time.Sleep(cooldownDuration)
}
}

return nil
Expand All @@ -252,6 +267,7 @@ func init() {

flags.IntP("quality", "q", 0, "the quality of music to download\n- 0: best quality available\n- 1: 128kbps MP3/AAC\n- 2: 320kbps MP3/AAC\n- 3: 16bit 44.1kHz\n- 4: 24bit ≤96kHz\n- 5: 24bit ≤192kHz")
flags.IntP("timeout", "t", 0, "how long before link search is timed out in seconds")
flags.Int("cooldown", 0, "how long to wait after downloading first url in seconds\n(only matters if you are downloading multiple urls at once)")

flags.BoolP("ignoreCover", "c", false, "ignore cover.jpg when unzipping downloaded music")
flags.BoolP("ignoreSubdirs", "d", false, "ignore subdirectories when unzipping downloaded music")
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var DefaultStructure = map[string]any{
"outputdir": "",
"quality": 0,
"timeout": 120,
"cooldown": 0,
"ignore": map[string]any{
"cover": false,
"subdirs": false,
Expand Down

0 comments on commit f26facd

Please sign in to comment.