|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MalScraper\Model\Additional; |
|
4
|
|
|
|
|
5
|
|
|
use MalScraper\Helper\Helper; |
|
6
|
|
|
use MalScraper\Model\MainModel; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* CharacterStaffModel class. |
|
10
|
|
|
*/ |
|
11
|
|
|
class CharacterStaffModel extends MainModel |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Type of info. Either anime or manga. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $_type; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Id of the anime or manga. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string|int |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Default constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $type |
|
31
|
|
|
* @param string|int $id |
|
32
|
|
|
* @param string $parserArea |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct($type, $id, $parserArea = '.js-scrollfix-bottom-rel') |
|
37
|
|
|
{ |
|
38
|
|
|
$this->_type = $type; |
|
39
|
|
|
$this->_id = $id; |
|
40
|
|
|
$this->_url = $this->_myAnimeListUrl.'/'.$type.'/'.$id; |
|
41
|
|
|
$this->_parserArea = $parserArea; |
|
42
|
|
|
|
|
43
|
|
|
parent::errorCheck($this); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Default call. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $method |
|
50
|
|
|
* @param array $arguments |
|
51
|
|
|
* |
|
52
|
|
|
* @return array|string|int |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __call($method, $arguments) |
|
55
|
|
|
{ |
|
56
|
|
|
if ($this->_error) { |
|
57
|
|
|
return $this->_error; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return call_user_func_array([$this, $method], $arguments); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get type (anime or manga). |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private function getType() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->_type; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get anime/manga id. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
private function getId() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->_id; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get anime/manga character list. |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
private function getCharacter() |
|
89
|
|
|
{ |
|
90
|
|
|
$character = []; |
|
91
|
|
|
$character_index = 0; |
|
92
|
|
|
$char_table = $this->_parser->find('h2', 0); |
|
93
|
|
|
if ($char_table->next_sibling()->tag == 'table') { |
|
94
|
|
|
$char_table = $char_table->next_sibling(); |
|
95
|
|
|
while (true) { |
|
96
|
|
|
$char_name_area = $char_table->find('td', 1); |
|
97
|
|
|
|
|
98
|
|
|
$character[$character_index]['image'] = $this->getCharacterImage($char_table); |
|
99
|
|
|
$character[$character_index]['id'] = $this->getCharacterId($char_name_area); |
|
100
|
|
|
$character[$character_index]['name'] = $this->getCharacterName($char_name_area); |
|
101
|
|
|
$character[$character_index]['role'] = $this->getCharacterRole($char_name_area); |
|
102
|
|
|
|
|
103
|
|
|
// va name + role |
|
104
|
|
|
$char_va_area = $char_table->find('td', 2); |
|
105
|
|
|
if ($char_va_area) { |
|
106
|
|
|
$character[$character_index]['va'] = $this->getVa($char_va_area); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$char_table = $char_table->next_sibling(); |
|
110
|
|
|
if ($char_table->tag == 'br' || $char_table->tag == 'a' || $char_table->tag == 'h2' || $char_table->tag == 'div') { |
|
111
|
|
|
break; |
|
112
|
|
|
} |
|
113
|
|
|
$character_index++; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $character; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get anime/manga va character. |
|
122
|
|
|
* |
|
123
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $char_va_area |
|
124
|
|
|
* |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
private function getVa($char_va_area) |
|
128
|
|
|
{ |
|
129
|
|
|
$va = []; |
|
130
|
|
|
$va_index = 0; |
|
131
|
|
|
$char_va_area = $char_va_area->find('table', 0); |
|
132
|
|
|
foreach ($char_va_area->find('tr') as $each_va) { |
|
133
|
|
|
$va_name_area = $each_va->find('td', 0); |
|
134
|
|
|
|
|
135
|
|
|
$va[$va_index]['id'] = $this->getCharacterVaId($va_name_area); |
|
136
|
|
|
$va[$va_index]['name'] = $this->getCharacterVaName($va_name_area); |
|
137
|
|
|
$va[$va_index]['role'] = $this->getCharacterVaRole($va_name_area); |
|
138
|
|
|
$va[$va_index]['image'] = $this->getCharacterVaImage($each_va); |
|
139
|
|
|
|
|
140
|
|
|
$va_index++; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return $va; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get anime/manga character image. |
|
148
|
|
|
* |
|
149
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $char_table |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
private function getCharacterImage($char_table) |
|
154
|
|
|
{ |
|
155
|
|
|
$char_image = $char_table->find('td .picSurround img', 0)->getAttribute('data-src'); |
|
156
|
|
|
|
|
157
|
|
|
return Helper::imageUrlCleaner($char_image); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Get anime/manga character id. |
|
162
|
|
|
* |
|
163
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $char_name_area |
|
164
|
|
|
* |
|
165
|
|
|
* @return string |
|
166
|
|
|
*/ |
|
167
|
|
|
private function getCharacterId($char_name_area) |
|
168
|
|
|
{ |
|
169
|
|
|
$char_id = $char_name_area->find('a', 0)->href; |
|
170
|
|
|
$char_id = explode('/', $char_id); |
|
171
|
|
|
|
|
172
|
|
|
return $char_id[4]; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Get anime/manga character name. |
|
177
|
|
|
* |
|
178
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $char_name_area |
|
179
|
|
|
* |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
|
|
private function getCharacterName($char_name_area) |
|
183
|
|
|
{ |
|
184
|
|
|
return $char_name_area->find('a', 0)->plaintext; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Get anime/manga character role. |
|
189
|
|
|
* |
|
190
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $char_name_area |
|
191
|
|
|
* |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
private function getCharacterRole($char_name_area) |
|
195
|
|
|
{ |
|
196
|
|
|
return $char_name_area->find('small', 0)->plaintext; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Get anime/manga character va id. |
|
201
|
|
|
* |
|
202
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $va_name_area |
|
203
|
|
|
* |
|
204
|
|
|
* @return string |
|
205
|
|
|
*/ |
|
206
|
|
|
private function getCharacterVaId($va_name_area) |
|
207
|
|
|
{ |
|
208
|
|
|
$va_id = $va_name_area->find('a', 0)->href; |
|
209
|
|
|
$va_id = explode('/', $va_id); |
|
210
|
|
|
|
|
211
|
|
|
return $va_id[4]; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get anime/manga character va name. |
|
216
|
|
|
* |
|
217
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $va_name_area |
|
218
|
|
|
* |
|
219
|
|
|
* @return string |
|
220
|
|
|
*/ |
|
221
|
|
|
private function getCharacterVaName($va_name_area) |
|
222
|
|
|
{ |
|
223
|
|
|
return $va_name_area->find('a', 0)->plaintext; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Get anime/manga character va image. |
|
228
|
|
|
* |
|
229
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_va |
|
230
|
|
|
* |
|
231
|
|
|
* @return string |
|
232
|
|
|
*/ |
|
233
|
|
|
private function getCharacterVaImage($each_va) |
|
234
|
|
|
{ |
|
235
|
|
|
$va_image = $each_va->find('td', 1)->find('img', 0)->getAttribute('data-src'); |
|
236
|
|
|
|
|
237
|
|
|
return Helper::imageUrlCleaner($va_image); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Get anime/manga character va role. |
|
242
|
|
|
* |
|
243
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $va_name_area |
|
244
|
|
|
* |
|
245
|
|
|
* @return string |
|
246
|
|
|
*/ |
|
247
|
|
|
private function getCharacterVaRole($va_name_area) |
|
248
|
|
|
{ |
|
249
|
|
|
return $va_name_area->find('small', 0)->plaintext; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Get anime/manga staff list. |
|
254
|
|
|
* |
|
255
|
|
|
* @return array |
|
256
|
|
|
*/ |
|
257
|
|
|
private function getStaff() |
|
258
|
|
|
{ |
|
259
|
|
|
$staff = []; |
|
260
|
|
|
$staff_index = 0; |
|
261
|
|
|
$staff_table = $this->_parser->find('h2', 1); |
|
262
|
|
|
if ($staff_table) { |
|
263
|
|
|
if ($staff_table->next_sibling()->tag == 'table') { |
|
264
|
|
|
$staff_table = $staff_table->next_sibling(); |
|
265
|
|
|
while (true) { |
|
266
|
|
|
$staff_name_area = $staff_table->find('td', 1); |
|
267
|
|
|
|
|
268
|
|
|
$staff[$staff_index]['image'] = $this->getCharacterImage($staff_table); |
|
269
|
|
|
$staff[$staff_index]['id'] = $this->getCharacterId($staff_name_area); |
|
270
|
|
|
$staff[$staff_index]['name'] = $this->getCharacterName($staff_name_area); |
|
271
|
|
|
$staff[$staff_index]['role'] = $this->getCharacterRole($staff_name_area); |
|
272
|
|
|
|
|
273
|
|
|
$staff_table = $staff_table->next_sibling(); |
|
274
|
|
|
if (!$staff_table) { |
|
275
|
|
|
break; |
|
276
|
|
|
} |
|
277
|
|
|
$staff_index++; |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
return $staff; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Get anime/manga character + staff complete list. |
|
287
|
|
|
* |
|
288
|
|
|
* @return array |
|
289
|
|
|
*/ |
|
290
|
|
|
private function getAllInfo() |
|
291
|
|
|
{ |
|
292
|
|
|
$data = [ |
|
293
|
|
|
'character' => $this->getCharacter(), |
|
294
|
|
|
'staff' => $this->getStaff(), |
|
295
|
|
|
]; |
|
296
|
|
|
|
|
297
|
|
|
return $data; |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|