-
Notifications
You must be signed in to change notification settings - Fork 1k
/
PokemonTVBridge.php
152 lines (145 loc) · 4.94 KB
/
PokemonTVBridge.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
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
149
150
151
152
<?php
class PokemonTVBridge extends BridgeAbstract
{
const NAME = 'PokemonTV Bridge';
const URI = 'https://www.pokemon.com/';
const DESCRIPTION = 'Returns latest episodes from PokemonTV';
const MAINTAINER = 'Bockiii';
const CACHE_TIMEOUT = 3600;
const PARAMETERS = [ [
'language' => [
'name' => 'Language',
'type' => 'list',
'title' => 'Select your language',
'values' => [
'Danish' => 'dk',
'Dutch' => 'nl',
'English (UK)' => 'uk',
'English (US)' => 'us',
'Finish' => 'fi',
'French' => 'fr',
'German' => 'de',
'Italian' => 'it',
'Latin America' => 'el',
'Norwegian' => 'no',
'Portoguese' => 'br',
'Russian' => 'ru',
'Spanish' => 'es',
'Swedish' => 'se'
],
'defaultValue' => 'English (US)'
],
'filtername' => [
'name' => 'Series Name Filter',
'exampleValue' => 'Ultra',
'required' => false
],
'filterseason' => [
'name' => 'Series Season Filter',
'exampleValue' => '22',
'required' => false
]
]];
public function collectData()
{
$link = 'https://www.pokemon.com/api/pokemontv/v2/channels/' . $this->getInput('language');
$html = getSimpleHTMLDOM($link);
$parsed_json = json_decode($html);
$filtername = $this->getInput('filtername');
$filterseason = $this->getInput('filterseason');
foreach ($parsed_json as $element) {
if (strlen($filtername) >= 1) {
if (!(stristr($element->{'channel_name'}, $filtername) !== false)) {
continue;
}
}
foreach ($element->{'media'} as $mediaelement) {
if (strlen($filterseason) >= 1) {
if ($mediaelement->{'season'} != $filterseason) {
continue;
}
}
switch ($element->media_type) {
case 'movie':
case 'junior':
case 'original':
case 'non-animation':
$itemtitle = $element->channel_name;
break;
case 'episode':
$season = str_pad($mediaelement->{'season'}, 2, '0', STR_PAD_LEFT);
$episode = str_pad($mediaelement->{'episode'}, 2, '0', STR_PAD_LEFT);
$itemtitle = $element->{'channel_name'} . ' - S' . $season . 'E' . $episode;
break;
default:
$itemtitle = '';
}
$streamurl = 'https://watch.pokemon.com/' . $this->getCountryCode() . '/#/player?id=' . $mediaelement->{'id'};
$item = [];
$item['uri'] = $streamurl;
$item['title'] = $itemtitle;
$item['timestamp'] = $mediaelement->{'last_modified'};
$item['content'] = '<h1>' . $itemtitle . ' ' . $mediaelement->{'title'}
. '</h1><br><br><a href="'
. $streamurl
. '"><img src="'
. $mediaelement->{'images'}->{'medium'}
. '" /></a><br><br>'
. $mediaelement->{'description'}
. '<br><br><a href="' . $mediaelement->{'offline_url'} . '">Download</a>';
$this->items[] = $item;
}
}
}
private function getCountryCode()
{
switch ($this->getInput('language')) {
case 'us':
return 'en-us';
break;
case 'de':
return 'de-de';
break;
case 'fr':
return 'fr-fr';
break;
case 'es':
return 'es-es';
break;
case 'el':
return 'es-xl';
break;
case 'it':
return 'it-it';
break;
case 'dk':
return 'da-dk';
break;
case 'fi':
return 'fi-fi';
break;
case 'br':
return 'pt-br';
break;
case 'uk':
return 'en-gb';
break;
case 'ru':
return 'ru-ru';
break;
case 'nl':
return 'nl-nl';
break;
case 'no':
return 'nb-no';
break;
case 'se':
return 'sv-se';
break;
}
}
public function getIcon()
{
return 'https://assets.pokemon.com/static2/_ui/img/favicon.ico';
}
}