Skip to content

Commit

Permalink
Fix SonyLiv channels and remove old SL redirect components (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabilrbl authored Jan 4, 2025
1 parent 2b28286 commit e8eba1d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/handlers/drm.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func MpdHandler(c *fiber.Ctx) error {
return []byte("<BaseURL>/render.dash/dash/</BaseURL>")
})
} else {
pattern := `<Period(.*)>`
pattern := `<Period(\s+[^>]*?)?\s*\/?>`
re = regexp.MustCompile(pattern)
resBody = re.ReplaceAllFunc(resBody, func(match []byte) []byte {
return []byte(fmt.Sprintf("%s\n<BaseURL>/render.dash/</BaseURL>", match))
Expand Down
44 changes: 22 additions & 22 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handlers
import (
"bytes"
"fmt"
"net/url"
"os"
"regexp"
"strconv"
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)

}
1 change: 1 addition & 0 deletions pkg/television/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8eba1d

Please sign in to comment.