slash.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package function
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. "net/url"
  8. "os"
  9. "strings"
  10. "github.com/JamZYM/golagrange/api"
  11. )
  12. func Func_bvdl(msg_text string, connBot api.WsBot, user_id int) {
  13. bv := strings.Replace(msg_text, "/bvdl ", "", 1)
  14. info, err := http.Post("http://"+os.Getenv("HOST")+":"+os.Getenv("BVDLPORT")+"/api/info?bv="+bv, "application/json", nil)
  15. if err != nil {
  16. connBot.Send_private_msg(user_id, "请求失败")
  17. fmt.Println(err)
  18. } else {
  19. defer info.Body.Close()
  20. var jsondata map[string]interface{}
  21. data, _ := io.ReadAll(info.Body)
  22. json.Unmarshal(data, &jsondata)
  23. title := jsondata["videos"].(map[string]interface{})["1"].(map[string]interface{})["title"].(string)
  24. fmt.Println("http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + bv + "&title=" + title)
  25. qbv := url.QueryEscape(bv)
  26. qtitle := url.QueryEscape(title)
  27. geturl := "http://" + os.Getenv("HOST") + ":" + os.Getenv("BVDLPORT") + "/api/download?bv=" + qbv + "&title=" + qtitle
  28. result, err := http.Get(geturl)
  29. if err != nil {
  30. connBot.Send_private_msg(user_id, "下载失败")
  31. fmt.Println(err)
  32. } else {
  33. fmt.Print(result.Body)
  34. connBot.Send_private_msg(user_id, title)
  35. }
  36. }
  37. }