fix m3u auth

This commit is contained in:
YouROK
2021-04-14 14:25:35 +03:00
parent 0c0c53b8db
commit 1b5f101298
2 changed files with 19 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ func stream(c *gin.Context) {
data := ""
notAuth := c.GetBool("not_auth")
if notAuth && play {
if notAuth && (play || m3u) {
streamNoAuth(c)
return
}
@@ -134,6 +134,9 @@ func streamNoAuth(c *gin.Context) {
link := c.Query("link")
indexStr := c.Query("index")
_, preload := c.GetQuery("preload")
_, m3u := c.GetQuery("m3u")
_, fromlast := c.GetQuery("fromlast")
_, play := c.GetQuery("play")
title := c.Query("title")
poster := c.Query("poster")
data := ""
@@ -193,5 +196,18 @@ func streamNoAuth(c *gin.Context) {
torr.Preload(tor, index)
}
tor.Stream(index, c.Request, c.Writer)
// return m3u if query
if m3u {
m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), "http://"+c.Request.Host, fromlast)
sendM3U(c, tor.Name()+".m3u", tor.Hash().HexString(), m3ulist)
return
} else
// return play if query
if play {
tor.Stream(index, c.Request, c.Writer)
return
}
c.Header("WWW-Authenticate", "Basic realm=Authorization Required")
c.AbortWithStatus(http.StatusUnauthorized)
return
}