Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: twitch API : сортировка каналов по количеству зрителей.

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Без описания
justuserost
Отправлено: 07 Декабря, 2013 - 17:29:30
Post Id


Новичок


Покинул форум
Сообщений всего: 1
Дата рег-ции: Дек. 2013  


Помог: 0 раз(а)




Доброе время суток.
Имеется скрипт ( codepad.org/gmk94Ne3 ) - выводит список указанных стримов с сайта twitch.tv , но в порядке "хаоса", в данном скрипте выводятся следующие стримы: $members = array("gspotdota","sheevergaming"," dreadztv","dotatalktv2"); , но они не понятно как сортированы.
Как и где в этом скрипте сделать сортировку этих каналов по кол-ву зрителей?

PHP:
скопировать код в буфер обмена
  1. <html>
  2. <head>
  3. <title>Streamlist</title>
  4. </head>
  5. <body>
  6. <?PHP
  7.  
  8. /**
  9. * @version   0.1
  10. * @copyright (C) 2012/2013 Cees Middel (Avon) www.maegis.net
  11. * @Inspired by Syi http://mushroom-mayhem.com
  12. * @license   GNU/GPL v3 http://www.gnu.org/licenses/gpl.html
  13. */
  14.  
  15. /**
  16. * array with all stream names i.e. www.twitch.tv/"iksf".
  17. * To add more users just add their channel names with comma seperation
  18. * This is all there is, no futher editing required
  19. */
  20. $members = array("gspotdota","sheevergaming","dreadztv","dotatalktv2");
  21.  
  22. // This variable becomes one long url with the channel names stringed up behind it
  23. // This url then fetches a json file from twitch with all the selected channels information
  24. $userGrab = "http://api.justin.tv/api/stream/list.json?channel=";
  25.  
  26. //I use this array to compare with the members array. All users in this arrat are substracted from the members array and hence are //"offline"
  27. $checkedOnline = array ();
  28.  
  29. foreach($members as $i =>$value){
  30.         $userGrab .= ",";
  31.         $userGrab .= $value;
  32. }
  33. unset($value);
  34.  
  35. //grabs the channel data from twitch.tv streams
  36. $json_file = file_get_contents($userGrab, 0, null, null);
  37. $json_array = json_decode($json_file, true);
  38.  
  39. //get's member names from stream url's and checks for online members
  40. foreach($members as $i =>$value){
  41.         $title = $json_array[$i]['channel']['channel_url'];
  42.         $array = explode('/', $title);
  43.         $member = end($array);
  44.         $viewer = $json_array[$i] ['channel_count'];
  45.         $login = $json_array[$i] ['streams_name'];
  46.         onlinecheck($member, $viewer, $login);
  47.         $checkedOnline[] = signin($member);
  48. }
  49.  
  50. unset($value);
  51. unset($i);
  52.  
  53. //checks if player streams are online
  54. function onlinecheck($online, $viewers, $login)
  55.     {  
  56.         //If the variable online is not equal to null, there is a good change this person is currently streaming
  57.                         if ($online != null)
  58.             {
  59.                     echo '<a href="http://www.twitch.tv/'.$online.'"> <strong>'.$online.'</strong>';
  60.                     echo '<a href="http://www.twitch.tv/'.$online.'"> <strong>'.$login.'</strong>';
  61.                                         echo '&nbsp <img src="/images/online.png"><strong> Status:</strong> Online! </br>';
  62.                     echo '<img src="/images/viewers.png"><strong>Viewers:</strong> &nbsp' .$viewers.'</br>';
  63. echo '<img src="http://static.starladder.tv/uploads/news/images/DOTA2/x3m4eg/solo.png" width="150" height="113" title="Click here to watch" />'; // Prints out an image
  64.                         echo '</a>';           
  65.                         }
  66.         }
  67.        
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. //This funcion add's online channel names to the checked online array
  76. function signin($person){
  77.         if($person != null){
  78.                 return $person;
  79.         }
  80.         else{
  81.                 return null;
  82.         }
  83. }
  84.        
  85. ?>
  86. <hr>
  87. <?PHP
  88. //This part list all the people currently offline. Here the array with online users is compared with the total users.
  89. //online users are then removed from the total users array.
  90.         foreach ($members as $i => $value1) {
  91.                 foreach($checkedOnline as $ii => $value2){
  92.                         if($value1 == $value2){
  93.                                 unset($members[$i]);
  94.                         }
  95.                 }
  96.                        
  97.         }
  98.  
  99. ?>
  100. </body>
  101. </html>

(Отредактировано автором: 07 Декабря, 2013 - 17:39:06)

 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Если скрипт не работает »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB