nickmcski

twitch live

Aug 22nd, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. ======livestream.php=====
  2. <?php
  3. include_once("teamspeak.php");
  4. include_once("include/announcement.php");
  5. $dark =isset($_GET['dark']);
  6. ?>
  7. <html>
  8. <head>
  9. <meta charset="utf-8">
  10. <title>Rlscraft Livesteam</title>
  11. <link type="text/css" rel="stylesheet" href="bootstrap/dist/css/bootstrap.css" />
  12. <link type="text/css" rel="stylesheet" href="css/main.css" />
  13. <link rel="shortcut icon" href="favicon.png">
  14. </head>
  15.  
  16. <body <? echo ($dark ? "style ='background-color:#555;'" : "     " )?>>
  17. <div id="wrapper">
  18. <?php include_once("include/analyticstracking.php") ?>
  19.  
  20.  
  21.       <?php
  22.         include_once("include/navbar.php");
  23.         include_once("include/footer.php");
  24. makeNewNav(basename(__FILE__), $dark);
  25. ?>
  26. <div class="container theme-showcase">
  27.       <? echo getMessage(); ?>
  28.  
  29. <?
  30. include "include/twitch_api.php";
  31.  
  32. function isStreaming($name){
  33.     $streams = json_decode(get_url_contents("https://api.twitch.tv/kraken/streams/" . $name));
  34.  
  35.     //print_r($streams);
  36.     //echo $streams -> stream;
  37.     if($streams -> stream == NULL){
  38.         $streaming = false;
  39.         //echo "false!!";
  40.     }else{
  41.         $streaming = true;
  42.         //echo "true!!!";
  43.     }
  44.     return $streaming;
  45.  
  46.  
  47. }
  48.  
  49.     $channels =array();
  50.     array_push($channels, "rlhl83", "xbossxs", "kh11601", "LoungeGaming");
  51.     $live = array();
  52.     $i = 0;
  53.     foreach($channels as $name){
  54.        
  55.         $streaming = isStreaming($name);
  56.         if($streaming){
  57.             $i++;
  58.             //echo "HE IS LIVE!";
  59.             array_push($live, $name);
  60.         }else{
  61.             //echo " He if offline!";
  62.         }
  63.     }
  64.     $width = "620";
  65.     $chatHeight = "400";
  66.     $videoHeight = "400";
  67.    
  68.     $multiple_streams = ($i == 1 ? "is " : "are ");
  69.     echo "<center><h3>There " . $multiple_streams . $i . " Channel" . ($i != 1 ? "s " : "") . "live</h3></center>";
  70.    
  71.     echo "<center><table> <tr>";
  72.     foreach($live as $name){
  73.         //echo "<br>" . $name . " Is live";
  74.         echo "<td> " . $name . " </td>";
  75.    
  76.     }
  77.     echo "</tr><tr>";
  78.     foreach($live as $name){
  79.     echo "<td>";
  80.         if($live[0] == $name){
  81.             video($name, $videoHeight, $width);
  82.         }else{
  83.             video($name, $videoHeight, $width, 0);
  84.         }
  85.         //echo "<br>" . $name . " Is live";
  86.        
  87.        
  88.         echo "</td>";
  89.     }
  90.     echo "</tr><tr>";  
  91.     foreach($live as $name){
  92.         //echo "<br>" . $name . " Is live";
  93.         chat($name, $chatHeight, $width);
  94.    
  95.     }  
  96.     echo "</tr></table></center>";
  97. ?>
  98. </div>
  99.  
  100.     <script src="bootstrap/assets/js/jquery.js"></script>
  101.     <script src="bootstrap/dist/js/bootstrap.min.js"></script>
  102. <?php makeFooter(); ?>
  103. </div>
  104. </body>
  105. </html>
  106. =====twitch_api.php=====
  107. <?php
  108.  
  109. function get_url_contents($url){
  110.     $crl = curl_init();
  111.     $timeout = 5;
  112.     curl_setopt ($crl, CURLOPT_URL,$url);
  113.     curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  114.     curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  115.     curl_setopt ($crl, CURLOPT_SSL_VERIFYPEER, false);
  116.     $ret = curl_exec($crl);
  117.     curl_close($crl);
  118.     return $ret;
  119. }
  120.  
  121. function video($stream, $videoheight, $width, $volume = 25){
  122.     echo"<object type='application/x-shockwave-flash' height='$videoheight' width='$width' id='live_embed_player_flash' data='http://www.twitch.tv/widgets/live_embed_player.swf?channel=$stream' bgcolor='#000000'>
  123.             <param name='allowFullScreen' value='true' />
  124.             <param name='allowScriptAccess' value='always' />
  125.             <param name='allowNetworking' value='all' />
  126.             <param name='movie' value='http://www.twitch.tv/widgets/live_embed_player.swf' />
  127.             <param name='flashvars' value='hostname=www.twitch.tv&channel=$stream&auto_play=true&start_volume=$volume' /></object>";
  128. }
  129.  
  130. function chat($name, $chatheight, $width){
  131.             echo"<td><center>
  132.            <iframe frameborder='0' scrolling='no' id='chat_embed' src='http://twitch.tv/chat/embed?channel=$name&popout_chat=true' height='$chatheight' width='$width'></iframe>
  133.             </center></td>";
  134. }
  135. ?>
Add Comment
Please, Sign In to add comment