-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtwitch_streams.php
54 lines (47 loc) · 1.48 KB
/
twitch_streams.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: Ricardo
* Date: 01/05/2018
* Time: 15:26
*/
/**
* @param string $url
* @return array
*/
function makeRequest(string $url): array
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Client-ID: 2f7bx36piv2sps61hnbloh7b0huorb'));
curl_setopt($curl, CURLOPT_POST, FALSE);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$json = curl_exec($curl);
curl_close($curl);
$t = json_decode($json);
return array($curl, $json, $t);
}
if (Website::getWebsiteConfig()->getValue('info_bar_twitch')) {
$url = "https://api.twitch.tv/helix/streams?first=100&game_id=19619";
list($curl, $json, $t) = makeRequest($url);
$twitch_c = 0;
$twitch_a = 0;
if ($t->data) {
foreach ($t->data as $twitch) {
$twitch_a++;
$twitch_c = $twitch_c + $twitch->viewer_count;
if ($twitch_a == 100) {
$twitch_b = "";
$url = "https://api.twitch.tv/helix/streams?first=100&game_id=19619&after={$t->pagination->cursor}";
list($curl, $json, $t) = makeRequest($url);
if (!empty($t->data)) {
foreach ($t->data as $tw) {
$twitch_a++;
$twitch_c = $twitch_c + $tw->viewer_count;
}
}
}
}
}
}