Skip to content

Commit

Permalink
Upgrade workers (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan authored Oct 23, 2024
1 parent 63f6c6c commit ffe6047
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var (
path = flag.String("path", "", "Output Path")
output = flag.String("output", "output.ts", "Output File Name")
workers = flag.Int64("workers", 0, "Workers")
workers = flag.Int("workers", 0, "Workers")
)

func usage() {
Expand Down
10 changes: 4 additions & 6 deletions downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultName = "output.ts"

type Downloader struct {
m3u8 string
workers int64
workers workers.Workers
results []errResult
}

Expand All @@ -37,10 +37,8 @@ func NewTask(m3u8 string) *Downloader {
return &Downloader{m3u8: m3u8}
}

func (d *Downloader) SetWorkers(n int64) *Downloader {
if n > 0 {
d.workers = n
}
func (d *Downloader) SetWorkers(n int) *Downloader {
d.workers = workers.Workers(n)
return d
}

Expand Down Expand Up @@ -72,7 +70,7 @@ func (d *Downloader) dlSegments(s []*m3u8.MediaSegment, path, output string) {
pb.Start()
defer pb.Done()

workers.NewWorkers(d.workers).Run(context.Background(), workers.SliceJob(s, func(_ int, segment *m3u8.MediaSegment) {
d.workers.Run(context.Background(), workers.SliceJob(s, func(_ int, segment *m3u8.MediaSegment) {
defer pb.Add(1)
d.dlSegment(segment, path, output)
}))
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/sunshineplan/gohttp v1.0.10
github.com/sunshineplan/useragent v1.0.1
github.com/sunshineplan/utils v0.1.73
github.com/sunshineplan/workers v1.0.1
github.com/sunshineplan/workers v1.0.3
)

require (
Expand All @@ -21,7 +21,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ github.com/sunshineplan/useragent v1.0.1 h1:0x4MIlcOQ2awc1XKUwEJr+fDcJXpm/bw1H7H
github.com/sunshineplan/useragent v1.0.1/go.mod h1:u+8L7UYZqQI4iMgbMdhE1GldRohbrlQGZr5lzegPRLE=
github.com/sunshineplan/utils v0.1.73 h1:Kvi45QYzdvNqQKON5Q67M7U/35+RrOnX7K8sbZtHsgI=
github.com/sunshineplan/utils v0.1.73/go.mod h1:61jHA9jn2CVlZzt9LbPz+MpOEiR6Jy5SNHHEcc/KQNk=
github.com/sunshineplan/workers v1.0.1 h1:vhDo4ZaerVu0QM1udRmWpvHY2U61/vTLRVwmKcYOxNw=
github.com/sunshineplan/workers v1.0.1/go.mod h1:EjLgk5vd/2ig6vdWDAZy/fpkzdSm8IVDsARPQVSyQy0=
github.com/sunshineplan/workers v1.0.3 h1:9NSB3nm9yxZFT/ZU4DaOXdWJ56Y2WXh238apdZUdA44=
github.com/sunshineplan/workers v1.0.3/go.mod h1:wUlVWxvfwTiuULOw4atF17bgeL30gIMI6gE050reEVw=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down

0 comments on commit ffe6047

Please sign in to comment.