mirror of
https://github.com/fumiama/RVC-Models-Downloader.git
synced 2025-01-19 04:26:43 +09:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8312d008be |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -15,6 +15,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@master
|
uses: actions/setup-go@master
|
||||||
|
with:
|
||||||
|
go-version: 1.22
|
||||||
|
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@master
|
uses: goreleaser/goreleaser-action@master
|
||||||
|
8
main.go
8
main.go
@ -33,6 +33,7 @@ func main() {
|
|||||||
wait := flag.Uint("w", 4, "connection waiting seconds")
|
wait := flag.Uint("w", 4, "connection waiting seconds")
|
||||||
ua := flag.String("ua", defua, "customize user agent")
|
ua := flag.String("ua", defua, "customize user agent")
|
||||||
h := flag.Bool("h", false, "display this help")
|
h := flag.Bool("h", false, "display this help")
|
||||||
|
home := flag.String("H", ".", "download under this path")
|
||||||
flag.BoolVar(¬ui, "notui", false, "use plain text instead of TUI")
|
flag.BoolVar(¬ui, "notui", false, "use plain text instead of TUI")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
@ -44,6 +45,11 @@ func main() {
|
|||||||
fmt.Println(cmdlst.String())
|
fmt.Println(cmdlst.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err := os.MkdirAll(*home, 0755)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorln("mkdirs of path", *home, "err:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
if notui {
|
if notui {
|
||||||
logrus.Infoln("RVC Models Downloader start at", time.Now().Local().Format(time.DateTime+" (MST)"))
|
logrus.Infoln("RVC Models Downloader start at", time.Now().Local().Format(time.DateTime+" (MST)"))
|
||||||
logrus.Infof("operating system: %s, architecture: %s", runtime.GOOS, runtime.GOARCH)
|
logrus.Infof("operating system: %s, architecture: %s", runtime.GOOS, runtime.GOARCH)
|
||||||
@ -89,7 +95,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
err := usercfg.download(args[0], "", *ua, time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
|
err := usercfg.download(args[0], "", *home, *ua, time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
|
||||||
ch <- struct{}{}
|
ch <- struct{}{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorln(err)
|
errorln(err)
|
||||||
|
16
net.go
16
net.go
@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -15,16 +16,16 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *config) download(path, prefix, ua string, waits time.Duration, usecust, usetrs, force bool) error {
|
func (c *config) download(p, prefix, home, ua string, waits time.Duration, usecust, usetrs, 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 := p[:strings.LastIndex(p, "/")+1] + t.Refer
|
||||||
infof("#%s%d refer to target '%s'.", prefix, i+1, refp)
|
infof("#%s%d refer to target '%s'.", prefix, i+1, refp)
|
||||||
refcfg, err := readconfig(refp, usecust)
|
refcfg, err := readconfig(refp, usecust)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", ua, waits, usecust, usetrs, force)
|
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", home, ua, waits, usecust, usetrs, force)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -38,11 +39,12 @@ func (c *config) download(path, prefix, ua string, waits time.Duration, usecust,
|
|||||||
warnf("#%s%d target required Arch: %s but you are %s, skip.", prefix, i+1, t.Arch, runtime.GOARCH)
|
warnf("#%s%d target required Arch: %s but you are %s, skip.", prefix, i+1, t.Arch, runtime.GOARCH)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := os.MkdirAll(t.Folder, 0755)
|
homefolder := path.Join(home, t.Folder)
|
||||||
|
err := os.MkdirAll(homefolder, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("#%s%d make target folder '%s'", prefix, i+1, t.Folder))
|
return errors.Wrap(err, fmt.Sprintf("#%s%d make target folder '%s'", prefix, i+1, homefolder))
|
||||||
}
|
}
|
||||||
infof("#%s%d open target folder '%s'.", prefix, i+1, t.Folder)
|
infof("#%s%d open target folder '%s'.", prefix, i+1, homefolder)
|
||||||
if len(t.Copy) == 0 {
|
if len(t.Copy) == 0 {
|
||||||
warnf("#%s%d empty copy target.", prefix, i+1)
|
warnf("#%s%d empty copy target.", prefix, i+1)
|
||||||
continue
|
continue
|
||||||
@ -57,7 +59,7 @@ func (c *config) download(path, prefix, ua string, waits time.Duration, usecust,
|
|||||||
if sleep > time.Millisecond {
|
if sleep > time.Millisecond {
|
||||||
time.Sleep(sleep)
|
time.Sleep(sleep)
|
||||||
}
|
}
|
||||||
fname := t.Folder + "/" + cp[strings.LastIndex(cp, "/")+1:]
|
fname := path.Join(homefolder, cp[strings.LastIndex(cp, "/")+1:])
|
||||||
if !force {
|
if !force {
|
||||||
if _, err := os.Stat(fname); err == nil || os.IsExist(err) {
|
if _, err := os.Stat(fname); err == nil || os.IsExist(err) {
|
||||||
warnf("#%s%d skip exist file %s", prefix, i+1, fname)
|
warnf("#%s%d skip exist file %s", prefix, i+1, fname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user