From 1b5f1012980b1c137742afb782f84ee766f83a3f Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Wed, 14 Apr 2021 14:25:35 +0300 Subject: [PATCH] fix m3u auth --- server/web/api/stream.go | 20 ++++++++++++++++++-- server/web/auth/auth.go | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/web/api/stream.go b/server/web/api/stream.go index d94977e..51adec0 100644 --- a/server/web/api/stream.go +++ b/server/web/api/stream.go @@ -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 } diff --git a/server/web/auth/auth.go b/server/web/auth/auth.go index db29439..721956b 100644 --- a/server/web/auth/auth.go +++ b/server/web/auth/auth.go @@ -64,7 +64,7 @@ func BasicAuth(accounts gin.Accounts) gin.HandlerFunc { user, found := pairs.searchCredential(c.Request.Header.Get("Authorization")) if !found { if strings.HasPrefix(c.FullPath(), "/stream") || - strings.HasPrefix(c.FullPath(), "/playlist") { + (strings.HasPrefix(c.FullPath(), "/playlist") && c.FullPath() != "/playlistall/all.m3u") { c.Set("not_auth", true) return }