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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
<?php
class RoosterTeethBridge extends BridgeAbstract
{
const MAINTAINER = 'tgkenney';
const NAME = 'Rooster Teeth';
const URI = 'https://roosterteeth.com';
const DESCRIPTION = 'Gets the latest channel videos from the Rooster Teeth website';
const API = 'https://svod-be.roosterteeth.com/';
const PARAMETERS = [
'Options' => [
'channel' => [
'type' => 'list',
'name' => 'Channel',
'title' => 'Select a channel to filter by',
'values' => [
'All channels' => 'all',
'Achievement Hunter' => 'achievement-hunter',
'Camp Camp' => 'camp-camp',
'Cow Chop' => 'cow-chop',
'Death Battle' => 'death-battle',
'Friends of RT' => 'friends-of-rt',
'Funhaus' => 'funhaus',
'Inside Gaming' => 'inside-gaming',
'JT Music' => 'jt-music',
'Kinda Funny' => 'kinda-funny',
'Red vs. Blue Universe' => 'red-vs-blue-universe',
'Rooster Teeth' => 'rooster-teeth',
'RWBY Universe' => 'rwby-universe',
'Squad Team Force' => 'squad-team-force',
'Sugar Pine 7' => 'sugar-pine-7',
'The Yogscast' => 'the-yogscast',
]
],
'sort' => [
'type' => 'list',
'name' => 'Sort',
'title' => 'Select a sort order',
'values' => [
'Newest -> Oldest' => 'desc',
'Oldest -> Newest' => 'asc'
],
'defaultValue' => 'desc'
],
'first' => [
'type' => 'list',
'name' => 'RoosterTeeth First',
'title' => 'Select whether to include "First" videos before they are public',
'values' => [
'True' => true,
'False' => false
]
],
'episodeImage' => [
'name' => 'Episode Image',
'type' => 'checkbox',
'defaultValue' => 'checked',
'title' => 'Select whether to include an episode image (if available)',
],
'limit' => [
'name' => 'Limit',
'type' => 'number',
'required' => false,
'title' => 'Maximum number of items to return',
'defaultValue' => 10
]
]
];
public function collectData()
{
if ($this->getInput('channel') !== 'all') {
$uri = self::API
. 'api/v1/episodes?per_page='
. $this->getInput('limit')
. '&channel_id='
. $this->getInput('channel')
. '&order=' . $this->getInput('sort')
. '&page=1';
$htmlJSON = getSimpleHTMLDOM($uri);
} else {
$uri = self::API
. '/api/v1/episodes?per_page='
. $this->getInput('limit')
. '&filter=all&order='
. $this->getInput('sort')
. '&page=1';
$htmlJSON = getSimpleHTMLDOM($uri);
}
$htmlArray = json_decode($htmlJSON, true);
foreach ($htmlArray['data'] as $key => $value) {
$item = [];
if (!$this->getInput('first') && $value['attributes']['is_sponsors_only']) {
continue;
}
$publicDate = date_create($value['attributes']['member_golive_at']);
$dateDiff = date_diff($publicDate, date_create(), false);
if (!$this->getInput('first') && $dateDiff->invert == 1) {
continue;
}
$item['uri'] = self::URI . $value['canonical_links']['self'];
$item['title'] = $value['attributes']['title'];
$item['timestamp'] = $value['attributes']['member_golive_at'];
$item['author'] = $value['attributes']['show_title'];
$item['content'] = $this->getItemContent($value);
$this->items[] = $item;
}
}
protected function getItemContent(array $value): string
{
$content = nl2br($value['attributes']['description']);
if (isset($value['attributes']['length'])) {
$duration_format = $value['attributes']['length'] > 3600 ? 'G:i:s' : 'i:s';
$content = sprintf(
'Duration: %s<br><br>%s',
gmdate($duration_format, $value['attributes']['length']),
$content
);
}
if ($this->getInput('episodeImage') === true) {
foreach ($value['included']['images'] ?? [] as $image) {
if ($image['type'] == 'episode_image') {
$content = sprintf(
'<img src="%s"/><br><br>%s',
$image['attributes']['medium'],
$content,
);
break;
}
}
}
return $content;
}
}
|