Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/rabilrbl/jiotv_go into jf
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyourap committed Sep 3, 2024
2 parents 064262a + 280208a commit 7c3d4b7
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.3
go-version: 1.23

- name: Download mips32r2 toolchain
run: wget -O toolchain.tar https://github.com/JFC-Group/JF-Buildroot/releases/download/2015.08.1/mipsel-buildroot-linux-uclibc-toolchain-2015.08.1.tar
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine AS builder
FROM golang:1.23-alpine AS builder

# Set the working directory inside the container
WORKDIR /app
Expand Down Expand Up @@ -39,4 +39,4 @@ EXPOSE 5001
ENTRYPOINT ["./jiotv_go"]

# Default arguments
CMD ["serve", "--public"]
CMD ["serve", "--public", "--skip-update-check"]
11 changes: 1 addition & 10 deletions cmd/jiotv_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"github.com/rabilrbl/jiotv_go/v3/web"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/etag"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/helmet"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/template/html/v2"
Expand All @@ -32,11 +30,10 @@ func JioTVServer(host, port, configPath string, prefork bool) error {
if err := config.Cfg.Load(configPath); err != nil {
return err
}

// Initialize the logger object
utils.Log = utils.GetLogger()


// Initialize the store object
if err := store.Init(); err != nil {
return err
Expand Down Expand Up @@ -88,12 +85,6 @@ func JioTVServer(host, port, configPath string, prefork bool) error {
Browse: false,
}))

// Helmet middleware to set security headers
app.Use(helmet.New())

// ETag middleware to set ETag header for caching
app.Use(etag.New())

// Handle all /bpk-tv/* routes
app.Use("/bpk-tv/", handlers.BpkProxyHandler)

Expand Down
2 changes: 1 addition & 1 deletion dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22-alpine
FROM golang:1.23-alpine

