From 5c05d602d27baef1053aed9c6bc3ff5d127fc68c Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Wed, 23 Oct 2024 13:11:07 +0800 Subject: [PATCH] Upgrade workers --- cmd/main.go | 2 +- downloader.go | 10 ++++------ go.mod | 4 ++-- go.sum | 8 ++++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 71aa781..d6eb492 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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() { diff --git a/downloader.go b/downloader.go index bec6ec9..682336d 100644 --- a/downloader.go +++ b/downloader.go @@ -20,7 +20,7 @@ const defaultName = "output.ts" type Downloader struct { m3u8 string - workers int64 + workers workers.Workers results []errResult } @@ -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 } @@ -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) })) diff --git a/go.mod b/go.mod index 621247c..dd3eff8 100644 --- a/go.mod +++ b/go.mod @@ -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 ( @@ -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 ) diff --git a/go.sum b/go.sum index 29ba64f..21d1944 100644 --- a/go.sum +++ b/go.sum @@ -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=