Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix Release Sep 9 2024 #411

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func LoginRefreshAccessToken() error {
// Prepare the request body
requestBody := map[string]string{
"appName": "RJIL_JioTV",
"deviceId": "6fcadeb7b4b10d77",
"deviceId": utils.GetDeviceID(),
"refreshToken": tokenData.RefreshToken,
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func LoginRefreshSSOToken() error {
req.Header.Set("User-Agent", "okhttp/4.2.2")
req.Header.Set("ssoToken", tokenData.SSOToken)
req.Header.Set("uniqueid", tokenData.UniqueID)
req.Header.Set("deviceid", "6fcadeb7b4b10d77")
req.Header.Set("deviceid",utils.GetDeviceID())

// Send the request
resp := fasthttp.AcquireResponse()
Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/drm.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func DRMKeyHandler(c *fiber.Ctx) error {
c.Request().Header.Set("devicetype", "phone")
c.Request().Header.Set("Accept-Encoding", "gzip, deflate")
c.Request().Header.Set("osVersion", "13")
c.Request().Header.Set("deviceId", "b6985e8cf2401d35")
c.Request().Header.Set("deviceId", utils.GetDeviceID())
c.Request().Header.Set("Content-Type", "application/octet-stream")

// Delete User-Agent header from the request
Expand Down
3 changes: 3 additions & 0 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func Init() {
if DisableTSHandler {
utils.Log.Println("TS Handler disabled!. All TS video requests will be served directly from JioTV servers.")
}
err := utils.GenerateRandomString(); if err != nil {
utils.Log.Println("Error generating random string", err)
}
// Get credentials from file
credentials, err := utils.GetJIOTVCredentials()
// Initialize TV object with nil credentials
Expand Down
3 changes: 2 additions & 1 deletion pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var KVS *TomlStore
// Init initializes the TOML file, creates if not exist, otherwise reads and decodes to struct.
func Init() error {
KVS = &TomlStore{}
filename := filepath.Join(GetPathPrefix(), "store_v2.toml")
// store_vX.toml, where X is changed whenever new version requires re-login
filename := filepath.Join(GetPathPrefix(), "store_v3.toml")

KVS.mu.Lock()
defer KVS.mu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/television/television.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func New(credentials *utils.JIOTV_CREDENTIALS) *Television {
"channel_id": "",
"crmid": credentials.CRM,
"userId": credentials.CRM,
"deviceId": "e4286d7b481d69b8",
"deviceId": utils.GetDeviceID(),
"devicetype": "phone",
"isott": "false",
"languageId": "6",
Expand Down
36 changes: 36 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package utils

import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"log"
Expand Down Expand Up @@ -324,6 +326,28 @@ func GetPathPrefix() string {
return store.GetPathPrefix()
}

// GetDeviceID returns the device ID
func GetDeviceID() string {
deviceID, err := store.Get("deviceId")
if err != nil {
Log.Println(err)
err = GenerateRandomString()
if err != nil {
Log.Println(err)
return ""
}
deviceID, err = store.Get("deviceId")
if deviceID == "" {
Log.Println("Device ID is empty")
return ""
} else if err != nil {
Log.Println(err)
return ""
}
}
return deviceID
}

// GetJIOTVCredentials return credentials from environment variables or credentials file
// Important note: If credentials are provided from environment variables, they will be used instead of credentials file
func GetJIOTVCredentials() (*JIOTV_CREDENTIALS, error) {
Expand Down Expand Up @@ -533,3 +557,15 @@ func ContainsString(item string, slice []string) bool {
}
return false
}

// GenerateRandomString generates a random 16-character hexadecimal string.
func GenerateRandomString() error {
bytes := make([]byte, 8) // 8 bytes will result in a 16-character hex string
if _, err := rand.Read(bytes); err != nil {
return err
}
if _, err := store.Get("deviceId"); err != nil {
store.Set("deviceId", hex.EncodeToString(bytes))
}
return nil
}
Loading