1
0
mirror of https://github.com/fumiama/RVC-Models-Downloader.git synced 2024-09-29 14:26:25 +09:00

feat: customizable ua (#2)

This commit is contained in:
源文雨 2024-05-18 20:29:23 +09:00
parent e6b2709814
commit 2b6ca35a6d
7 changed files with 21 additions and 6 deletions

View File

@ -96,6 +96,8 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
use standard TLS client
-notui
use plain text instead of TUI
-ua string
customize user agent
-w uint
connection waiting seconds (default 4)
'target/to/download'

View File

@ -98,6 +98,8 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
use standard TLS client
-notui
use plain text instead of TUI
-ua string
customize user agent
-w uint
connection waiting seconds (default 4)
'target/to/download'

View File

@ -96,6 +96,8 @@ Usage: rvcmd [-notrs] [-dns dns.yaml] 'target/to/download'
use standard TLS client
-notui
use plain text instead of TUI
-ua string
customize user agent
-w uint
connection waiting seconds (default 4)
'target/to/download'

View File

@ -20,8 +20,6 @@ import (
//go:generate ./pckcfg.sh assets packs tools
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0"
var (
notui = false
sc screen
@ -33,6 +31,7 @@ func main() {
cust := flag.Bool("c", false, "use custom yaml instruction")
force := flag.Bool("f", false, "force download even file exists")
wait := flag.Uint("w", 4, "connection waiting seconds")
ua := flag.String("ua", defua, "customize user agent")
flag.BoolVar(&notui, "notui", false, "use plain text instead of TUI")
flag.Parse()
args := flag.Args()
@ -89,7 +88,7 @@ func main() {
}
ch := make(chan struct{})
go func() {
err := usercfg.download(args[0], "", time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
err := usercfg.download(args[0], "", *ua, time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
ch <- struct{}{}
if err != nil {
errorln(err)

8
net.go
View File

@ -15,7 +15,7 @@ import (
"github.com/pkg/errors"
)
func (c *config) download(path, prefix string, waits time.Duration, usecust, usetrs, force bool) error {
func (c *config) download(path, prefix, ua string, waits time.Duration, usecust, usetrs, force bool) error {
for i, t := range c.Targets {
if t.Refer != "" {
refp := path[:strings.LastIndex(path, "/")+1] + t.Refer
@ -24,7 +24,7 @@ func (c *config) download(path, prefix string, waits time.Duration, usecust, use
if err != nil {
return err
}
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", waits, usecust, usetrs, force)
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", ua, waits, usecust, usetrs, force)
if err != nil {
return err
}
@ -70,7 +70,9 @@ func (c *config) download(path, prefix string, waits time.Duration, usecust, use
return
}
infof("#%s%d get: %s", prefix, i+1, req.URL)
req.Header.Add("user-agent", ua)
if len(ua) > 0 {
req.Header.Add("user-agent", ua)
}
var resp *http.Response
if usetrs {
resp, err = http2.DefaultClient.Do(req)

5
ua.go Normal file
View File

@ -0,0 +1,5 @@
//go:build !windows
package main
const defua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0"

3
ua_windows.go Normal file
View File

@ -0,0 +1,3 @@
package main
const defua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0"