-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from rabilrbl/feat/web-epg
feat: Web EPG support and minor optimizations Add new poster route for epg episode posters optimize constants
- Loading branch information
Showing
8 changed files
with
206 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ web/node_modules/ | |
|
||
# Logs | ||
jiotv_go.log | ||
jiotv_go*.log | ||
|
||
# EPG | ||
epg.xml.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/rabilrbl/jiotv_go/v2/pkg/epg" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/fiber/v2/middleware/proxy" | ||
) | ||
|
||
const ( | ||
EPG_POSTER_URL = "https://jiotv.catchup.cdn.jio.com/dare_images/shows/" | ||
) | ||
|
||
// WebEPGHandler responds to requests for EPG data for individual channels. | ||
func WebEPGHandler(c *fiber.Ctx) error { | ||
// Get channel ID from URL | ||
channelID, err := strconv.Atoi(c.Params("channelID")) | ||
if err != nil { | ||
return fiber.NewError(fiber.StatusBadRequest, "Invalid channel ID") | ||
} | ||
|
||
// Get offset from URL | ||
offset, err := strconv.Atoi(c.Params("offset")) | ||
if err != nil { | ||
return fiber.NewError(fiber.StatusBadRequest, "Invalid offset") | ||
} | ||
|
||
url := fmt.Sprintf(epg.EPG_URL, offset, channelID) | ||
if err := proxy.Do(c, url, TV.Client); err != nil { | ||
return err | ||
} | ||
|
||
c.Response().Header.Del(fiber.HeaderServer) | ||
return nil | ||
} | ||
|
||
// PosterHandler loads image from JioTV server | ||
func PosterHandler(c *fiber.Ctx) error { | ||
// catch all params | ||
fmt.Println(c.Params("*")) | ||
url := EPG_POSTER_URL + c.Params("date") + "/" + c.Params("file") | ||
if err := proxy.Do(c, url, TV.Client); err != nil { | ||
return err | ||
} | ||
c.Response().Header.Del(fiber.HeaderServer) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
function getCurrentAndNextTwoShows(epgData) { | ||
const currentTime = new Date(); // Current date time | ||
const shows = []; | ||
let currentIndex = -1; | ||
|
||
// Find the currently playing show | ||
epgData.epg.some((show, index) => { | ||
const showStartTime = new Date(show.startEpoch); | ||
const showEndTime = new Date(show.endEpoch); | ||
|
||
if (showStartTime <= currentTime && currentTime < showEndTime) { | ||
const { showname, description, endEpoch, episodePoster, keywords } = show; | ||
shows.push({ showname, description, endEpoch, episodePoster, keywords }); | ||
currentIndex = index; | ||
return true; // Stop iterating after finding the current show | ||
} | ||
return false; | ||
}); | ||
|
||
// Get the next two shows | ||
if (currentIndex !== -1) { | ||
const nextTwoShows = epgData.epg.slice(currentIndex + 1, currentIndex + 3); | ||
nextTwoShows.forEach(show => { | ||
const { showname, description, endEpoch, episodePoster, keywords } = show; | ||
shows.push({ showname, description, endEpoch, episodePoster, keywords }); | ||
}); | ||
} | ||
|
||
return shows; | ||
} | ||
|
||
const url = new URL(window.location.href); | ||
// do regex to get channelID | ||
const channelID = url.pathname.match(/\/play\/(.*)/)[1]; | ||
const offset = 0; | ||
|
||
|
||
function updateEPG(epgData) { | ||
const shows = getCurrentAndNextTwoShows(epgData); | ||
const shownameElement = document.getElementById('showname'); | ||
const descriptionElement = document.getElementById('description'); | ||
const episodePosterElement = document.getElementById('episodePoster'); | ||
shownameElement.innerHTML = shows[0].showname + shownameElement.innerHTML; | ||
descriptionElement.innerText = shows[0].description; | ||
const posterUrl = new URL("/jtvposter/", window.location.href); | ||
posterUrl.pathname += shows[0].episodePoster; | ||
episodePosterElement.src = posterUrl.href; | ||
|
||
const keywordsElement = document.getElementById('keywords'); | ||
const keywords = shows[0].keywords; | ||
keywords.forEach((keyword) => { | ||
const keywordElement = document.createElement('div'); | ||
keywordElement.className = 'badge badge-outline'; | ||
keywordElement.innerText = keyword; | ||
keywordsElement.appendChild(keywordElement); | ||
}); | ||
|
||
const e_hour = document.getElementById('e_hour'); | ||
const e_minute = document.getElementById('e_minute'); | ||
const e_second = document.getElementById('e_second'); | ||
|
||
const endEpochTime = shows[0].endEpoch; | ||
function updateTimer() { | ||
const currentTime = new Date().getTime(); | ||
const difference = endEpochTime - currentTime; | ||
|
||
if (difference <= 0) { | ||
clearInterval(timerInterval); | ||
updateEPG(); | ||
return; | ||
} | ||
|
||
const differenceDate = new Date(difference); | ||
const hours = differenceDate.getUTCHours(); | ||
const minutes = differenceDate.getUTCMinutes(); | ||
const seconds = differenceDate.getUTCSeconds(); | ||
|
||
|
||
if (hours === 0) { | ||
document.getElementById('countdown_hour').style.display = 'none'; | ||
} else { | ||
e_hour.setAttribute('style', `--value:${hours.toString().padStart(2, '0')};`); | ||
} | ||
if (hours === 0 && minutes === 0) { | ||
document.getElementById('countdown_minute').style.display = 'none'; | ||
} else { | ||
e_minute.setAttribute('style', `--value:${minutes.toString().padStart(2, '0')};`); | ||
} | ||
e_second.setAttribute('style', `--value:${seconds.toString().padStart(2, '0')};`); | ||
} | ||
|
||
// Initial call to update the timer | ||
updateTimer(); | ||
|
||
// Set the interval to update the timer every second | ||
const timerInterval = setInterval(updateTimer, 1000); | ||
} | ||
|
||
const epgParent = document.getElementById('epg_parent'); | ||
epgParent.style.display = 'none'; | ||
|
||
(async () => { | ||
const epgResponse = await fetch(`/epg/${channelID}/${offset}`); | ||
|
||
if (!epgResponse.ok) { | ||
console.error('Failed to fetch EPG data'); | ||
return; | ||
} | ||
|
||
const epgData = await epgResponse.json(); | ||
epgParent.style.display = 'block'; | ||
updateEPG(epgData); | ||
})(); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters