1
0
mirror of https://github.com/fumiama/RVC-Models-Downloader.git synced 2024-11-17 13:47:11 +09:00

feat: add cmdline option -f

This commit is contained in:
源文雨 2024-04-18 18:42:23 +09:00
parent da4eaf8c66
commit fed1f04b53
3 changed files with 13 additions and 5 deletions

View File

@ -52,6 +52,7 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
-c use custom yaml instruction -c use custom yaml instruction
-dns string -dns string
custom dns.yaml custom dns.yaml
-f force download even file exists
-notrs -notrs
use standard TLS client use standard TLS client
'target/to/download' 'target/to/download'

14
cfg.go
View File

@ -65,7 +65,7 @@ type targets struct {
Arch string `yaml:"Arch"` Arch string `yaml:"Arch"`
} }
func (c *config) download(path, prefix string, usecust bool) error { func (c *config) download(path, prefix string, usecust, force bool) error {
for i, t := range c.Targets { for i, t := range c.Targets {
if t.Refer != "" { if t.Refer != "" {
refp := path[:strings.LastIndex(path, "/")+1] + t.Refer refp := path[:strings.LastIndex(path, "/")+1] + t.Refer
@ -74,7 +74,7 @@ func (c *config) download(path, prefix string, usecust bool) error {
if err != nil { if err != nil {
return err return err
} }
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", usecust) err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", usecust, force)
if err != nil { if err != nil {
return err return err
} }
@ -116,6 +116,13 @@ func (c *config) download(path, prefix string, usecust bool) error {
if sleep > time.Millisecond { if sleep > time.Millisecond {
time.Sleep(sleep) time.Sleep(sleep)
} }
fname := t.Folder + "/" + cp
if !force {
if _, err := os.Stat(fname); err == nil || os.IsExist(err) {
logrus.Warnf("#%s%d skip exist file %s", prefix, i+1, fname)
return
}
}
req, err := http.NewRequest("GET", c.BaseURL+"/"+cp, nil) req, err := http.NewRequest("GET", c.BaseURL+"/"+cp, nil)
if err != nil { if err != nil {
logrus.Errorf("#%s%d new request to %s err: %v", prefix, i+1, cp, err) logrus.Errorf("#%s%d new request to %s err: %v", prefix, i+1, cp, err)
@ -134,14 +141,13 @@ func (c *config) download(path, prefix string, usecust bool) error {
logrus.Errorf("#%s%d get %s err: %v", prefix, i+1, req.URL, err) logrus.Errorf("#%s%d get %s err: %v", prefix, i+1, req.URL, err)
return return
} }
fname := t.Folder + "/" + cp
f, err := os.Create(fname) f, err := os.Create(fname)
if err != nil { if err != nil {
logrus.Errorf("#%s%d create file %s err: %v", prefix, i+1, fname, err) logrus.Errorf("#%s%d create file %s err: %v", prefix, i+1, fname, err)
return return
} }
logrus.Infof("#%s%d writing file %s", prefix, i+1, fname)
defer f.Close() defer f.Close()
logrus.Infof("#%s%d writing file %s", prefix, i+1, fname)
pm := newmeter(fmt.Sprintf("#%s%d", prefix, i+1), fname, int(resp.ContentLength)) pm := newmeter(fmt.Sprintf("#%s%d", prefix, i+1), fname, int(resp.ContentLength))
_, err = io.Copy(io.MultiWriter(f, &pm), resp.Body) _, err = io.Copy(io.MultiWriter(f, &pm), resp.Body)
if err != nil { if err != nil {

View File

@ -26,6 +26,7 @@ func main() {
ntrs := flag.Bool("notrs", false, "use standard TLS client") ntrs := flag.Bool("notrs", false, "use standard TLS client")
dnsf := flag.String("dns", "", "custom dns.yaml") dnsf := flag.String("dns", "", "custom dns.yaml")
cust := flag.Bool("c", false, "use custom yaml instruction") cust := flag.Bool("c", false, "use custom yaml instruction")
force := flag.Bool("f", false, "force download even file exists")
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
if len(args) != 1 { if len(args) != 1 {
@ -64,7 +65,7 @@ func main() {
logrus.Errorln(err) logrus.Errorln(err)
return return
} }
err = usercfg.download(args[0], "", *cust) err = usercfg.download(args[0], "", *cust, *force)
if err != nil { if err != nil {
logrus.Errorln(err) logrus.Errorln(err)
return return