I'm trying to make a badge that says whether or not my Livestream channel is online or offline. I found some javascript that can do this for Twitch channels:
(function() {
var user_name, twitch_widget;
user_name = "nerdist";
twitch_widget = $("#twitch-widget");
twitch_widget.attr("href","http://twitch.tv/" + user_name + "/embed");
$.getJSON('https://api.twitch.tv/kraken/streams/' + user_name + '?client_id=' + '&callback=?', function(data) {
if (data.stream) {
twitch_widget.html("<span class='online'></span><strong> nerdist</strong></br><span class='live'>Online! Playing: " + data.stream.game + "</span>");
} else {
twitch_widget.html("<span class='offline'></span><strong> nerdist</strong></br><span class='notlive'>Offline</span>");
}
});
})();
And I used that to make a functioning badge as seen here: http://codepen.io/EagleJow/pen/GpmGQe
That works great, but I would also like to do this with a Livestream channel and I'm not sure how to go about doing that. I can tell by looking at the javascript that it's able to identify if a channel is online or not by looking at a JSON file on the twitch.tv server.
I'm hoping someone can help me out by tweaking the code to work with a Livestream channel. I've already found out (from here: http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API#Channel_Live_Status) that you can find out a Livestream channel's live status through this xml page:
xChannel Name
x.api.channel.livestream.com/2.0/livestatus.xml
^Replace Channel Name
with the name of the livestream channel.
If the channel is online it will say <ls:isLive>true</ls:isLive>
and if it's offline it'll say <ls:isLive>false</ls:isLive>
My best guess would be something like this:
(function() {
var livestream_widget;
livestream_widget = $("#livestream-widget");
livestream_widget.attr("href","[channel URL]");
$.getXML('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.xml', function(data) {
if (data.stream) {
livestream_widget.html("<span class='online'></span><strong> daytradingradio</strong></br><span class='live'>Online!</span>");
} else {
livestream_widget.html("<span class='offline'></span><strong> daytradingradio</strong></br><span class='notlive'>Offline</span>");
}
});
})();
But I'm not sure what to put instead of "function(data)" and "if (data.stream)". Something like "if (isLive=true)" maybe?
Any help would be appreciated.