m3u8
This commit is contained in:
34
bin/main.go
34
bin/main.go
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -205,6 +206,11 @@ func main() {
|
||||
w.Write([]byte("Hello World!"))
|
||||
})
|
||||
|
||||
// 屏蔽 /favicon.ico
|
||||
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Not Found", http.StatusNotFound)
|
||||
})
|
||||
|
||||
// 获取浏览记录
|
||||
http.HandleFunc("/history", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
|
||||
@@ -596,6 +602,34 @@ func main() {
|
||||
w.Write(data)
|
||||
})
|
||||
|
||||
// 获取转换后的m3u8视频链接
|
||||
http.HandleFunc("/video/", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
|
||||
|
||||
queryParam := r.URL.Query().Get("url")
|
||||
safeParam, err := url.QueryUnescape(queryParam)
|
||||
if err != nil {
|
||||
log.Println("解码URL失败", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
urls := models.GetVideoM3U8(safeParam)
|
||||
|
||||
// 将对象转换为有缩进的JSON输出
|
||||
json, err := json.MarshalIndent(&struct{Urls string `json:"urls"`}{
|
||||
Urls: urls,
|
||||
}, "", " ")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 输出JSON
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(json)
|
||||
})
|
||||
|
||||
// 从Viper中读取配置
|
||||
port := viper.GetString("server.port")
|
||||
log.Println("Server is running at http://localhost:" + port)
|
||||
|
Reference in New Issue
Block a user