mirror of
				https://github.com/fumiama/RVC-Models-Downloader.git
				synced 2025-11-04 04:45:08 +09:00 
			
		
		
		
	feat: customizable ua (#2)
This commit is contained in:
		
							parent
							
								
									e6b2709814
								
							
						
					
					
						commit
						2b6ca35a6d
					
				@ -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'
 | 
			
		||||
 | 
			
		||||
@ -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'
 | 
			
		||||
 | 
			
		||||
@ -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'
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							@ -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(¬ui, "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
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								net.go
									
									
									
									
									
								
							@ -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
									
								
							
							
						
						
									
										5
									
								
								ua.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										3
									
								
								ua_windows.go
									
									
									
									
									
										Normal 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"
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user