|
@@ -156,6 +156,75 @@ func DownloadAdv(downloadnode, downloaderid, url, method string, reqparam, head
|
|
|
return "", nil, nil
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func DownloadAdvNew(downloadnode, downloaderid, url, method string, reqparam, head map[string]interface{}, mycookie []*http.Cookie, encoding string, useproxy, ishttps bool, code string, timeout int64) (string, []*http.Cookie, map[string]interface{}) {
|
|
|
+ defer mu.Catch()
|
|
|
+ ResultMsclient := MsclientTest
|
|
|
+ if downloadnode == "test" { //805
|
|
|
+ ResultMsclient = MsclientTest
|
|
|
+ } else if downloadnode == "comm" { //801
|
|
|
+ ResultMsclient = Msclient
|
|
|
+ } else if downloadnode == "bid" { //803
|
|
|
+ ResultMsclient = MsclientBid
|
|
|
+ }
|
|
|
+ msgid := mu.UUID(8)
|
|
|
+ if len(head) < 1 {
|
|
|
+ l := len(agent.UserAgents["common"])
|
|
|
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
+ head["User-Agent"] = agent.UserAgents["common"][r.Intn(l)]
|
|
|
+ }
|
|
|
+ isImg := regImg.MatchString(url)
|
|
|
+ var ret []byte
|
|
|
+ var err error
|
|
|
+ if downloaderid == "" {
|
|
|
+ ret, err = ResultMsclient.Call("", msgid, mu.SERVICE_DOWNLOAD, mu.SENDTO_TYPE_RAND_RECIVER, map[string]interface{}{
|
|
|
+ "url": url,
|
|
|
+ "method": method,
|
|
|
+ "head": head,
|
|
|
+ "reqparam": reqparam,
|
|
|
+ "cookie": mycookie,
|
|
|
+ "encoding": encoding,
|
|
|
+ "useproxy": useproxy,
|
|
|
+ "ishttps": ishttps,
|
|
|
+ "new": true,
|
|
|
+ }, timeout)
|
|
|
+ } else {
|
|
|
+ if isAvailable(downloaderid) {
|
|
|
+ ret, err = ResultMsclient.Call(downloaderid, msgid, mu.SERVICE_DOWNLOAD, mu.SENDTO_TYPE_P2P, map[string]interface{}{
|
|
|
+ "url": url,
|
|
|
+ "method": method,
|
|
|
+ "head": head,
|
|
|
+ "reqparam": reqparam,
|
|
|
+ "cookie": mycookie,
|
|
|
+ "encoding": encoding,
|
|
|
+ "useproxy": useproxy,
|
|
|
+ "ishttps": ishttps,
|
|
|
+ }, timeout)
|
|
|
+ } else {
|
|
|
+ return "", nil, nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ str := "方法DownloadAdv,url:" + url + ",err:" + err.Error()
|
|
|
+ log.Println(str)
|
|
|
+ }
|
|
|
+ tmp := map[string]interface{}{}
|
|
|
+ json.Unmarshal(ret, &tmp)
|
|
|
+ cooks := util.ParseHttpCookie(tmp["cookie"])
|
|
|
+ headers, _ := tmp["header"].(map[string]interface{})
|
|
|
+ if v, ok := tmp["code"].(string); ok && v == "200" {
|
|
|
+ if isImg {
|
|
|
+ bs, _ := tmp["content"].(string)
|
|
|
+ return string(bs), cooks, headers
|
|
|
+ } else {
|
|
|
+ bs, _ := base64.StdEncoding.DecodeString(tmp["content"].(string))
|
|
|
+ return string(bs), cooks, headers
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return "", nil, nil
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func DownloadFile(downloaderid, url, method string, reqparam, head map[string]interface{}, mycookie []*http.Cookie, encoding string, useproxy, ishttps bool, code string, timeout int64) []byte {
|
|
|
defer mu.Catch()
|
|
|
timeout = timeout * 10
|