package ffmpeg import ( "ycmediakit/internal/pkg/server/ffmpegServer" "ycmediakit/internal/pkg/unit/result" "github.com/gin-gonic/gin" ) func StartToHls(c *gin.Context) { target := c.Query("target") streamPath := c.Query("streamPath") target, ok := ffmpegServer.PrepareUrl(target) if !ok { result.InvalidParams.WithVoidFV().Failure(c) return } streamPath, ok = ffmpegServer.PrepareStreamPath(streamPath) if !ok { result.InvalidParams.WithVoidFV().Failure(c) return } ok = toHlsServer.Exists(streamPath) if ok { result.Created.WithFullFV(toHlsServer.BuildHlsPath(streamPath)).Success(c) return } err := ffmpegServer.ProbeWithTimeout(target, cfg.Timeout) if err != nil { log.Error(err.Error()) result.Wrong.WithVoidFV().WithMsg(err.Error()).Error(c) return } ok = toHlsServer.Add(target, streamPath, cfg.Timeout, &cfg.ToHls) if !ok { result.Ok.WithVoidFV().Failure(c) return } go func() { _, err = toHlsServer.RunToHlsCmd(streamPath) if err != nil { log.Error(err.Error()) err = toHlsServer.DeleteAndStop(streamPath) if err != nil { log.Error(err.Error()) } } }() result.Ok.WithFullFV(toHlsServer.BuildHlsPath(streamPath)).Success(c) } func ExistsToHls(c *gin.Context) { streamPath := c.Query("streamPath") streamPath, ok := ffmpegServer.PrepareStreamPath(streamPath) if !ok { result.InvalidParams.Failure(c) return } ok = toHlsServer.Exists(streamPath) result.Ok.WithFlag(ok).Success(c) } func CloseToHls(c *gin.Context) { streamPath := c.Query("streamPath") streamPath, ok := ffmpegServer.PrepareStreamPath(streamPath) if !ok { result.InvalidParams.Failure(c) return } ok = toHlsServer.Exists(streamPath) if !ok { result.NotFound.Failure(c) return } err := toHlsServer.DeleteAndStop(streamPath) if err != nil { log.Error(err.Error()) result.Wrong.WithMsg(err.Error()).Error(c) return } result.Ok.WithFlag(true).Success(c) } func GetToHlsList(c *gin.Context) { result.Ok.WithData(toHlsServer.GetList()).Success(c) }