ENV GO111MODULE=on \
JIOTV_DEBUG=true
Expand Down
7 changes: 7 additions & 0 deletions docs/usage/iptv.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ JioTV Go offers a convenient M3U playlist endpoint to enhance your IPTV experien
Please note that either `c=split` or `c=language` can be used at a time.
6. If you would like to skip one or more genre from playlist, you can use `sg=Educational,Lifestyle`
```
http://localhost:5001/playlist.m3u?sg=Educational,Lifestyle
```
This will skip all channels from provided list of genres.
For both specific quality and split category, append the `q=` and `c=` query parameters:
```
Expand Down
3 changes: 3 additions & 0 deletions docs/usage/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ You can append `?q=<level>` to the path where `<level>` should be replaced with

You can also append `&c=split` to the path to have categories based on both language and genre. Example categories: `Hindi - Entertainment`, `English - News`, `Tamil - Sports`, etc.

You can also append `&sg=<genre_list>` to the path in order to skip specific genres. Here replace `<genre_list>` with comma(,) seperated list of genres.
Valid genres: `Entertainment`, `Movies`, `Kids`, `Sports`, `Lifestyle`, `Infotainment`, `News`, `Music`, `Devotional`, `Business`, `Educational`, `Shopping`, `JioDarshan`

### M3U Playlist

- **Path**: `/channels?type=m3u`
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rabilrbl/jiotv_go/v3

go 1.22
go 1.23

require (
github.com/BurntSushi/toml v1.4.0
Expand All @@ -15,7 +15,7 @@ require (
github.com/gofiber/utils v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.26.0 // indirect
Expand All @@ -30,7 +30,7 @@ require (
github.com/gofiber/template/html/v2 v2.1.2
github.com/google/uuid v1.5.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/madflojo/tasks v1.2.0
github.com/madflojo/tasks v1.2.1
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/madflojo/tasks v1.2.0 h1:wYVgHx293eFFN2xtfsgNQ8T4LUPZEdnGH5jvLn3B7kg=
github.com/madflojo/tasks v1.2.0/go.mod h1:BKSfcHnUSlQMA5wXdaxgthhKc75GfVIivEywn2YWqt0=
github.com/madflojo/tasks v1.2.1 h1:0HMN1RCVf6yDjrlIbthkET1KCB+gxknQG3/SLO+HHj4=
github.com/madflojo/tasks v1.2.1/go.mod h1:/WMv6u3Xb5eyy+aIM76ildaIT166GOxN/jya9oI7dyo=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -41,8 +41,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.14.6 h1:GyjwcWBAf+GFDMLziwerKvpuS7ZF+mNTAXIB2aspiZs=
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
REFRESH_TOKEN_TASK_ID = "jiotv_refresh_token"
REFRESH_TOKEN_TASK_ID = "jiotv_refresh_token"
REFRESH_SSOTOKEN_TASK_ID = "jiotv_refresh_sso_token"
)

Expand Down
38 changes: 30 additions & 8 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ import (

var (
TV *television.Television
DisableTSHandler = config.Cfg.DisableTSHandler
isLogoutDisabled = config.Cfg.DisableLogout
DisableTSHandler bool
isLogoutDisabled bool
Title string
EnableDRM = config.Cfg.DRM
EnableDRM bool
SONY_LIST = []string{"154", "155", "162", "289", "291", "471", "474", "476", "483", "514", "524", "525", "697", "872", "873", "874", "891", "892", "1146", "1393", "1772", "1773", "1774", "1775"}
)

const (
REFRESH_TOKEN_URL = "https://auth.media.jio.com/tokenservice/apis/v1/refreshtoken?langId=6"
REFRESH_SSO_TOKEN_URL = "https://tv.media.jio.com/apis/v2.0/loginotp/refresh?langId=6"
PLAYER_USER_AGENT = "plaYtv/7.0.5 (Linux;Android 8.1.0) ExoPlayerLib/2.11.7"
REQUEST_USER_AGENT = "okhttp/4.2.2"
)

// Init initializes the necessary operations required for the handlers to work.
Expand All @@ -40,6 +42,9 @@ func Init() {
} else {
Title = "JioTV Go"
}
DisableTSHandler = config.Cfg.DisableTSHandler
isLogoutDisabled = config.Cfg.DisableLogout
EnableDRM = config.Cfg.DRM
if DisableTSHandler {
utils.Log.Println("TS Handler disabled!. All TS video requests will be served directly from JioTV servers.")
}
Expand Down Expand Up @@ -145,6 +150,15 @@ func LiveHandler(c *fiber.Ctx) error {
if id[:2] == "sl" {
return sonyLivRedirect(c, liveResult)
}
// Check if liveResult.Bitrates.Auto is empty
if liveResult.Bitrates.Auto == "" {
error_message := "No stream found for channel id: " + id + "Status: " + liveResult.Message
utils.Log.Println(error_message)
utils.Log.Println(liveResult)
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
"message": error_message,
})
}
// quote url as it will be passed as a query parameter
// It is required to quote the url as it may contain special characters like ? and &
coded_url, err := secureurl.EncryptURL(liveResult.Bitrates.Auto)
Expand Down Expand Up @@ -292,6 +306,7 @@ func SLHandler(c *fiber.Ctx) error {
c.Request().Header.Del("Accept-Language")
c.Request().Header.Del("Origin")
c.Request().Header.Del("Referer")
c.Request().Header.Set("User-Agent", PLAYER_USER_AGENT)
if err := proxy.Do(c, url, TV.Client); err != nil {
return err
}
Expand Down Expand Up @@ -329,7 +344,7 @@ func RenderKeyHandler(c *fiber.Ctx) error {
c.Request().Header.Set("srno", "230203144000")
c.Request().Header.Set("ssotoken", TV.SsoToken)
c.Request().Header.Set("channelId", channel_id)

c.Request().Header.Set("User-Agent", PLAYER_USER_AGENT)
if err := proxy.Do(c, decoded_url, TV.Client); err != nil {
return err
}
Expand All @@ -346,7 +361,7 @@ func RenderTSHandler(c *fiber.Ctx) error {
utils.Log.Panicln(err)
return err
}

c.Request().Header.Set("User-Agent", PLAYER_USER_AGENT)
if err := proxy.Do(c, decoded_url, TV.Client); err != nil {
return err
}
Expand All @@ -357,9 +372,11 @@ func RenderTSHandler(c *fiber.Ctx) error {
// ChannelsHandler fetch all channels from JioTV API
// Also to generate M3U playlist
func ChannelsHandler(c *fiber.Ctx) error {

quality := strings.TrimSpace(c.Query("q"))
splitCategory := strings.TrimSpace(c.Query("c"))
languages := strings.TrimSpace(c.Query("l"))
skipGenres := strings.TrimSpace(c.Query("sg"))
apiResponse := television.Channels()
// hostUrl should be request URL like http://localhost:5001
hostURL := strings.ToLower(c.Protocol()) + "://" + c.Hostname()
Expand All @@ -375,6 +392,10 @@ func ChannelsHandler(c *fiber.Ctx) error {
continue
}

if skipGenres != "" && utils.ContainsString(television.CategoryMap[channel.Category], strings.Split(skipGenres, ",")) {
continue
}

var channelURL string
if quality != "" {
channelURL = fmt.Sprintf("%s/live/%s/%s.m3u8", hostURL, quality, channel.ID)
Expand All @@ -397,8 +418,7 @@ func ChannelsHandler(c *fiber.Ctx) error {
// Set the Content-Disposition header for file download
c.Set("Content-Disposition", "attachment; filename=jiotv_playlist.m3u")
c.Set("Content-Type", "application/vnd.apple.mpegurl") // Set the video M3U MIME type
c.Response().Header.Set("Cache-Control", "public, max-age=3600")
return c.SendString(m3uContent)
return c.SendStream(strings.NewReader(m3uContent))
}

for i, channel := range apiResponse.Result {
Expand Down Expand Up @@ -470,12 +490,14 @@ func PlaylistHandler(c *fiber.Ctx) error {
quality := c.Query("q")
splitCategory := c.Query("c")
languages := c.Query("l")
return c.Redirect("/channels?type=m3u&q="+quality+"&c="+splitCategory+"&l="+languages, fiber.StatusMovedPermanently)
skipGenres := c.Query("sg")
return c.Redirect("/channels?type=m3u&q="+quality+"&c="+splitCategory+"&l="+languages+"&sg="+skipGenres, fiber.StatusMovedPermanently)
}

// ImageHandler loads image from JioTV server
func ImageHandler(c *fiber.Ctx) error {
url := "https://jiotv.catchup.cdn.jio.com/dare_images/images/" + c.Params("file")
c.Request().Header.Set("User-Agent", REQUEST_USER_AGENT)
if err := proxy.Do(c, url, TV.Client); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/epg/epg.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func GenXMLGz(filename string) error {
if err != nil {
return err
}
// Add XML header
xmlHeader := `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tv SYSTEM "http://www.w3.org/2006/05/tv">`
xml = append([]byte(xmlHeader), xml...)
// write to file
f, err := os.Create(filename)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions pkg/television/television.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ const (
CHANNELS_API_URL = "https://jiotvapi.cdn.jio.com/apis/v3.0/getMobileChannelList/get/?langId=6&os=android&devicetype=phone&usertype=JIO&version=315&langId=6"
)

var (
// DisableTSHandler is used to serve .ts files directly from JioTV Servers
DisableTSHandler = config.Cfg.DisableTSHandler
)

// New function creates a new Television instance with the provided credentials
func New(credentials *utils.JIOTV_CREDENTIALS) *Television {
// Check if credentials are provided
Expand Down Expand Up @@ -252,7 +247,7 @@ func ReplaceM3U8(baseUrl, match []byte, params, channel_id string) []byte {
}

func ReplaceTS(baseUrl, match []byte, params string) []byte {
if DisableTSHandler {
if config.Cfg.DisableTSHandler {
return []byte(string(baseUrl) + string(match) + "?" + params)
}
coded_url, err := secureurl.EncryptURL(string(baseUrl) + string(match) + "?" + params)
Expand All @@ -264,7 +259,7 @@ func ReplaceTS(baseUrl, match []byte, params string) []byte {
}

func ReplaceAAC(baseUrl, match []byte, params string) []byte {
if DisableTSHandler {
if config.Cfg.DisableTSHandler {
return []byte(string(baseUrl) + string(match) + "?" + params)
}
coded_url, err := secureurl.EncryptURL(string(baseUrl) + string(match) + "?" + params)
Expand Down
8 changes: 4 additions & 4 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c3d4b7

Please sign in to comment.