Skip to content

Commit

Permalink
use host from the browser to generate playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuman852 committed May 28, 2023
1 parent b8497e6 commit 4372810
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 5 additions & 2 deletions routes/ip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ router.post("/ip", (req, res) => {
});

router.get("/ip", async (req, res) => {
// console.log(req.originalUrl);
const host = req.get("host");
const protocol = req.protocol;
const BASE_URL = `${protocol}://${host}`;
console.log(req.originalUrl);
if (req.query.type == "getServerIp" && req.query.auth == "141204") {
let ipData = await fetch("http://ip-api.com/json");
return res.send(await ipData.json());
Expand All @@ -24,7 +27,7 @@ router.get("/ip", async (req, res) => {
flag: "r",
});
} else {
ipdata = "127.0.0.1";
ipdata = BASE_URL;
}
res.status(200).send({ ip: ipdata, port: port });
});
Expand Down
15 changes: 13 additions & 2 deletions routes/playlist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const PORT = process.env.PORT || 3500;
const pwd=process.cwd();
router.get("/playlist", async (req, res) => {
res.contentType("application/vnd.apple.mpegurl");
// get current hostname
const host = req.get("host");
// get http or https
const protocol = req.protocol;
const BASE_URL = `${protocol}://${host}`;
let ip;
if (fs["existsSync"]("ipData.jiotv")) {
ip = fs["readFileSync"]("ipData.jiotv", {
Expand All @@ -20,12 +25,18 @@ router.get("/playlist", async (req, res) => {
} else {
ip = "127.0.0.1";
}
const playlistData = await playlist(`${ip}:${PORT}`);
const playlistData = await playlist(BASE_URL);
res.status(200).send(playlistData);
});

router.get("/playlist/download", async (req, res) => {
res.contentType("application/vnd.apple.mpegurl");
// get current hostname
const host = req.get("host");
// get http or https
const protocol = req.protocol;
// print full url
const BASE_URL = `${protocol}://${host}`;
res.setHeader(
"Content-Disposition",
"attachment; filename=" + "playlist.m3u8"
Expand All @@ -40,7 +51,7 @@ router.get("/playlist/download", async (req, res) => {
ip = "127.0.0.1";
}

const playlistData = await playlist(`${ip}:${PORT}`);
const playlistData = await playlist(BASE_URL);
res.status(200).send(playlistData);
});

Expand Down
2 changes: 1 addition & 1 deletion utils/genPlaylist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async function genPlaylist(url) {
// fs
let response = await playlist();

const ServerUrl = `http://${url}`;
const ServerUrl = `${url}`;
for (let resData of response["result"]) {
const channel_name = resData["channel_name"];
const channelLogoUrl = "https://jiotv.catchup.cdn.jio.com/dare_images/images/" + resData["logoUrl"];
Expand Down

0 comments on commit 4372810

Please sign in to comment.