Skip to content

Commit

Permalink
feat: change the ratelimit to thread level.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 22, 2022
1 parent afc5951 commit 56f9ebb
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/sanqiu.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var sanqiuCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Request Per Minute", flags.RateLimit).
Row("Thread Limit (req/min)", flags.RateLimit).
Row("Aliyun RefreshToken", flags.HideSensitive(flags.RefreshToken)).
Row("Telecom Username", flags.HideSensitive(flags.Username)).
Row("Telecom Password", flags.HideSensitive(flags.Password)).
Expand Down Expand Up @@ -68,7 +68,7 @@ func init() {
f.Int64VarP(&flags.InitialBookID, "initial", "i", flags.InitialBookID, "The book id you want to start download")
f.BoolVarP(&flags.Rename, "rename", "r", flags.Rename, "Rename the book file by book id")
f.IntVarP(&flags.Thread, "thread", "t", flags.Thread, "The number of download thead")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes for every thread")

// Drive ISP flags.
f.StringVar(&flags.Driver, "source", flags.Driver, "The source (aliyun, telecom, lanzou) to download book")
Expand Down
4 changes: 2 additions & 2 deletions cmd/sobooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var sobooksCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Request Per Minute", flags.RateLimit).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

// Set the domain for using in the client.Client.
Expand Down Expand Up @@ -70,7 +70,7 @@ func init() {
f.Int64VarP(&flags.InitialBookID, "initial", "i", flags.InitialBookID, "The book id you want to start download")
f.BoolVarP(&flags.Rename, "rename", "r", flags.Rename, "Rename the book file by book id")
f.IntVarP(&flags.Thread, "thread", "t", flags.Thread, "The number of download thead")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes for every thread")

// SoBooks books flags.
f.StringVar(&flags.SoBooksCode, "code", flags.SoBooksCode, "The secret code for SoBooks")
Expand Down
4 changes: 2 additions & 2 deletions cmd/talebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var talebookDownloadCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Request Per Minute", flags.RateLimit).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

// Create the fetcher.
Expand Down Expand Up @@ -124,7 +124,7 @@ func init() {
f.Int64VarP(&flags.InitialBookID, "initial", "i", flags.InitialBookID, "The book id you want to start download")
f.BoolVarP(&flags.Rename, "rename", "r", flags.Rename, "Rename the book file by book id")
f.IntVarP(&flags.Thread, "thread", "t", flags.Thread, "The number of download thead")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes for every thread")

// Mark some flags as required.
_ = talebookDownloadCmd.MarkFlagRequired("website")
Expand Down
4 changes: 2 additions & 2 deletions cmd/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var telegramCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Request Per Minute", flags.RateLimit).
Row("Thread Limit (req/min)", flags.RateLimit).
Print()

// Create the fetcher.
Expand Down Expand Up @@ -76,7 +76,7 @@ func init() {
f.Int64VarP(&flags.InitialBookID, "initial", "i", flags.InitialBookID, "The book id you want to start download")
f.BoolVarP(&flags.Rename, "rename", "r", flags.Rename, "Rename the book file by book id")
f.IntVarP(&flags.Thread, "thread", "t", flags.Thread, "The number of download thead")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes for every thread")

// Bind the required arguments
_ = telegramCmd.MarkFlagRequired("channelID")
Expand Down
4 changes: 2 additions & 2 deletions cmd/tianlang.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var tianlangCmd = &cobra.Command{
Row("Initial ID", flags.InitialBookID).
Row("Rename File", flags.Rename).
Row("Thread", flags.Thread).
Row("Request Per Minute", flags.RateLimit).
Row("Thread Limit (req/min)", flags.RateLimit).
Row("Secret key", flags.TianlangSecretKey).
Row("Aliyun RefreshToken", flags.HideSensitive(flags.RefreshToken)).
Row("Telecom Username", flags.HideSensitive(flags.Username)).
Expand Down Expand Up @@ -69,7 +69,7 @@ func init() {
f.Int64VarP(&flags.InitialBookID, "initial", "i", flags.InitialBookID, "The book id you want to start download")
f.BoolVarP(&flags.Rename, "rename", "r", flags.Rename, "Rename the book file by book id")
f.IntVarP(&flags.Thread, "thread", "t", flags.Thread, "The number of download thead")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes")
f.IntVar(&flags.RateLimit, "ratelimit", flags.RateLimit, "The allowed requests per minutes for every thread")

// Tianlang books flags.
f.StringVar(&flags.TianlangSecretKey, "secretKey", flags.TianlangSecretKey, "The secret key for tianlang")
Expand Down
2 changes: 1 addition & 1 deletion internal/fetcher/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Config struct {
InitialBookID int64 // The book id start to download.
Rename bool // Rename the file by using book ID.
Thread int // The number of download threads.
RateLimit int // Request per minute.
RateLimit int // Request per minute for a thread.
precessFile string // Define the download process.

// The extra configuration for a custom fetcher services.
Expand Down
3 changes: 2 additions & 1 deletion internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func (f *commonFetcher) Download() error {
if f.precessFile == "" {
f.precessFile = defaultProgressFile
}
f.progress, err = progress.NewProgress(f.InitialBookID, size, f.RateLimit, filepath.Join(configPath, f.precessFile))
rate := f.RateLimit * f.Thread
f.progress, err = progress.NewProgress(f.InitialBookID, size, rate, filepath.Join(configPath, f.precessFile))
if err != nil {
return err
}
Expand Down

0 comments on commit 56f9ebb

Please sign in to comment.