Skip to content

Commit

Permalink
fix hls header
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com>
  • Loading branch information
pierre-emmanuelJ committed Mar 19, 2021
1 parent ba6da3b commit ed79269
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
1 change: 0 additions & 1 deletion pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (c *Config) xtreamRoutes(r *gin.RouterGroup) {
r.GET(fmt.Sprintf("/movie/%s/%s/:id", c.User, c.Password), c.xtreamStreamMovie)
r.GET(fmt.Sprintf("/series/%s/%s/:id", c.User, c.Password), c.xtreamStreamSeries)
r.GET(fmt.Sprintf("/hlsr/:token/%s/%s/:channel/:hash/:chunk", c.User, c.Password), c.xtreamHlsrStream)
r.GET("/hls/:token/:id", c.xtreamHlsStream)
}

func (c *Config) m3uRoutes(r *gin.RouterGroup) {
Expand Down
20 changes: 5 additions & 15 deletions pkg/server/xtreamHandles.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (c *Config) hlsXtreamStream(ctx *gin.Context, oriURL *url.URL) {
return
}

req.Header.Set("User-Agent", ctx.Request.UserAgent())
copyHttpHeader(req.Header, ctx.Request.Header)

resp, err := client.Do(req)
if err != nil {
Expand All @@ -314,7 +314,7 @@ func (c *Config) hlsXtreamStream(ctx *gin.Context, oriURL *url.URL) {
return
}

hlsReq.Header.Set("User-Agent", ctx.Request.UserAgent())
copyHttpHeader(hlsReq.Header, ctx.Request.Header)

hlsResp, err := client.Do(hlsReq)
if err != nil {
Expand All @@ -330,6 +330,9 @@ func (c *Config) hlsXtreamStream(ctx *gin.Context, oriURL *url.URL) {
}
body := string(b)
body = strings.ReplaceAll(body, "/"+c.XtreamUser.String()+"/"+c.XtreamPassword.String()+"/", "/"+c.User.String()+"/"+c.Password.String()+"/")

copyHttpHeader(ctx.Request.Header, hlsResp.Header)

ctx.Data(http.StatusOK, hlsResp.Header.Get("Content-Type"), []byte(body))
return
}
Expand All @@ -339,16 +342,3 @@ func (c *Config) hlsXtreamStream(ctx *gin.Context, oriURL *url.URL) {

ctx.Status(resp.StatusCode)
}

func (c *Config) xtreamHlsStream(ctx *gin.Context) {
id := ctx.Param("id")
token := ctx.Param("token")

rpURL, err := url.Parse(fmt.Sprintf("%s/hls/%s/%s", c.XtreamBaseURL, token, id))
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err) // nolint: errcheck
return
}

c.stream(ctx, rpURL)
}

0 comments on commit ed79269

Please sign in to comment.