Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- showsVIC = {};
- showsNSW = {};
- showsQLD = {};
- showsSA = {};
- showsWA = {};
- //ORDER:
- // 1. Load page
- // 2. Create channel objects
- // 3. Load guide data
- // 4. Display guide/channels
- // Channel Class //
- function Channel(name, URLs) {
- this.name = name;
- this.URLs = URLs;
- this.currentShows = {VIC:"", NSW:"", QLD:"", SA:"", WA:""};
- this.onNow;
- }
- Channel.prototype = {
- getName:function () {
- return this.name;
- },
- getIconName:function () {
- return this.name + ".png";
- },
- getURLForState:function (state) {
- return this.URLs[state];
- },
- setCurrentShowsForState:function (currentShows, state) {
- this.currentShows[state] = currentShows;
- },
- getCurrentShowsForState:function (state) {
- return this.currentShows[state];
- },
- setOnNow:function (onNow) {
- this.onNow = onNow;
- },
- getOnNow:function () {
- return this.onNow;
- }
- }
- // Function to initalise all channels //
- function createChannels() {
- chABC = new Channel("ABC", {
- VIC:"https://abctvlivehls-lh.akamaihd.net/i/abc1_1@360323/master.m3u8",
- NSW:"https://abctvlivehls-lh.akamaihd.net/i/abc1_1@360323/master.m3u8",
- QLD:"https://abctvlivehls-lh.akamaihd.net/i/abc1_1@360323/master.m3u8",
- SA:"https://abctvlivehls-lh.akamaihd.net/i/abc1_1@360323/master.m3u8",
- WA:"https://abctvlivehls-lh.akamaihd.net/i/abc1_1@360323/master.m3u8"
- });
- chSBS = new Channel("SBS", {
- VIC:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs1-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- NSW:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs1-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- QLD:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs1-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- SA:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs1-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- WA:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs1-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8"
- });
- ch7 = new Channel("7", {
- VIC:"https://melbourneseven-i.akamaihd.net/hls/live/263658/MEL1/master.m3u8",
- NSW:"https://sydneyseven-i.akamaihd.net/hls/live/263630/SYD1/master.m3u8",
- QLD:"https://brisbaneseven-i.akamaihd.net/hls/live/263663/BRI1/master.m3u8",
- SA:"https://adelaideseven-i.akamaihd.net/hls/live/263667/ADE1/master.m3u8",
- WA:"https://perthseven-i.akamaihd.net/hls/live/263674/PER1/master.m3u8"
- });
- ch9 = new Channel("9", {
- VIC:"https://9nowch9livehls-i.akamaihd.net/hls/live/250962/melbourne/master.m3u8",
- NSW:"https://9nowch9livehls-i.akamaihd.net/hls/live/250964/sydney/master.m3u8",
- QLD:"https://9nowch9livehls-i.akamaihd.net/hls/live/250961/brisbane/master.m3u8",
- SA:"https://9nowch9livehls-i.akamaihd.net/hls/live/250960/adelaide/master.m3u8",
- WA:"https://9nowch9livehls-i.akamaihd.net/hls/live/250963/perth/master.m3u8"
- });
- ch10 = new Channel("10", {
- VIC:"http://csm-e.cds1.yospace.com/csm/extlive/networkten01,SDATV.m3u8",
- NSW:"http://csm-e.cds1.yospace.com/csm/extlive/networkten01,SDTEN.m3u8",
- QLD:"http://csm-e.cds1.yospace.com/csm/extlive/networkten01,SDTVQ.m3u8",
- SA:"http://csm-e.cds1.yospace.com/csm/extlive/networkten01,SDADS.m3u8",
- WA:"http://csm-e.cds1.yospace.com/csm/extlive/networkten01,SDNEW.m3u8"
- });
- chABC2 = new Channel("ABC2", {
- VIC:"https://abctvlivehls-lh.akamaihd.net/i/abckids_1@327097/master.m3u8",
- NSW:"https://abctvlivehls-lh.akamaihd.net/i/abckids_1@327097/master.m3u8",
- QLD:"https://abctvlivehls-lh.akamaihd.net/i/abckids_1@327097/master.m3u8",
- SA:"https://abctvlivehls-lh.akamaihd.net/i/abckids_1@327097/master.m3u8",
- WA:"https://abctvlivehls-lh.akamaihd.net/i/abckids_1@327097/master.m3u8"
- });
- chABCME = new Channel("ABCME", {
- VIC:"https://abctvlivehls-lh.akamaihd.net/i/abc3_1@332134/master.m3u8",
- NSW:"https://abctvlivehls-lh.akamaihd.net/i/abc3_1@332134/master.m3u8",
- QLD:"https://abctvlivehls-lh.akamaihd.net/i/abc3_1@332134/master.m3u8",
- SA:"https://abctvlivehls-lh.akamaihd.net/i/abc3_1@332134/master.m3u8",
- WA:"https://abctvlivehls-lh.akamaihd.net/i/abc3_1@332134/master.m3u8"
- });
- chABCNews = new Channel("ABCNews", {
- VIC:"https://abcnews24hls-lh.akamaihd.net/i/news24_1@3259/master.m3u8",
- NSW:"https://abcnews24hls-lh.akamaihd.net/i/news24_1@3259/master.m3u8",
- QLD:"https://abcnews24hls-lh.akamaihd.net/i/news24_1@3259/master.m3u8",
- SA:"https://abcnews24hls-lh.akamaihd.net/i/news24_1@3259/master.m3u8",
- WA:"https://abcnews24hls-lh.akamaihd.net/i/news24_1@3259/master.m3u8"
- });
- chSBSViceland = new Channel("SBSViceland", {
- VIC:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs2-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- NSW:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs2-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- QLD:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs2-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- SA:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs2-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- WA:"http://sbslivefvstreaming.sbs.com.au/out/u/sbs2-mo-000-c3093-delpkg1-delpkg1-abr/index-root-ipad.m3u8"
- });
- chSBSFood = new Channel("SBSFood", {
- VIC:"http://sbslivefvstreaming.sbs.com.au/out/u/fdnet-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- NSW:"http://sbslivefvstreaming.sbs.com.au/out/u/fdnet-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- QLD:"http://sbslivefvstreaming.sbs.com.au/out/u/fdnet-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- SA:"http://sbslivefvstreaming.sbs.com.au/out/u/fdnet-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- WA:"http://sbslivefvstreaming.sbs.com.au/out/u/fdnet-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8"
- });
- chNITV = new Channel("NITV", {
- VIC:"http://sbslivefvstreaming.sbs.com.au/out/u/nitv-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- NSW:"http://sbslivefvstreaming.sbs.com.au/out/u/nitv-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- QLD:"http://sbslivefvstreaming.sbs.com.au/out/u/nitv-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- SA:"http://sbslivefvstreaming.sbs.com.au/out/u/nitv-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8",
- WA:"http://sbslivefvstreaming.sbs.com.au/out/u/nitv-mo-000-c3094-delpkg1-delpkg1-abr/index-root-ipad.m3u8"
- });
- ch7TWO = new Channel("7TWO", {
- VIC:"https://melbourneseven-i.akamaihd.net/hls/live/263659/MEL2/master.m3u8",
- NSW:"https://sydneyseven-i.akamaihd.net/hls/live/263631/SYD2/master.m3u8",
- QLD:"https://brisbaneseven-i.akamaihd.net/hls/live/263664/BRI2/master.m3u8",
- SA:"https://adelaideseven-i.akamaihd.net/hls/live/263668/ADE2/master.m3u8",
- WA:"https://perthseven-i.akamaihd.net/hls/live/263675/PER2/master.m3u8"
- });
- ch7mate = new Channel("7mate", {
- VIC:"https://melbourneseven-i.akamaihd.net/hls/live/263661/MEL3/master.m3u8",
- NSW:"https://sydneyseven-i.akamaihd.net/hls/live/263632/SYD3/master.m3u8",
- QLD:"https://brisbaneseven-i.akamaihd.net/hls/live/263665/BRI3/master.m3u8",
- SA:"https://adelaideseven-i.akamaihd.net/hls/live/263669/ADE3/master.m3u8",
- WA:"https://perthseven-i.akamaihd.net/hls/live/263676/PER3/master.m3u8"
- });
- ch7flix = new Channel("7flix", {
- VIC:"https://melbourneseven-i.akamaihd.net/hls/live/263662/MEL6/master.m3u8",
- NSW:"https://sydneyseven-i.akamaihd.net/hls/live/263634/SYD6/master.m3u8",
- QLD:"https://brisbaneseven-i.akamaihd.net/hls/live/263666/BRI6/master.m3u8",
- SA:"https://adelaideseven-i.akamaihd.net/hls/live/263670/ADE6/master.m3u8",
- WA:"https://perthseven-i.akamaihd.net/hls/live/263677/PER6/master.m3u8"
- });
- ch9Gem = new Channel("9Gem", {
- VIC:"https://9nowgemlivehls-i.akamaihd.net/hls/live/250972/melbourne/master.m3u8",
- NSW:"https://9nowgemlivehls-i.akamaihd.net/hls/live/250974/sydney/master.m3u8",
- QLD:"https://9nowgemlivehls-i.akamaihd.net/hls/live/250971/brisbane/master.m3u8",
- SA:"https://9nowgemlivehls-i.akamaihd.net/hls/live/250970/adelaide/master.m3u8",
- WA:"https://9nowgemlivehls-i.akamaihd.net/hls/live/250973/perth/master.m3u8"
- });
- ch9Go = new Channel("9Go", {
- VIC:"https://9nowgolivehls-i.akamaihd.net/hls/live/250977/melbourne/master.m3u8",
- NSW:"https://9nowgolivehls-i.akamaihd.net/hls/live/250987/sydney/master.m3u8",
- QLD:"https://9nowgolivehls-i.akamaihd.net/hls/live/250976/brisbane/master.m3u8",
- SA:"https://9nowgolivehls-i.akamaihd.net/hls/live/250975/adelaide/master.m3u8",
- WA:"https://9nowgolivehls-i.akamaihd.net/hls/live/250978/perth/master.m3u8"
- });
- ch9Life = new Channel("9Life", {
- VIC:"https://9nowlifelivehls-i.akamaihd.net/hls/live/250992/melbourne/master.m3u8",
- NSW:"https://9nowlifelivehls-i.akamaihd.net/hls/live/250994/sydney/master.m3u8",
- QLD:"https://9nowlifelivehls-i.akamaihd.net/hls/live/250991/brisbane/master.m3u8",
- SA:"https://9nowlifelivehls-i.akamaihd.net/hls/live/250990/adelaide/master.m3u8",
- WA:"https://9nowlifelivehls-i.akamaihd.net/hls/live/250993/perth/master.m3u8"
- });
- chRacing = new Channel("Racing", {
- VIC:"https://melbourneseven-i.akamaihd.net/hls/live/263815/RAC/master.m3u8",
- NSW:"https://melbourneseven-i.akamaihd.net/hls/live/263815/RAC/master.m3u8",
- QLD:"https://melbourneseven-i.akamaihd.net/hls/live/263815/RAC/master.m3u8",
- SA:"https://melbourneseven-i.akamaihd.net/hls/live/263815/RAC/master.m3u8",
- WA:"https://melbourneseven-i.akamaihd.net/hls/live/263815/RAC/master.m3u8"
- });
- channels = [chABC, chSBS, ch7, ch9, ch10, chABC2, chABCME, chABCNews, chSBSViceland, chSBSFood, chNITV, ch7TWO, ch7mate, ch7flix, ch9Gem, ch9Go, ch9Life, chRacing];
- console.log("Successfully created channels");
- return channels;
- }
- // Create guide divs //
- function createGuideDivs() {
- for (channel in channels) {
- //var newGuideChannel = $(".guide").clone();
- //newGuideChannel.attr("id", "ch" + channels[channel].getName())
- var template = [
- '<li class="container guide" id="' + channels[channel].getName() + '">',
- '<div class="logoCol">',
- '<img class="channelLogo" src="Icons/' + channels[channel].getIconName() + '" alt="' + channels[channel].getName() + '">',
- '</div>',
- '<div class="currentShowCol">',
- '<div class="showTime"></div>',
- '<div class="showTitle">' + channels[channel].getName() + '</div>',
- '<div class="showSubtitle"></div>',
- '</div>',
- '<div class="nextShowCol">',
- '<div class="showTime"></div>',
- '<div class="showTitle"></div>',
- '<div class="showSubtitle"></div>',
- '</div>',
- '</li>'
- ].join("\n");
- $(".guideList").append(template);
- }
- }
- jQuery(document).ready(function($) {
- currentHeader = Math.floor(Math.random() * (2 - 0)) - 1;
- randomHeader();
- channels = createChannels();
- createGuideDivs();
- loadGuide();
- try {
- if (localStorage["state"]) {
- var state = localStorage["state"];
- $(".current-state").text(state);
- } else {
- localStorage["state"] = "VIC";
- $(".current-state").text(localStorage["state"]);
- }
- if (localStorage["channel"]) {
- if (localStorage["channel"].slice(0,2) != "ch") {
- localStorage["channel"] = "ch" + localStorage["channel"]
- }
- } else {
- localStorage["channel"] = "ch7";
- }
- channel = window[localStorage["channel"]];
- loadVideo(channel);
- updateVideoInfo();
- } catch (e) {
- console.log("Error when reading from local storage. Probably in private mode.\n" + e);
- }
- //When the user clicks on a state, change the saved state and load the stream for that state
- $(".state").click(function() {
- var state = $(this).text();
- localStorage["state"] = state;
- $(".current-state").text(state);
- var channelToLoad = window[localStorage["channel"]];
- loadVideo(channelToLoad);
- loadGuide();
- });
- //When the user clicks on the guide, load the selected channel
- $(".guide").click(function() {
- channelName = "ch" + $(this).attr("id");
- localStorage["channel"] = channelName;
- var channelToLoad = window[localStorage["channel"]];
- loadVideo(channelToLoad);
- updateVideoInfo();
- });
- //When the user clicks on the header, change the font
- $(".title").click(function() {
- randomHeader();
- });
- window.onclick = function(event) {
- if (!event.target.matches('.current-state')) {
- var dropdowns = document.getElementsByClassName("dropdown-content");
- var i;
- for (i = 0; i < dropdowns.length; i++) {
- var openDropdown = dropdowns[i];
- if (openDropdown.classList.contains('show')) {
- openDropdown.classList.remove('show');
- }
- }
- }
- }
- loadGuide();
- });
- function randomHeader() {
- headers = ["headerOriginal", "headerBlond", "headerTLOP"];
- if (currentHeader < 2) {
- currentHeader ++;
- } else {
- currentHeader = 0;
- }
- if (currentHeader < 2) {
- $(".title").html("<h1 id='" + headers[currentHeader] + "'>Streamee</h1>");
- } else {
- $(".title").html("<img src='/Fonts/TLOP.png' class='headerLogo'>");
- }
- }
- function updateVideoInfo() {
- currentChannel = localStorage["channel"];
- currentShow = window[currentChannel].getOnNow();
- try {
- $(".iShowTitle").text(currentShow.name);
- $(".iShowSubtitle").text(currentShow.subtitle);
- $(".iShowDesc").text(currentShow.description);
- } catch (e) {
- $(".iShowTitle").text(window[currentChannel].getName());
- $(".iShowSubtitle").text("");
- $(".iShowDesc").text("");
- }
- }
- function getCurrentStream() {
- var player = videojs('video');
- }
- function playStream(stream) {
- $('.videocontent video source').attr('src', stream);
- $(".videocontent video")[0].load();
- var player = videojs('video');
- player.pause();
- player.src({ type: "application/x-mpegURL", src: stream });
- player.load();
- player.play();
- }
- function loadVideo(channelToLoad) {
- if (channelToLoad) {
- var stream = channelToLoad.getURLForState(localStorage["state"]);
- if (channelToLoad.name.includes("ABC")) {
- var player = videojs('video');
- player.pause();
- //need to get token - ugh
- var token = 'L$#_rR7}K3IaB';
- var tokenURL = 'https://freeview-fv.global.ssl.fastly.net/288/epgApi/getToken?region=Melbourne&network=ABC&channel_id=101002210221&format=html&token=L$%23_rR7}K3IaB';
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
- playStream(stream + '?' + xmlHttp.responseText);
- }
- }
- xmlHttp.open("GET", tokenURL, true); // true for asynchronous
- xmlHttp.send(null);
- } else {
- playStream(stream);
- }
- }
- }
- function toggleDropdown() {
- document.getElementById("myDropdown").classList.toggle("show");
- }
- function loadGuide() {
- date = new Date($.now()); //get current time/date
- JSONfile = "Guide/" + getDate() + ".json"
- $.getJSON(JSONfile, function( data ) {
- $.each( data, function( key, val ) {
- if (key == "VIC") {
- showsVIC = val;
- } else if (key == "NSW") {
- showsNSW = val;
- } else if (key == "QLD") {
- showsQLD = val;
- } else if (key == "SA") {
- showsSA = val;
- } else if (key == "WA") {
- showsWA = val;
- }
- });
- saveGuideData();
- getCurrentShows();
- setInterval(getCurrentShows, 60*1000);
- });
- }
- function saveGuideData() {
- for (channel in channels) {
- channels[channel].setCurrentShowsForState(showsVIC[channels[channel].getName()], "VIC");
- channels[channel].setCurrentShowsForState(showsNSW[channels[channel].getName()], "NSW");
- channels[channel].setCurrentShowsForState(showsQLD[channels[channel].getName()], "QLD");
- channels[channel].setCurrentShowsForState(showsSA[channels[channel].getName()], "SA");
- channels[channel].setCurrentShowsForState(showsWA[channels[channel].getName()], "WA");
- }
- console.log("Guide data saved to channels");
- }
- function convertDate(date) {
- //var myDate = "20161029140000";
- year = date.slice(0,4);
- month = parseInt(date.slice(4,6));
- day = date.slice(6,8);
- hour = date.slice(8,10);
- minutes = date.slice(10,12);
- tz = date.slice(15,20);
- //date = new Date(year, month, day, hour, minutes);
- newDate = new Date(month + '/' + day + '/' + year + ' ' + hour + ':' + minutes + ':00 UTC')
- return newDate;
- }
- function getCurrentShows() {
- console.log("Getting current shows");
- currentDate = new Date($.now()); //get current time/date
- var state = localStorage["state"];
- for (channel in channels) {
- showList = channels[channel].getCurrentShowsForState(state);
- for (show in showList) {
- showDate = convertDate(showList[show].start_time);
- if (showDate > currentDate) {
- channels[channel].setOnNow(showList[show-1]);
- channelName = channels[channel].getName();
- currentShow = showList[show-1];
- nextShow = showList[show];
- //Convert the start/end times to readable HH:MM am/pm format
- cShowStart = convertDate(showList[show-1].start_time).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'});
- cShowEnd = convertDate(showList[show-1].end_time).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'});
- nShowStart = showDate.toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'});
- nShowEnd = convertDate(showList[show].end_time).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'});
- //Create the show time strings
- cShowTime = cShowStart + " - " + cShowEnd;
- nShowTime = nShowStart + " - " + nShowEnd;
- $("#" + channelName + " > .currentShowCol > .showTitle").text(currentShow.name);
- $("#" + channelName + " > .currentShowCol > .showTime").text(cShowTime);
- $("#" + channelName + " > .nextShowCol > .showTitle").text(nextShow.name);
- $("#" + channelName + " > .nextShowCol > .showTime").text(nShowTime);
- if (currentShow.subtitle == "") {
- $("#" + channelName + " > .currentShowCol > .showSubtitle").html(" ");
- //$("tr.clickable-row#" + channels[channel] + " > td.currentShow > ul > li.showSubtitle").html("");
- } else {
- $("#" + channelName + " > .currentShowCol > .showSubtitle").text(currentShow.subtitle);
- //$("tr.clickable-row#" + channels[channel] + " > td.currentShow > ul > li.showSubtitle").text(currentShow.subtitle);
- }
- if (nextShow.subtitle == "") {
- $("#" + channelName + " > .nextShowCol > .showSubtitle").html(" ");
- //$("tr.clickable-row#" + channels[channel] + " > td.nextShow > ul > li.showSubtitle").html(" ");
- } else {
- $("#" + channelName + " > .nextShowCol > .showSubtitle").text(nextShow.subtitle);
- //$("tr.clickable-row#" + channels[channel] + " > td.nextShow > ul > li.showSubtitle").text(nextShow.subtitle);
- }
- break;
- }
- }
- }
- updateVideoInfo();
- }
- function getDate() {
- var date = new Date();
- var year = date.getFullYear();
- var month = String(date.getMonth() + 1);
- var day = String(date.getDate());
- if (month.length < 2) {
- month = "0".concat(month);
- }
- if (day.length < 2) {
- day = "0".concat(day);
- }
- return [year, month, day].join('-');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement