1
|
|
|
<?php |
2
|
|
|
namespace Redbox\Twitch\Resource; |
3
|
|
|
use Redbox\Twitch\Entity; |
4
|
|
|
|
5
|
|
|
class Streams extends ResourceAbstract |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
public function getStreamByChannel($args = []) |
9
|
|
|
{ |
10
|
|
|
$response = $this->call('getStreamByChannel', $args); |
11
|
|
|
|
12
|
|
|
$stream = new Entity\Stream; |
13
|
|
|
$stream->setOnline(false); |
14
|
|
|
|
15
|
|
|
if ($response->stream) { |
16
|
|
|
$info = $response->stream; |
17
|
|
|
$stream->setOnline(true); |
18
|
|
|
$stream->setGame($info->game); |
19
|
|
|
$stream->setViewers($info->viewers); |
20
|
|
|
$stream->setCreatedAt($info->created_at); |
21
|
|
|
$stream->setVideoheight($info->video_height); |
22
|
|
|
$stream->setAverageFps($info->average_fps); |
23
|
|
|
$stream->setDelay($info->delay); |
24
|
|
|
$stream->setIsPlaylist($info->is_playlist); |
25
|
|
|
$stream->setPreview($info->preview); |
26
|
|
|
$stream->setChannel($info->channel); |
27
|
|
|
$stream->setId($info->_id); |
28
|
|
|
} |
29
|
|
|
return $stream; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getStreams($args = []) |
33
|
|
|
{ |
34
|
|
|
$response = $this->call('getStreams', $args); |
35
|
|
|
|
36
|
|
|
$streams = []; |
37
|
|
|
|
38
|
|
|
if ($response->streams) { |
39
|
|
|
foreach($response->streams as $info) |
40
|
|
|
{ |
41
|
|
|
$stream = new Entity\Stream; |
42
|
|
|
$stream->setOnline(true); |
43
|
|
|
$stream->setGame($info->game); |
44
|
|
|
$stream->setViewers($info->viewers); |
45
|
|
|
$stream->setCreatedAt($info->created_at); |
46
|
|
|
$stream->setVideoheight($info->video_height); |
47
|
|
|
$stream->setAverageFps($info->average_fps); |
48
|
|
|
$stream->setDelay($info->delay); |
49
|
|
|
$stream->setIsPlaylist($info->is_playlist); |
50
|
|
|
$stream->setPreview($info->preview); |
51
|
|
|
$stream->setChannel($info->channel); |
52
|
|
|
$stream->setId($info->_id); |
53
|
|
|
$streams[] = $stream; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
return $streams; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getFeaturedStreams($args = []) |
60
|
|
|
{ |
61
|
|
|
$response = $this->call('getFeaturedStreams', $args); |
62
|
|
|
|
63
|
|
|
$streams = []; |
64
|
|
|
|
65
|
|
|
if ($response->featured) { |
66
|
|
|
foreach($response->featured as $info) |
67
|
|
|
{ |
68
|
|
|
$featured = new Entity\FeaturedStream; |
69
|
|
|
$featured->setText($info->text); |
70
|
|
|
$featured->setImage($info->image); |
71
|
|
|
$featured->setTitle($info->title); |
72
|
|
|
$featured->setPriority($info->priority); |
73
|
|
|
$featured->setScheduled($info->scheduled); |
74
|
|
|
|
75
|
|
|
$steam_info = $info->stream; |
76
|
|
|
$stream = new Entity\Stream; |
77
|
|
|
$stream->setOnline(true); |
78
|
|
|
$stream->setGame($steam_info->game); |
79
|
|
|
$stream->setViewers($steam_info->viewers); |
80
|
|
|
$stream->setCreatedAt($steam_info->created_at); |
81
|
|
|
$stream->setVideoheight($steam_info->video_height); |
82
|
|
|
$stream->setAverageFps($steam_info->average_fps); |
83
|
|
|
$stream->setDelay($steam_info->delay); |
84
|
|
|
$stream->setIsPlaylist($steam_info->is_playlist); |
85
|
|
|
$stream->setPreview($steam_info->preview); |
86
|
|
|
$stream->setChannel($steam_info->channel); |
87
|
|
|
$stream->setId($steam_info->_id); |
88
|
|
|
|
89
|
|
|
$featured->setStream($stream); |
90
|
|
|
$streams[] = $featured; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
return $streams; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getStreamsSummary($args = []) |
97
|
|
|
{ |
98
|
|
|
$response = $this->call('getStreamsSummary', $args); |
99
|
|
|
$summary = new Entity\StreamSummary; |
100
|
|
|
|
101
|
|
|
if (isset($response->channels) === true) { |
102
|
|
|
$summary->setChannels($response->channels); |
103
|
|
|
$summary->setViewers($response->viewers); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $summary; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getStreamsFollowed($args = []) |
110
|
|
|
{ |
111
|
|
|
$response = $this->call('getStreamsFollowed', $args); |
112
|
|
|
|
113
|
|
|
$streams = []; |
114
|
|
|
|
115
|
|
|
if ($response->streams) { |
116
|
|
|
foreach($response->streams as $info) |
117
|
|
|
{ |
118
|
|
|
$stream = new Entity\Stream; |
119
|
|
|
$stream->setOnline(true); |
120
|
|
|
$stream->setGame($info->game); |
121
|
|
|
$stream->setViewers($info->viewers); |
122
|
|
|
$stream->setCreatedAt($info->created_at); |
123
|
|
|
$stream->setVideoheight($info->video_height); |
124
|
|
|
$stream->setAverageFps($info->average_fps); |
125
|
|
|
$stream->setDelay($info->delay); |
126
|
|
|
$stream->setIsPlaylist($info->is_playlist); |
127
|
|
|
$stream->setPreview($info->preview); |
128
|
|
|
$stream->setChannel($info->channel); |
129
|
|
|
$stream->setId($info->_id); |
130
|
|
|
$streams[] = $stream; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
return $streams; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
} |