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