
package main
import (
"bufio"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
)
func main() {
url := "https://tenapi.cn/v2/video"
reader := bufio.NewReader(os.Stdin)
fmt.Print("请输入视频 URL: ")
urlInput, _ := reader.ReadString('\n')
urlInput = strings.TrimSpace(urlInput)
payload := strings.NewReader("url=" + urlInput)
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var data map[string]interface{}
err := decoder.Decode(&data)
if err != nil {
panic(err)
}
video_title := data["data"].(map[string]interface{})["title"].(string)
video_cover := data["data"].(map[string]interface{})["cover"].(string)
video_url := data["data"].(map[string]interface{})["url"].(string)
file, err := os.Create(video_title + ".mp4")
if err != nil {
panic(err)
}
defer file.Close()
resp, err := http.Get(video_url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
_, err = io.Copy(file, resp.Body)
if err != nil {
panic(err)
}
fmt.Println("视频下载成功!")
fmt.Println("视频标题:", video_title)
fmt.Println("视频封面:", video_cover)
fmt.Println("视频下载地址:", video_url)
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}