|
|
|
@ -3,6 +3,7 @@ package mget
|
|
|
|
|
import (
|
|
|
|
|
"b612.me/stario"
|
|
|
|
|
"b612.me/starlog"
|
|
|
|
|
"b612.me/starnet"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
"os"
|
|
|
|
@ -26,7 +27,8 @@ var headers []string
|
|
|
|
|
var ua string
|
|
|
|
|
var proxy string
|
|
|
|
|
var skipVerify bool
|
|
|
|
|
var speedcontrol string
|
|
|
|
|
var speedcontrol, user, pwd string
|
|
|
|
|
var dialTimeout, timeout int
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
Cmd.Flags().StringVarP(&mg.Tareget, "output", "o", "", "输出文件名")
|
|
|
|
@ -34,10 +36,14 @@ func init() {
|
|
|
|
|
Cmd.Flags().IntVarP(&mg.Thread, "thread", "t", 8, "线程数")
|
|
|
|
|
Cmd.Flags().IntVarP(&mg.RedoRPO, "safe", "s", 1048576, "安全校验点")
|
|
|
|
|
Cmd.Flags().StringSliceVarP(&headers, "header", "H", []string{}, "自定义请求头,格式: key=value")
|
|
|
|
|
Cmd.Flags().StringVarP(&proxy, "proxy", "p", "", "代理地址")
|
|
|
|
|
Cmd.Flags().StringVarP(&proxy, "proxy", "P", "", "代理地址")
|
|
|
|
|
Cmd.Flags().StringVarP(&ua, "user-agent", "U", "", "自定义User-Agent")
|
|
|
|
|
Cmd.Flags().BoolVarP(&skipVerify, "skip-verify", "k", false, "跳过SSL验证")
|
|
|
|
|
Cmd.Flags().StringVarP(&speedcontrol, "speed", "S", "", "限速,如1M,意思是1MB/s")
|
|
|
|
|
Cmd.Flags().IntVarP(&dialTimeout, "dial-timeout", "d", 5, "连接网络超时时间,单位:秒")
|
|
|
|
|
Cmd.Flags().IntVarP(&timeout, "timeout", "T", 0, "下载超时时间,单位:秒")
|
|
|
|
|
Cmd.Flags().StringVarP(&user, "user", "u", "", "http basic认证用户")
|
|
|
|
|
Cmd.Flags().StringVarP(&pwd, "passwd", "p", "", "http basic认证密码")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseSpeedString(speedString string) (uint64, error) {
|
|
|
|
@ -83,6 +89,17 @@ func Run(cmd *cobra.Command, args []string) {
|
|
|
|
|
starlog.Errorln("缺少URL参数")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
mg.Setting = *starnet.NewSimpleRequest(args[0], "GET")
|
|
|
|
|
mg.OriginUri = args[0]
|
|
|
|
|
if dialTimeout > 0 {
|
|
|
|
|
mg.Setting.SetDialTimeout(time.Duration(dialTimeout) * time.Second)
|
|
|
|
|
}
|
|
|
|
|
if timeout > 0 {
|
|
|
|
|
mg.Setting.SetTimeout(time.Duration(timeout) * time.Second)
|
|
|
|
|
}
|
|
|
|
|
if user != "" || pwd != "" {
|
|
|
|
|
mg.Setting.RequestOpts.SetBasicAuth(user, pwd)
|
|
|
|
|
}
|
|
|
|
|
if speedcontrol != "" {
|
|
|
|
|
speed, err := parseSpeedString(speedcontrol)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -109,7 +126,6 @@ func Run(cmd *cobra.Command, args []string) {
|
|
|
|
|
if skipVerify {
|
|
|
|
|
mg.Setting.SetSkipTLSVerify(true)
|
|
|
|
|
}
|
|
|
|
|
mg.OriginUri = args[0]
|
|
|
|
|
sig := make(chan os.Signal)
|
|
|
|
|
signal.Notify(sig, os.Interrupt)
|
|
|
|
|
select {
|
|
|
|
|