1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MalScraper\Model\Lists; |
4
|
|
|
|
5
|
|
|
use MalScraper\Model\MainModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* AllProducerModel class. |
9
|
|
|
*/ |
10
|
|
|
class AllProducerModel extends MainModel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Either anime or manga. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $_type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Default constructor. |
21
|
|
|
* |
22
|
|
|
* @param string $type |
23
|
|
|
* @param string $parserArea |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function __construct($type, $parserArea = '.anime-manga-search') |
28
|
|
|
{ |
29
|
|
|
$this->_type = $type; |
30
|
|
|
if ($type == 'anime') { |
31
|
|
|
$this->_url = $this->_myAnimeListUrl.'/anime/producer'; |
32
|
|
|
} else { |
33
|
|
|
$this->_url = $this->_myAnimeListUrl.'/manga/magazine'; |
34
|
|
|
} |
35
|
|
|
$this->_parserArea = $parserArea; |
36
|
|
|
|
37
|
|
|
parent::errorCheck($this); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Default call. |
42
|
|
|
* |
43
|
|
|
* @param string $method |
44
|
|
|
* @param array $arguments |
45
|
|
|
* |
46
|
|
|
* @return array|string|int |
47
|
|
|
*/ |
48
|
|
|
public function __call($method, $arguments) |
49
|
|
|
{ |
50
|
|
|
if ($this->_error) { |
51
|
|
|
return $this->_error; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return call_user_func_array([$this, $method], $arguments); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get producer id. |
59
|
|
|
* |
60
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_studio |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
private function getProducerId($each_studio) |
65
|
|
|
{ |
66
|
|
|
$link = $each_studio->href; |
67
|
|
|
$link = explode('/', $link); |
68
|
|
|
|
69
|
|
|
return $link[3]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get producer name. |
74
|
|
|
* |
75
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_studio |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
private function getProducerName($each_studio) |
80
|
|
|
{ |
81
|
|
|
$name = $each_studio->plaintext; |
82
|
|
|
|
83
|
|
|
return trim(preg_replace('/\([0-9,]+\)/', '', $name)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get producer count. |
88
|
|
|
* |
89
|
|
|
* @param \simplehtmldom_1_5\simple_html_dom $each_studio |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
private function getProducerCount($each_studio) |
94
|
|
|
{ |
95
|
|
|
$count = $each_studio->plaintext; |
96
|
|
|
preg_match('/\([0-9,]+\)/', $count, $cnt); |
97
|
|
|
$count = substr($cnt[0], 1, strlen($cnt[0]) - 2); |
98
|
|
|
|
99
|
|
|
return str_replace(',', '', $count); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get list of all [producer]. |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
private function getAllInfo() |
108
|
|
|
{ |
109
|
|
|
$data = []; |
110
|
|
|
foreach ($this->_parser->find('.genre-list a') as $each_studio) { |
111
|
|
|
$studio = []; |
112
|
|
|
|
113
|
|
|
$studio['id'] = $this->getProducerId($each_studio); |
114
|
|
|
$studio['name'] = $this->getProducerName($each_studio); |
115
|
|
|
$studio['count'] = $this->getProducerCount($each_studio); |
116
|
|
|
|
117
|
|
|
$data[] = $studio; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $data; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|