diff --git a/lib/app.go b/lib/app.go index 2a2c45a..94171ff 100644 --- a/lib/app.go +++ b/lib/app.go @@ -5,12 +5,14 @@ type App struct { SelectedTidalApiUrl string Verbose bool SpotifyClient *SpotifyClient + ApiInterval int // How many ms to wait between one call to apis and the other } func NewApp() App { return App{ UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", Verbose: false, + ApiInterval: 800, } } diff --git a/lib/download.go b/lib/download.go index 7241d02..73a727a 100644 --- a/lib/download.go +++ b/lib/download.go @@ -95,7 +95,7 @@ func (app *App) DownloadPlaylist(url string, outputFile string, service string, } // Avoid getting rate limited - time.Sleep(800 * time.Millisecond) + time.Sleep(time.Duration(app.ApiInterval) * time.Millisecond) } return nil diff --git a/main.go b/main.go index ee534bb..586b667 100644 --- a/main.go +++ b/main.go @@ -4,13 +4,14 @@ import ( "context" "log" "os" + "strconv" "github.com/Superredstone/spotiflac-cli/lib" "github.com/urfave/cli/v3" ) func main() { - outputFolder := "" + outputFolder := "" service := "" app := lib.NewApp() @@ -39,6 +40,13 @@ func main() { Usage: "set service to tidal/amazon/qobuz (FFmpeg is required for amazon and qobuz)", Destination: &service, }, + &cli.IntFlag{ + Name: "interval", + Aliases: []string{"i"}, + Usage: "interval between api requests in milliseconds", + DefaultText: strconv.Itoa(app.ApiInterval), + Destination: &app.ApiInterval, + }, }, Action: func(ctx context.Context, cmd *cli.Command) error { song_url := cmd.Args().First() @@ -59,9 +67,9 @@ func main() { }, Flags: []cli.Flag{ &cli.BoolFlag{ - Name: "verbose", - Aliases: []string{"v"}, - Usage: "verbose output", + Name: "verbose", + Aliases: []string{"v"}, + Usage: "verbose output", Destination: &app.Verbose, }, },