k.zhang 4 years ago
parent
commit
f6bfc11957
1 changed files with 54 additions and 7 deletions
  1. 54 7
      apis/dyjx/url_jx.go

+ 54 - 7
apis/dyjx/url_jx.go

@@ -10,6 +10,7 @@ import (
 	"fmt"
 	"github.com/asmcos/requests"
 	"github.com/gin-gonic/gin"
+	"io/ioutil"
 	"net/http"
 	"strings"
 )
@@ -52,6 +53,7 @@ func DeWater(in models.DyJieXiInput) (error, models.DyJieXiOutput) {
 			return http.ErrUseLastResponse
 		},
 	}
+	//client.Head()
 
 	res, err := client.Get(baseHost)
 	if err != nil {
@@ -122,6 +124,39 @@ func DeWater(in models.DyJieXiInput) (error, models.DyJieXiOutput) {
 	dysy.Create(dysy.DeWaterVideoURL)
 
 	fmt.Println("out.Data.VideoUrl = ", out.Data.VideoUrl)
+
+	client1 := &http.Client{
+		CheckRedirect: func(req *http.Request, via []*http.Request) error {
+			return http.ErrUseLastResponse
+		},
+	}
+	//client.Head()
+
+	res1, err := client1.Get(out.Data.VideoUrl)
+	if err != nil {
+		return errors.New(apis.ClientGetFail), out
+	}
+	ss, err := ioutil.ReadAll(res1.Body)
+	fmt.Println(string(ss))
+
+	//reqq := requests.Requests()
+
+	// 获取 header
+
+	//header, err := ubaRequestHeader("")
+	//if err != nil {
+	//	fmt.Println(err.Error())
+	//}
+	//fmt.Println(header)
+	//respp, err := reqq.Get(out.Data.VideoUrl, header)
+	//if err != nil {
+	//	fmt.Println(err.Error())
+	//}
+	////fmt.Println(respp.Text())
+	//fmt.Println(respp.Text()[0:100])
+	//index := strings.Index(respp.Text(), "src")
+	//fmt.Println("index = ", index)
+
 	//打开视频连接
 	//reqq := requests.Requests()
 
@@ -130,19 +165,21 @@ func DeWater(in models.DyJieXiInput) (error, models.DyJieXiOutput) {
 	//	fmt.Println("err =", err.Error())
 	//}
 
-	respp, err := http.Get(out.Data.VideoUrl)
-	if err != nil {
-		fmt.Println("http get error", err)
-	}
+	//respp, err := http.Post(out.Data.VideoUrl, "text/html", nil)
+	//if err != nil {
+	//	fmt.Println("http get error", err)
+	//}
 	//body, err := ioutil.ReadAll(respp.Body)
 	//if err != nil {
 	//	fmt.Println("read error", err)
 	//
 	//}
-	str = respp.Header.Get("Location")
-	fmt.Println("str = ", str)
+	//str = respp.Header.Get("Location")
+	//fmt.Println("str = ", str)
 
-	//fmt.Println(string(body))
+	//fmt.Println(string(body)[0:100])
+	//index := strings.Index(string(body), "src")
+	//fmt.Println("index = ", index)
 	//fmt.Println("resp = ", resp.Text())
 	//fmt.Println("resp = ", resp.SaveFile("./name"))
 	//fmt.Println("resp = ", string(resp.Content()))
@@ -150,3 +187,13 @@ func DeWater(in models.DyJieXiInput) (error, models.DyJieXiOutput) {
 	return nil, out
 
 }
+
+func ubaRequestHeader(body string) (header requests.Header, err error) {
+
+	// 正确返回
+	return requests.Header{
+		"Content-Type": "text/html; charset=utf-8",
+		"User-Agent":   "Mozilla/5.0 (Linux; Android 9.0; Z832 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Mobile Safari/537.36",
+	}, nil
+
+}