2015-10-07 1 views
0

J'essaie de créer un badge indiquant si mon canal Livestream est en ligne ou hors ligne. J'ai trouvé javascript qui peut le faire pour les canaux Twitch:Utilisation de données XML et Javascript pour créer un badge Livestream en ligne/hors ligne

(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>"); 
     } 
    }); 

})(); 

Et je que pour faire un badge qui fonctionne comme on le voit ici: http://codepen.io/EagleJow/pen/GpmGQe

Cela fonctionne très bien, mais je voudrais aussi faire avec un canal Livestream et je ne suis pas sûr de savoir comment y arriver. Je peux dire en regardant le javascript qu'il est capable d'identifier si une chaîne est en ligne ou non en regardant un fichier JSON sur le serveur twitch.tv. Je souhaite que quelqu'un puisse m'aider en modifiant le code pour travailler avec un canal Livestream. Je l'ai déjà découvert (d'ici: http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API#Channel_Live_Status) que vous pouvez trouver un statut direct de canal Livestream à travers cette page xml: x Channel Name x.api.channel.livestream.com/2.0/livestatus.xml

^Remplacez Channel Name par le nom du canal livestream.

Si le canal est en ligne, il dira <ls:isLive>true</ls:isLive> et si c'est déconnecté ça va dire <ls:isLive>false</ls:isLive>

Ma meilleure estimation serait quelque chose comme ceci:

(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>"); 
     } 
    }); 

})(); 

Mais je ne sais pas quoi mettre à la place de "function (data)" et "if (data.stream)". Quelque chose comme "if (isLive = true)" peut-être?

Toute aide serait appréciée.

+0

En regardant cette page: http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API#Channel_Live_Status Je peux voir qu'il est possible d'utiliser JSON au lieu de XML. Je ne sais pas si cela fonctionnerait mieux ou non. Aussi ce fil semble très similaire, mais je ne sais toujours pas comment l'implémenter dans le code que j'utilise: http://stackoverflow.com/questions/7020357/can-someone-help-me-with-using- livestreams-api-faire-un-cross-domain-xml-reque –

Répondre

0
(function() { 

    var livestream_widget; 

    livestream_widget = $("#livestream-widget"); 

    livestream_widget.attr("href","[channelurl]"); 
    $.getJSON('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.json?callback=?', function(data) { 

     if (data.channel.isLive === true) { 

      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>"); 
     } 
    }); 

})();