|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MalScraper\Model\General; |
|
4
|
|
|
|
|
5
|
|
|
use MalScraper\Helper\Helper; |
|
6
|
|
|
use MalScraper\Model\MainModel; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* InfoModel class. |
|
10
|
|
|
*/ |
|
11
|
|
|
class InfoModel 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 = '#content') |
|
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 anime/manga id. |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
private function getId() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->_id; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get anime/manga cover. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string|bool |
|
77
|
|
|
*/ |
|
78
|
|
|
private function getCover() |
|
79
|
|
|
{ |
|
80
|
|
|
$anime_cover = $this->_parser->find('img.ac', 0); |
|
81
|
|
|
|
|
82
|
|
|
return $anime_cover ? $anime_cover->src : ''; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get anime/manga title. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string|bool |
|
89
|
|
|
*/ |
|
90
|
|
|
private function getTitle() |
|
91
|
|
|
{ |
|
92
|
|
|
$anime_cover = $this->_parser->find('img.ac', 0); |
|
93
|
|
|
|
|
94
|
|
|
return $anime_cover ? $anime_cover->alt : ''; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get anime/manga alternative title. |
|
99
|
|
|
* |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
private function getTitle2() |
|
103
|
|
|
{ |
|
104
|
|
|
$title2 = []; |
|
105
|
|
|
|
|
106
|
|
|
$anime_info = $this->_parser->find('.js-scrollfix-bottom', 0); |
|
107
|
|
|
|
|
108
|
|
|
$title2['english'] = $this->getTitle3($anime_info, 'English'); |
|
109
|
|
|
$title2['synonym'] = $this->getTitle3($anime_info, 'Synonyms'); |
|
110
|
|
|
$title2['japanese'] = $this->getTitle3($anime_info, 'Japanese'); |
|
111
|
|
|
|
|
112
|
|
|
// preg_match('/(English:<\/span>)([^<]*)/', $anime_info->innertext, $english); |
|
113
|
|
|
// $title2['english'] = trim($english ? $english[2] : ''); |
|
114
|
|
|
|
|
115
|
|
|
// preg_match('/(Synonyms:<\/span>)([^<]*)/', $anime_info->innertext, $synonym); |
|
116
|
|
|
// $title2['synonym'] = trim($synonym ? $synonym[2] : ''); |
|
117
|
|
|
|
|
118
|
|
|
// preg_match('/(Japanese:<\/span>)([^<]*)/', $anime_info->innertext, $japanese); |
|
119
|
|
|
// $title2['japanese'] = trim($japanese ? $japanese[2] : ''); |
|
120
|
|
|
|
|
121
|
|
|
return $title2; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get anime/manga alternative title. |
|
126
|
|
|
* |
|
127
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $anime_info |
|
128
|
|
|
* @param string $type |
|
129
|
|
|
* |
|
130
|
|
|
* @return array |
|
131
|
|
|
*/ |
|
132
|
|
|
private function getTitle3($anime_info, $type) |
|
133
|
|
|
{ |
|
134
|
|
|
preg_match('/('.$type.':<\/span>)([^<]*)/', $anime_info->innertext, $title); |
|
135
|
|
|
return trim($title ? $title[2] : ''); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Get anime/manga promotional video. |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
private function getVideo() |
|
144
|
|
|
{ |
|
145
|
|
|
$video_area = $this->_parser->find('.video-promotion', 0); |
|
146
|
|
|
if ($video_area) { |
|
147
|
|
|
$video = $video_area->find('a', 0)->href; |
|
148
|
|
|
|
|
149
|
|
|
return Helper::videoUrlCleaner($video); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return ''; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Get anime/manga synopsis. |
|
157
|
|
|
* |
|
158
|
|
|
* @return string |
|
159
|
|
|
*/ |
|
160
|
|
|
private function getSynopsis() |
|
161
|
|
|
{ |
|
162
|
|
|
$synopsis = $this->_parser->find('span[itemprop=description]', 0); |
|
163
|
|
|
if ($synopsis) { |
|
164
|
|
|
$synopsis = $synopsis->plaintext; |
|
165
|
|
|
|
|
166
|
|
|
return trim(preg_replace('/\n[^\S\n]*/', "\n", $synopsis)); |
|
167
|
|
|
} else { |
|
168
|
|
|
return; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Get anime/manga score. |
|
174
|
|
|
* |
|
175
|
|
|
* @return string |
|
176
|
|
|
*/ |
|
177
|
|
|
private function getScore() |
|
178
|
|
|
{ |
|
179
|
|
|
$score = $this->_parser->find('div[class="fl-l score"]', 0)->plaintext; |
|
180
|
|
|
$score = trim($score); |
|
181
|
|
|
|
|
182
|
|
|
return $score != 'N/A' ? $score : null; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get number of user who give score. |
|
187
|
|
|
* |
|
188
|
|
|
* @return string |
|
189
|
|
|
*/ |
|
190
|
|
|
private function getVoter() |
|
191
|
|
|
{ |
|
192
|
|
|
$voter = $this->_parser->find('div[class="fl-l score"]', 0)->getAttribute('data-user'); |
|
193
|
|
|
|
|
194
|
|
|
return trim(str_replace(['users', 'user', ','], '', $voter)); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Get anime/manga rank. |
|
199
|
|
|
* |
|
200
|
|
|
* @return string |
|
201
|
|
|
*/ |
|
202
|
|
|
private function getRank() |
|
203
|
|
|
{ |
|
204
|
|
|
$rank = $this->_parser->find('span[class="numbers ranked"] strong', 0)->plaintext; |
|
205
|
|
|
$rank = $rank != 'N/A' ? $rank : ''; |
|
206
|
|
|
|
|
207
|
|
|
return str_replace('#', '', $rank); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Get anime/manga popularity. |
|
212
|
|
|
* |
|
213
|
|
|
* @return string |
|
214
|
|
|
*/ |
|
215
|
|
|
private function getPopularity() |
|
216
|
|
|
{ |
|
217
|
|
|
$popularity = $this->_parser->find('span[class="numbers popularity"] strong', 0)->plaintext; |
|
218
|
|
|
|
|
219
|
|
|
return str_replace('#', '', $popularity); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Get number of user who watch/read the anime/manga. |
|
224
|
|
|
* |
|
225
|
|
|
* @return string |
|
226
|
|
|
*/ |
|
227
|
|
|
private function getMembers() |
|
228
|
|
|
{ |
|
229
|
|
|
$member = $this->_parser->find('span[class="numbers members"] strong', 0)->plaintext; |
|
230
|
|
|
|
|
231
|
|
|
return str_replace(',', '', $member); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Get number of user who favorite the anime/manga. |
|
236
|
|
|
* |
|
237
|
|
|
* @return string |
|
238
|
|
|
*/ |
|
239
|
|
|
private function getFavorite() |
|
240
|
|
|
{ |
|
241
|
|
|
$favorite = $this->_parser->find('div[data-id=info2]', 0)->next_sibling()->next_sibling()->next_sibling(); |
|
242
|
|
|
$favorite_title = $favorite->find('span', 0)->plaintext; |
|
243
|
|
|
$favorite = $favorite->plaintext; |
|
244
|
|
|
$favorite = trim(str_replace($favorite_title, '', $favorite)); |
|
245
|
|
|
$favorite = str_replace(',', '', $favorite); |
|
246
|
|
|
|
|
247
|
|
|
return preg_replace("/([\s])+/", ' ', $favorite); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Get anime/manga detail info. |
|
252
|
|
|
* |
|
253
|
|
|
* @return array |
|
254
|
|
|
*/ |
|
255
|
|
|
private function getOtherInfo() |
|
256
|
|
|
{ |
|
257
|
|
|
$info = []; |
|
258
|
|
|
|
|
259
|
|
|
$anime_info = $this->_parser->find('.js-scrollfix-bottom', 0); |
|
260
|
|
|
$other_info = (count($anime_info->find('h2')) > 2) ? $anime_info->find('h2', 1) : $anime_info->find('h2', 0); |
|
|
|
|
|
|
261
|
|
|
$next_info = $other_info->next_sibling(); |
|
|
|
|
|
|
262
|
|
|
while (true) { |
|
263
|
|
|
$info_type = $next_info->find('span', 0)->plaintext; |
|
264
|
|
|
|
|
265
|
|
|
$clean_info_type = strtolower(str_replace(': ', '', $info_type)); |
|
266
|
|
|
$clean_info_value = $this->getCleanInfo($info_type, $next_info); |
|
267
|
|
|
$clean_info_value = $this->getCleanerInfo1($clean_info_type, $clean_info_value); |
|
268
|
|
|
$clean_info_value = $this->getCleanerInfo2($next_info, $clean_info_type, $clean_info_value); |
|
269
|
|
|
|
|
270
|
|
|
$info[$clean_info_type] = $clean_info_value; |
|
271
|
|
|
|
|
272
|
|
|
$next_info = $next_info->next_sibling(); |
|
273
|
|
|
if ($next_info->tag == 'h2' || $next_info->tag == 'br') { |
|
274
|
|
|
break; |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
return $info; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
/** |
|
282
|
|
|
* Get clean other info. |
|
283
|
|
|
* |
|
284
|
|
|
* @param string $info_type |
|
285
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $next_info |
|
286
|
|
|
* |
|
287
|
|
|
* @return string |
|
288
|
|
|
*/ |
|
289
|
|
|
private function getCleanInfo($info_type, $next_info) |
|
290
|
|
|
{ |
|
291
|
|
|
$info_value = $next_info->plaintext; |
|
292
|
|
|
$clean_info_value = trim(str_replace($info_type, '', $info_value)); |
|
293
|
|
|
$clean_info_value = preg_replace("/([\s])+/", ' ', $clean_info_value); |
|
294
|
|
|
|
|
295
|
|
|
return str_replace([', add some', '?', 'Not yet aired', 'Unknown'], '', $clean_info_value); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Get cleaner other info. |
|
300
|
|
|
* |
|
301
|
|
|
* @param string $clean_info_type |
|
302
|
|
|
* @param string $clean_info_value |
|
303
|
|
|
* |
|
304
|
|
|
* @return string|array |
|
305
|
|
|
*/ |
|
306
|
|
|
private function getCleanerInfo1($clean_info_type, $clean_info_value) |
|
307
|
|
|
{ |
|
308
|
|
|
if ($clean_info_type == 'published' || $clean_info_type == 'aired') { |
|
309
|
|
|
$start_air = $end_air = ''; |
|
310
|
|
|
if ($clean_info_value != 'Not available') { |
|
311
|
|
|
$parsed_airing = explode(' to ', $clean_info_value); |
|
312
|
|
|
$start_air = ($parsed_airing[0] != '?') ? $parsed_airing[0] : ''; |
|
313
|
|
|
if (count($parsed_airing) > 1) { |
|
314
|
|
|
$end_air = ($parsed_airing[1] != '?') ? $parsed_airing[1] : ''; |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
$clean_info_value = []; |
|
319
|
|
|
$clean_info_value['start'] = $start_air; |
|
320
|
|
|
$clean_info_value['end'] = $end_air; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
return $clean_info_value; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Get cleaner other info. |
|
328
|
|
|
* |
|
329
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $next_info |
|
330
|
|
|
* @param string $clean_info_type |
|
331
|
|
|
* @param string|array $clean_info_value |
|
332
|
|
|
* |
|
333
|
|
|
* @return string|array |
|
334
|
|
|
*/ |
|
335
|
|
|
private function getCleanerInfo2($next_info, $clean_info_type, $clean_info_value) |
|
336
|
|
|
{ |
|
337
|
|
|
if ($clean_info_type == 'producers' |
|
338
|
|
|
|| $clean_info_type == 'licensors' |
|
339
|
|
|
|| $clean_info_type == 'studios' |
|
340
|
|
|
|| $clean_info_type == 'genres' |
|
341
|
|
|
|| $clean_info_type == 'authors' |
|
342
|
|
|
) { |
|
343
|
|
|
$info_temp = []; |
|
344
|
|
|
$info_temp_index = 0; |
|
345
|
|
|
if ($clean_info_value != 'None found') { |
|
346
|
|
|
foreach ($next_info->find('a') as $each_info) { |
|
347
|
|
|
$temp_id = explode('/', $each_info->href); |
|
348
|
|
|
$info_temp[$info_temp_index]['id'] = $clean_info_type == 'authors' ? $temp_id[2] : $temp_id[3]; |
|
349
|
|
|
$info_temp[$info_temp_index]['name'] = $each_info->plaintext; |
|
350
|
|
|
$info_temp_index++; |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
return $info_temp; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
return $clean_info_value; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* Get anime/manga relation. |
|
362
|
|
|
* |
|
363
|
|
|
* @return array |
|
364
|
|
|
*/ |
|
365
|
|
|
private function getRelated() |
|
366
|
|
|
{ |
|
367
|
|
|
$related = []; |
|
368
|
|
|
$related_area = $this->_parser->find('.anime_detail_related_anime', 0); |
|
369
|
|
|
if ($related_area) { |
|
370
|
|
|
foreach ($related_area->find('tr') as $rel) { |
|
371
|
|
|
$rel_type = $rel->find('td', 0)->plaintext; |
|
372
|
|
|
$rel_type = trim(strtolower(str_replace(':', '', $rel_type))); |
|
373
|
|
|
|
|
374
|
|
|
$each_rel = []; |
|
375
|
|
|
$each_rel_index = 0; |
|
376
|
|
|
$rel_anime = $rel->find('td', 1); |
|
377
|
|
|
foreach ($rel_anime->find('a') as $r) { |
|
378
|
|
|
$each_rel[$each_rel_index] = $this->getRelatedDetail($r); |
|
379
|
|
|
$each_rel_index++; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
$related[$rel_type] = $each_rel; |
|
383
|
|
|
} |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
return $related; |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* Get related detail. |
|
391
|
|
|
* |
|
392
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $r |
|
393
|
|
|
* |
|
394
|
|
|
* @return array |
|
395
|
|
|
*/ |
|
396
|
|
|
private function getRelatedDetail($r) |
|
397
|
|
|
{ |
|
398
|
|
|
$related = []; |
|
399
|
|
|
$rel_anime_link = $r->href; |
|
400
|
|
|
$separated_anime_link = explode('/', $rel_anime_link); |
|
401
|
|
|
|
|
402
|
|
|
$related['id'] = $separated_anime_link[2]; |
|
403
|
|
|
$related['title'] = $r->plaintext; |
|
404
|
|
|
$related['type'] = $separated_anime_link[1]; |
|
405
|
|
|
|
|
406
|
|
|
return $related; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* Get anime/manga character and its va. |
|
411
|
|
|
* |
|
412
|
|
|
* @return array |
|
413
|
|
|
*/ |
|
414
|
|
|
private function getCharacter() |
|
415
|
|
|
{ |
|
416
|
|
|
$character = []; |
|
417
|
|
|
$char_index = 0; |
|
418
|
|
|
$character_area = $this->_parser->find('div[class^=detail-characters-list]', 0); |
|
419
|
|
|
if ($character_area) { |
|
420
|
|
|
$character_list = [ |
|
421
|
|
|
$character_area->find('div[class*=fl-l]', 0), |
|
422
|
|
|
$character_area->find('div[class*=fl-r]', 0), |
|
423
|
|
|
]; |
|
424
|
|
|
foreach ($character_list as $character_side) { |
|
425
|
|
|
if ($character_side) { |
|
426
|
|
|
foreach ($character_side->find('table[width=100%]') as $each_char) { |
|
427
|
|
|
$char = $each_char->find('tr td', 1); |
|
428
|
|
|
$va = $each_char->find('table td', 0); |
|
429
|
|
|
|
|
430
|
|
|
$character[$char_index]['id'] = $this->getStaffId($char); |
|
431
|
|
|
$character[$char_index]['name'] = $this->getStaffName($char); |
|
432
|
|
|
$character[$char_index]['role'] = $this->getStaffRole($char); |
|
433
|
|
|
$character[$char_index]['image'] = $this->getStaffImage($each_char); |
|
434
|
|
|
|
|
435
|
|
|
$character[$char_index]['va_id'] = $character[$char_index]['va_name'] = ''; |
|
436
|
|
|
$character[$char_index]['va_role'] = $character[$char_index]['va_image'] = ''; |
|
437
|
|
|
|
|
438
|
|
|
if ($va) { |
|
439
|
|
|
$character[$char_index]['va_id'] = $this->getStaffId($va); |
|
440
|
|
|
$character[$char_index]['va_name'] = $this->getStaffName($va, true); |
|
441
|
|
|
$character[$char_index]['va_role'] = $this->getStaffRole($va); |
|
442
|
|
|
$character[$char_index]['va_image'] = $this->getStaffImage($each_char, true); |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
$char_index++; |
|
446
|
|
|
} |
|
447
|
|
|
} |
|
448
|
|
|
} |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
return $character; |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
/** |
|
455
|
|
|
* Get anime/manga staff involved. |
|
456
|
|
|
* |
|
457
|
|
|
* @return array |
|
458
|
|
|
*/ |
|
459
|
|
|
private function getStaff() |
|
460
|
|
|
{ |
|
461
|
|
|
$staff = []; |
|
462
|
|
|
$staff_index = 0; |
|
463
|
|
|
$staff_area = $this->_parser->find('div[class^=detail-characters-list]', 1); |
|
464
|
|
|
if ($staff_area) { |
|
465
|
|
|
$staff_list = [ |
|
466
|
|
|
$staff_area->find('div[class*=fl-l]', 0), |
|
467
|
|
|
$staff_area->find('div[class*=fl-r]', 0), |
|
468
|
|
|
]; |
|
469
|
|
|
foreach ($staff_list as $staff_side) { |
|
470
|
|
|
if ($staff_side) { |
|
471
|
|
|
foreach ($staff_side->find('table[width=100%]') as $each_staff) { |
|
472
|
|
|
$st = $each_staff->find('tr td', 1); |
|
473
|
|
|
|
|
474
|
|
|
$staff[$staff_index]['id'] = $this->getStaffId($st); |
|
475
|
|
|
$staff[$staff_index]['name'] = $this->getStaffName($st); |
|
476
|
|
|
$staff[$staff_index]['role'] = $this->getStaffRole($st); |
|
477
|
|
|
$staff[$staff_index]['image'] = $this->getStaffImage($each_staff); |
|
478
|
|
|
|
|
479
|
|
|
$staff_index++; |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
return $staff; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* Get staff id. |
|
490
|
|
|
* |
|
491
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $st |
|
492
|
|
|
* |
|
493
|
|
|
* @return string |
|
494
|
|
|
*/ |
|
495
|
|
|
private function getStaffId($st) |
|
496
|
|
|
{ |
|
497
|
|
|
$staff_id = $st->find('a', 0)->href; |
|
498
|
|
|
$staff_id = explode('/', $staff_id); |
|
499
|
|
|
|
|
500
|
|
|
return $staff_id[4]; |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* Get staff name. |
|
505
|
|
|
* |
|
506
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $st |
|
507
|
|
|
* @param bool $va (Optional) |
|
508
|
|
|
* |
|
509
|
|
|
* @return string |
|
510
|
|
|
*/ |
|
511
|
|
|
private function getStaffName($st, $va = false) |
|
512
|
|
|
{ |
|
513
|
|
|
if ($va) { |
|
514
|
|
|
return $st->find('a', 0)->plaintext; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
return trim(preg_replace('/\s+/', ' ', $st->find('a', 0)->plaintext)); |
|
518
|
|
|
} |
|
519
|
|
|
|
|
520
|
|
|
/** |
|
521
|
|
|
* Get staff role. |
|
522
|
|
|
* |
|
523
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $st |
|
524
|
|
|
* |
|
525
|
|
|
* @return string |
|
526
|
|
|
*/ |
|
527
|
|
|
private function getStaffRole($st) |
|
528
|
|
|
{ |
|
529
|
|
|
return trim($st->find('small', 0)->plaintext); |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
/** |
|
533
|
|
|
* Get staff image. |
|
534
|
|
|
* |
|
535
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_staff |
|
536
|
|
|
* @param bool $va (Optional) |
|
537
|
|
|
* |
|
538
|
|
|
* @return string |
|
539
|
|
|
*/ |
|
540
|
|
|
private function getStaffImage($each_staff, $va = false) |
|
541
|
|
|
{ |
|
542
|
|
|
if ($va) { |
|
543
|
|
|
$staff_image = $each_staff->find('table td', 1)->find('img', 0)->getAttribute('data-src'); |
|
544
|
|
|
} else { |
|
545
|
|
|
$staff_image = $each_staff->find('tr td', 0)->find('img', 0)->getAttribute('data-src'); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
return Helper::imageUrlCleaner($staff_image); |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
/** |
|
552
|
|
|
* Get anime/manga opening and ending song. |
|
553
|
|
|
* |
|
554
|
|
|
* @return array |
|
555
|
|
|
*/ |
|
556
|
|
|
private function getSong() |
|
557
|
|
|
{ |
|
558
|
|
|
$song = []; |
|
559
|
|
|
$song_area = $this->_parser->find('div[class*="theme-songs opnening"]', 0); |
|
560
|
|
|
if ($song_area) { |
|
561
|
|
|
foreach ($song_area->find('span.theme-song') as $each_song) { |
|
562
|
|
|
$each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext)); |
|
563
|
|
|
$song['opening'][] = $each_song; |
|
564
|
|
|
} |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
$song_area = $this->_parser->find('div[class*="theme-songs ending"]', 0); |
|
568
|
|
|
if ($song_area) { |
|
569
|
|
|
foreach ($song_area->find('span.theme-song') as $each_song) { |
|
570
|
|
|
$each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext)); |
|
571
|
|
|
$song['closing'][] = $each_song; |
|
572
|
|
|
} |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
return $song; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* Get anime/manga review. |
|
580
|
|
|
* |
|
581
|
|
|
* @return array |
|
582
|
|
|
*/ |
|
583
|
|
|
private function getReview() |
|
584
|
|
|
{ |
|
585
|
|
|
$review = []; |
|
586
|
|
|
$review_area = $this->_parser->find('.js-scrollfix-bottom-rel', 0); |
|
587
|
|
|
$review_area = $review_area->find('table tr', 1); |
|
588
|
|
|
$review_area = $review_area->find('.borderDark'); |
|
589
|
|
|
foreach ($review_area as $each_review) { |
|
590
|
|
|
$tmp = []; |
|
591
|
|
|
|
|
592
|
|
|
$top_area = $each_review->find('.spaceit', 0); |
|
593
|
|
|
$bottom_area = $top_area->next_sibling(); |
|
594
|
|
|
$very_bottom_area = $bottom_area->next_sibling(); |
|
595
|
|
|
|
|
596
|
|
|
$tmp['id'] = $this->getReviewId($very_bottom_area); |
|
597
|
|
|
$tmp['username'] = $this->getReviewUser($top_area); |
|
598
|
|
|
$tmp['image'] = $this->getReviewImage($top_area); |
|
599
|
|
|
$tmp['helpful'] = $this->getReviewHelpful($top_area); |
|
600
|
|
|
$tmp['date'] = $this->getReviewDate($top_area); |
|
601
|
|
|
if ($this->_type == 'anime') { |
|
602
|
|
|
$tmp['episode'] = $this->getReviewEpisode($top_area); |
|
603
|
|
|
} else { |
|
604
|
|
|
$tmp['chapter'] = $this->getReviewEpisode($top_area); |
|
605
|
|
|
} |
|
606
|
|
|
$tmp['score'] = $this->getReviewScore($bottom_area); |
|
607
|
|
|
$tmp['review'] = $this->getReviewText($bottom_area); |
|
608
|
|
|
|
|
609
|
|
|
$review[] = $tmp; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
return $review; |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
/** |
|
616
|
|
|
* Get review user. |
|
617
|
|
|
* |
|
618
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $very_bottom_area |
|
619
|
|
|
* |
|
620
|
|
|
* @return string |
|
621
|
|
|
*/ |
|
622
|
|
|
private function getReviewId($very_bottom_area) |
|
623
|
|
|
{ |
|
624
|
|
|
$id = $very_bottom_area->find('a', 0)->href; |
|
625
|
|
|
$id = explode('?id=', $id); |
|
626
|
|
|
|
|
627
|
|
|
return $id[1]; |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
/** |
|
631
|
|
|
* Get review id. |
|
632
|
|
|
* |
|
633
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $top_area |
|
634
|
|
|
* |
|
635
|
|
|
* @return string |
|
636
|
|
|
*/ |
|
637
|
|
|
private function getReviewUser($top_area) |
|
638
|
|
|
{ |
|
639
|
|
|
$user = $top_area->find('table', 0); |
|
640
|
|
|
|
|
641
|
|
|
return $user->find('td', 1)->find('a', 0)->plaintext; |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
/** |
|
645
|
|
|
* Get review image. |
|
646
|
|
|
* |
|
647
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $top_area |
|
648
|
|
|
* |
|
649
|
|
|
* @return string |
|
650
|
|
|
*/ |
|
651
|
|
|
private function getReviewImage($top_area) |
|
652
|
|
|
{ |
|
653
|
|
|
$image = $top_area->find('table', 0); |
|
654
|
|
|
$image = $image->find('td', 0)->find('img', 0)->src; |
|
655
|
|
|
|
|
656
|
|
|
return Helper::imageUrlCleaner($image); |
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
/** |
|
660
|
|
|
* Get review helful. |
|
661
|
|
|
* |
|
662
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $top_area |
|
663
|
|
|
* |
|
664
|
|
|
* @return string |
|
665
|
|
|
*/ |
|
666
|
|
|
private function getReviewHelpful($top_area) |
|
667
|
|
|
{ |
|
668
|
|
|
$helpful = $top_area->find('table', 0); |
|
669
|
|
|
$helpful = $helpful->find('td', 1)->find('strong', 0)->plaintext; |
|
670
|
|
|
|
|
671
|
|
|
return trim($helpful); |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
/** |
|
675
|
|
|
* Get review date. |
|
676
|
|
|
* |
|
677
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $top_area |
|
678
|
|
|
* |
|
679
|
|
|
* @return array |
|
680
|
|
|
*/ |
|
681
|
|
|
private function getReviewDate($top_area) |
|
682
|
|
|
{ |
|
683
|
|
|
$date = $top_area->find('div div', 0); |
|
684
|
|
|
|
|
685
|
|
|
return [ |
|
686
|
|
|
'date' => $date->plaintext, |
|
687
|
|
|
'time' => $date->title, |
|
688
|
|
|
]; |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
/** |
|
692
|
|
|
* Get review episode seen. |
|
693
|
|
|
* |
|
694
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $top_area |
|
695
|
|
|
* |
|
696
|
|
|
* @return string |
|
697
|
|
|
*/ |
|
698
|
|
|
private function getReviewEpisode($top_area) |
|
699
|
|
|
{ |
|
700
|
|
|
$episode = $top_area->find('div div', 1)->plaintext; |
|
701
|
|
|
$episode = str_replace(['episodes seen', 'chapters read'], '', $episode); |
|
702
|
|
|
|
|
703
|
|
|
return trim($episode); |
|
704
|
|
|
} |
|
705
|
|
|
|
|
706
|
|
|
/** |
|
707
|
|
|
* Get review score. |
|
708
|
|
|
* |
|
709
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $bottom_area |
|
710
|
|
|
* |
|
711
|
|
|
* @return array |
|
712
|
|
|
*/ |
|
713
|
|
|
private function getReviewScore($bottom_area) |
|
714
|
|
|
{ |
|
715
|
|
|
$score = []; |
|
716
|
|
|
$score_area = $bottom_area->find('table', 0); |
|
717
|
|
|
if ($score_area) { |
|
718
|
|
|
foreach ($score_area->find('tr') as $each_score) { |
|
719
|
|
|
$score_type = strtolower($each_score->find('td', 0)->plaintext); |
|
720
|
|
|
$score_value = $each_score->find('td', 1)->plaintext; |
|
721
|
|
|
$score[$score_type] = $score_value; |
|
722
|
|
|
} |
|
723
|
|
|
} |
|
724
|
|
|
|
|
725
|
|
|
return $score; |
|
726
|
|
|
} |
|
727
|
|
|
|
|
728
|
|
|
/** |
|
729
|
|
|
* Get review text. |
|
730
|
|
|
* |
|
731
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $bottom_area |
|
732
|
|
|
* |
|
733
|
|
|
* @return string |
|
734
|
|
|
*/ |
|
735
|
|
|
private function getReviewText($bottom_area) |
|
736
|
|
|
{ |
|
737
|
|
|
$useless_area_1 = $bottom_area->find('div', 0)->plaintext; |
|
738
|
|
|
$useless_area_2 = $bottom_area->find('div[id^=revhelp_output]', 0)->plaintext; |
|
739
|
|
|
$useless_area_3 = $bottom_area->find('a[id^=reviewToggle]', 0) ? $bottom_area->find('a[id^=reviewToggle]', 0)->plaintext : null; |
|
740
|
|
|
$text = str_replace([$useless_area_1, $useless_area_2, $useless_area_3], '', $bottom_area->plaintext); |
|
741
|
|
|
$text = str_replace('<', '<', $text); |
|
742
|
|
|
|
|
743
|
|
|
return trim(preg_replace('/\h+/', ' ', $text)); |
|
744
|
|
|
} |
|
745
|
|
|
|
|
746
|
|
|
/** |
|
747
|
|
|
* Get anime/manga all information. |
|
748
|
|
|
* |
|
749
|
|
|
* @return array |
|
750
|
|
|
*/ |
|
751
|
|
|
private function getAllInfo() |
|
752
|
|
|
{ |
|
753
|
|
|
$data = [ |
|
754
|
|
|
'id' => $this->getId(), |
|
755
|
|
|
'cover' => $this->getCover(), |
|
756
|
|
|
'title' => $this->getTitle(), |
|
757
|
|
|
'title2' => $this->getTitle2(), |
|
758
|
|
|
'video' => $this->getVideo(), |
|
759
|
|
|
'synopsis' => $this->getSynopsis(), |
|
760
|
|
|
'score' => $this->getScore(), |
|
761
|
|
|
'voter' => $this->getVoter(), |
|
762
|
|
|
'rank' => $this->getRank(), |
|
763
|
|
|
'popularity'=> $this->getPopularity(), |
|
764
|
|
|
'members' => $this->getMembers(), |
|
765
|
|
|
'favorite' => $this->getFavorite(), |
|
766
|
|
|
]; |
|
767
|
|
|
|
|
768
|
|
|
$data = array_merge($data, $this->getOtherInfo()); |
|
769
|
|
|
|
|
770
|
|
|
$data2 = [ |
|
771
|
|
|
'related' => $this->getRelated(), |
|
772
|
|
|
'character' => $this->getCharacter(), |
|
773
|
|
|
'staff' => $this->getStaff(), |
|
774
|
|
|
'song' => $this->getSong(), |
|
775
|
|
|
'review' => $this->getReview(), |
|
776
|
|
|
]; |
|
777
|
|
|
|
|
778
|
|
|
$data = array_merge($data, $data2); |
|
779
|
|
|
|
|
780
|
|
|
return $data; |
|
781
|
|
|
} |
|
782
|
|
|
} |
|
783
|
|
|
|