|
@@ -1,7 +1,6 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "bytes"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io"
|
|
@@ -15,7 +14,7 @@ import (
|
|
|
)
|
|
|
|
|
|
func msgProccess(msg map[string]interface{}, connBot api.WsBot) {
|
|
|
- fmt.Println(msg)
|
|
|
+ // fmt.Println(msg)
|
|
|
if msg["message_type"].(string) == "private" {
|
|
|
user_id := int(msg["user_id"].(float64))
|
|
|
// println(user_id)
|
|
@@ -25,30 +24,48 @@ func msgProccess(msg map[string]interface{}, connBot api.WsBot) {
|
|
|
bv := strings.Replace(msg["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})["text"].(string), "/bvdl ", "", 1)
|
|
|
// println(bv)
|
|
|
// println(os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/info")
|
|
|
- info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info", "application/json",
|
|
|
- bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
- {
|
|
|
- "bv":%s
|
|
|
- }
|
|
|
- `, bv))))
|
|
|
+ // info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info", "application/json",
|
|
|
+ // bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
+ // {
|
|
|
+ // "bv":%s
|
|
|
+ // }
|
|
|
+ // `, bv))))
|
|
|
+ info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info?bv="+bv, "application/json", nil)
|
|
|
if err != nil {
|
|
|
connBot.Send_private_msg(user_id, "请求失败")
|
|
|
fmt.Println(err)
|
|
|
} else {
|
|
|
- // defer info.Body.Close()
|
|
|
+ defer info.Body.Close()
|
|
|
+ var jsondata map[string]interface{}
|
|
|
data, _ := io.ReadAll(info.Body)
|
|
|
- fmt.Println(string(data))
|
|
|
- result, err := http.Post(os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/download", "application/json",
|
|
|
- bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
- {
|
|
|
- "bv":%s;
|
|
|
- "title":"%s"
|
|
|
- }
|
|
|
- `, bv, "title"))))
|
|
|
+ json.Unmarshal(data, &jsondata)
|
|
|
+ // fmt.Println(string(data))
|
|
|
+ title := jsondata["videos"].(map[string]interface{})["1"].(map[string]interface{})["title"].(string)
|
|
|
+ // result, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/download", "application/json",
|
|
|
+ // bytes.NewBuffer([]byte(fmt.Sprintf(`
|
|
|
+ // {
|
|
|
+ // "bv":%s;
|
|
|
+ // "title":"%s"
|
|
|
+ // }
|
|
|
+ // `, bv, title))))
|
|
|
+ fmt.Println("http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + bv + "&title=" + title)
|
|
|
+ // result, err := http.PostForm("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/download?bv="+bv+"&title="+title, nil)
|
|
|
+
|
|
|
+ url := "http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + bv + "&title=" + title
|
|
|
+ result, err := http.Get(url)
|
|
|
+
|
|
|
+ // url := "http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download"
|
|
|
+ // body := fmt.Sprintf(`{"bv":"%s","title":"%s"}`, bv, title)
|
|
|
+ // result, err := http.Post(url, "application/json", strings.NewReader(body))
|
|
|
+
|
|
|
if err != nil {
|
|
|
connBot.Send_private_msg(user_id, "下载失败")
|
|
|
+ fmt.Println(err)
|
|
|
+ } else {
|
|
|
+ fmt.Print(result)
|
|
|
+ connBot.Send_private_msg(user_id, title)
|
|
|
}
|
|
|
- fmt.Print(result)
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|