From e8eba1d020e781a31bab9efe450f80efd1243b5c Mon Sep 17 00:00:00 2001 From: Mohammed Rabil Date: Sat, 4 Jan 2025 15:51:37 +0530 Subject: [PATCH] Fix SonyLiv channels and remove old SL redirect components (#493) --- internal/handlers/drm.go | 2 +- internal/handlers/handlers.go | 44 +++++++++++++++++------------------ pkg/television/types.go | 1 + 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/internal/handlers/drm.go b/internal/handlers/drm.go index e742364c..53c455d7 100644 --- a/internal/handlers/drm.go +++ b/internal/handlers/drm.go @@ -243,7 +243,7 @@ func MpdHandler(c *fiber.Ctx) error { return []byte("/render.dash/dash/") }) } else { - pattern := `` + pattern := `]*?)?\s*\/?>` re = regexp.MustCompile(pattern) resBody = re.ReplaceAllFunc(resBody, func(match []byte) []byte { return []byte(fmt.Sprintf("%s\n/render.dash/", match)) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index d113ade3..c821b6d8 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -3,7 +3,6 @@ package handlers import ( "bytes" "fmt" - "net/url" "os" "regexp" "strconv" @@ -149,10 +148,6 @@ func LiveHandler(c *fiber.Ctx) error { "message": err, }) } - // remove sl channels checks - // if id[:2] == "sl" { - // return sonyLivRedirect(c, liveResult) - // } // Check if liveResult.Bitrates.Auto is empty if liveResult.Bitrates.Auto == "" { @@ -439,8 +434,28 @@ func PlayHandler(c *fiber.Ctx) error { quality := c.Query("q") var player_url string - if !utils.ContainsString(id, SONY_LIST) && EnableDRM { - player_url = "/mpd/" + id + "?q=" + quality + if EnableDRM { + // Some sonyLiv channels are DRM protected and others are not + // Inorder to check, we need to make additional request to JioTV API + // Quick dirty fix, otherise we need to refactor entire LiveTV Handler approach + if utils.ContainsString(id, SONY_LIST) { + liveResult, err := TV.Live(id) + if err != nil { + utils.Log.Println(err) + return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ + "message": err, + }) + } + // if drm is available, use DRM player + if liveResult.IsDRM { + player_url = "/mpd/" + id + "?q=" + quality + } else { + // if not, use HLS player + player_url = "/player/" + id + "?q=" + quality + } + } else { + player_url = "/mpd/" + id + "?q=" + quality + } } else { player_url = "/player/" + id + "?q=" + quality } @@ -508,18 +523,3 @@ func EPGHandler(c *fiber.Ctx) error { func DASHTimeHandler(c *fiber.Ctx) error { return c.SendString(time.Now().UTC().Format("2006-01-02T15:04:05.000Z")) } - -// sonylivRedirect redirects to sonyliv channels -func sonyLivRedirect(c *fiber.Ctx, liveResult *television.LiveURLOutput) error { - ch_url := liveResult.Bitrates.Auto - // remove origin from url - cho_url, err := url.Parse(ch_url) - if err != nil { - utils.Log.Println(err) - return err - } - - // remove origin from url - return c.Redirect(cho_url.Path+"?"+cho_url.RawQuery, fiber.StatusFound) - -} diff --git a/pkg/television/types.go b/pkg/television/types.go index 3e2eb7f4..82ba295c 100644 --- a/pkg/television/types.go +++ b/pkg/television/types.go @@ -83,6 +83,7 @@ type LiveURLOutput struct { StartTime float64 `json:"startTime"` VodStitch bool `json:"vodStitch"` Mpd MPD `json:"mpd"` + IsDRM bool `json:"isDRM"` } // CategoryMap represents Categories for channels