mirror of
https://github.com/Monibuca/plugin-hdl.git
synced 2025-10-04 16:32:42 +08:00
更新日志方法
This commit is contained in:
38
main.go
38
main.go
@@ -26,47 +26,33 @@ type HDLConfig struct {
|
||||
var streamPathReg = regexp.MustCompile(`/(hdl/)?((.+)(\.flv)|(.+))`)
|
||||
|
||||
func (config *HDLConfig) Update(override config.Config) {
|
||||
override.Unmarshal(config)
|
||||
if config.PullOnStart {
|
||||
for streamPath, url := range config.AutoPullList {
|
||||
if err := PullStream(streamPath, url); err != nil {
|
||||
util.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if config.ListenAddr != "" || config.ListenAddrTLS != "" {
|
||||
util.Print(Green("HDL Listen at "), BrightBlue(config.ListenAddr), BrightBlue(config.ListenAddrTLS))
|
||||
plugin.Infoln(Green("HDL Listen at "), BrightBlue(config.ListenAddr), BrightBlue(config.ListenAddrTLS))
|
||||
config.Listen(plugin, config)
|
||||
}
|
||||
}
|
||||
func (config *HDLConfig) API_pull(rw http.ResponseWriter, r *http.Request) {
|
||||
func (config *HDLConfig) API_Pull(rw http.ResponseWriter, r *http.Request) {
|
||||
targetURL := r.URL.Query().Get("target")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
save := r.URL.Query().Get("save")
|
||||
if err := PullStream(streamPath, targetURL); err == nil {
|
||||
if save == "1" {
|
||||
if config.PullStream(streamPath, Puller{RemoteURL: targetURL, Config: &config.Pull}) {
|
||||
if r.URL.Query().Get("save") != "" {
|
||||
if config.AutoPullList == nil {
|
||||
config.AutoPullList = make(map[string]string)
|
||||
}
|
||||
config.AutoPullList[streamPath] = targetURL
|
||||
if err = plugin.Save(); err != nil {
|
||||
util.Println(err)
|
||||
if err := plugin.Save(); err != nil {
|
||||
plugin.Errorln(err)
|
||||
}
|
||||
}
|
||||
rw.WriteHeader(200)
|
||||
} else {
|
||||
rw.WriteHeader(500)
|
||||
}
|
||||
}
|
||||
|
||||
var hdlConfig = new(HDLConfig)
|
||||
var plugin = InstallPlugin(hdlConfig)
|
||||
|
||||
func init() {
|
||||
plugin.HandleApi("/list", util.GetJsonHandler(FilterStreams[*HDLPuller], time.Second))
|
||||
plugin.HandleFunc("/", hdlConfig.ServeHTTP)
|
||||
func (config *HDLConfig) API_List(rw http.ResponseWriter, r *http.Request) {
|
||||
util.ReturnJson(FilterStreams[*HDLPuller], time.Second, rw, r)
|
||||
}
|
||||
|
||||
var Config = new(HDLConfig)
|
||||
var plugin = InstallPlugin(Config)
|
||||
|
||||
func (config *HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
parts := streamPathReg.FindStringSubmatch(r.RequestURI)
|
||||
if len(parts) == 0 {
|
||||
@@ -80,7 +66,7 @@ func (config *HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Transfer-Encoding", "chunked")
|
||||
w.Header().Set("Content-Type", "video/x-flv")
|
||||
sub := Subscriber{ID: r.RemoteAddr, Type: "FLV"}
|
||||
if sub.Subscribe(stringPath, hdlConfig.Subscribe) {
|
||||
if sub.Subscribe(stringPath, Config.Subscribe) {
|
||||
vt, at := sub.WaitVideoTrack(), sub.WaitAudioTrack()
|
||||
var buffer bytes.Buffer
|
||||
if _, err := amf.WriteString(&buffer, "onMetaData"); err != nil {
|
||||
|
Reference in New Issue
Block a user