Completed
Push — dev ( 7d51be...c4b666 )
by Darko
07:23
created

Hotmovies::processSite()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 40
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 40
ccs 0
cts 26
cp 0
rs 8.2114
c 0
b 0
f 0
cc 8
nc 8
nop 1
crap 72
1
<?php
2
3
namespace Blacklight\processing\adult;
4
5
class Hotmovies extends AdultMovies
6
{
7
    /**
8
     * Constant Urls used within this class
9
     * Needed Search Queries Variables.
10
     */
11
    private const EXTRASEARCH = '&complete=on&search_in=video_title';
12
    private const HMURL = 'http://www.hotmovies.com';
13
    private const TRAILINGSEARCH = '/search.php?words=';
14
    /**
15
     * Keyword Search.
16
     *
17
     * @var string
18
     */
19
    protected $searchTerm = '';
20
    /**
21
     * Define a cookie location.
22
     *
23
     * @var string
24
     */
25
    public $cookie = '';
26
    /**
27
     * If a direct link is set parse it instead of search for it.
28
     *
29
     * @var string
30
     */
31
    protected $directLink = '';
32
    /**
33
     * Sets the direct url in the getAll method.
34
     *
35
     * @var string
36
     */
37
    protected $_directUrl = '';
38
39
    /**
40
     * Sets the link to get in curl.
41
     *
42
     * @var string
43
     */
44
    protected $_getLink = '';
45
46
    /**
47
     * POST parameters used with curl.
48
     *
49
     * @var array
50
     */
51
    protected $_postParams = [];
52
53
    /**
54
     * Results return from some methods.
55
     *
56
     * @var array
57
     */
58
    protected $_res = [];
59
60
    /**
61
     * Raw Html from Curl.
62
     */
63
    protected $_response;
64
65
    /**
66
     * Sets the title in the getAll method.
67
     *
68
     * @var string
69
     */
70
    protected $_title = '';
71
72
    protected function trailers()
73
    {
74
        // TODO: Implement trailers() method.
75
76
        return false;
77
    }
78
79
    /**
80
     * Gets the synopsis.
81
     *
82
     * @return array
83
     */
84
    protected function synopsis(): array
85
    {
86
        $this->_res['synopsis'] = 'N/A';
87
        if ($this->_html->findOne('.desc_link')) {
88
            $ret = $this->_html->findOne('.video_description');
89
            if ($ret !== false) {
0 ignored issues
show
introduced by
The condition $ret !== false is always true.
Loading history...
90
                $this->_res['synopsis'] = trim($ret->innerText);
91
            }
92
        }
93
94
        return $this->_res;
95
    }
96
97
    /**
98
     * Process ProductInfo.
99
     *
100
     * @param bool $extras
101
     *
102
     * @return array
103
     */
104
    protected function productInfo($extras = false): array
105
    {
106
        $studio = false;
107
        $director = false;
108
        if ($ret = $this->_html->find('div.page_video_info')) {
109
            foreach ($ret->find('text') as $e) {
110
                $e = trim($e->plaintext);
111
                $rArray = [',', '...', '&nbsp:'];
112
                $e = str_replace($rArray, '', $e);
113
                if (stripos($e, 'Studio:') !== false) {
114
                    $studio = true;
115
                }
116
                if (strpos($e, 'Director:') !== false) {
117
                    $director = true;
118
                    $e = null;
119
                }
120
                if ($studio === true) {
121
                    if ((stripos($e, 'Custodian of Records') === false) && stripos($e, 'Description') === false) {
122
                        if ($director === true && ! empty($e)) {
123
                            $this->_res['director'] = $e;
124
                            $e = null;
125
                            $director = false;
126
                        }
127
                        if (! empty($e)) {
128
                            $this->_res['productinfo'][] = $e;
129
                        }
130
                    } else {
131
                        break;
132
                    }
133
                }
134
            }
135
        }
136
        if (isset($this->_res['productinfo']) && \is_array($this->_res['productinfo'])) {
137
            $this->_res['productinfo'] = array_chunk($this->_res['productinfo'], 2, false);
138
        }
139
140
        return $this->_res;
141
    }
142
143
    /**
144
     * Gets the cast members and director.
145
     *
146
     * @return array
147
     */
148
    protected function cast()
149
    {
150
        $cast = [];
151
        if ($this->_html->find('.stars bottom_margin')) {
152
            foreach ($this->_html->find('a[title]') as $e) {
153
                $e = trim($e->title);
154
                $e = preg_replace('/\((.*)\)/', '', $e);
155
                $cast[] = trim($e);
156
            }
157
            $this->_res['cast'] = $cast;
158
        }
159
160
        return $this->_res;
161
    }
162
163
    /**
164
     * Gets categories.
165
     *
166
     * @return array
167
     */
168
    protected function genres()
169
    {
170
        $genres = [];
171
        if ($ret = $this->_html->findOne('div.categories')) {
172
            foreach ($ret->find('a') as $e) {
173
                if (strpos($e->title, ' -> ') !== false) {
174
                    $e = explode(' -> ', $e->plaintext);
175
                    $genres[] = trim($e[1]);
176
                }
177
            }
178
            $this->_res['genres'] = $genres;
179
        }
180
181
        return $this->_res;
182
    }
183
184
    /**
185
     * Get Box Cover Images.
186
     *
187
     *
188
     * @return array|false|mixed
189
     */
190
    protected function covers()
191
    {
192
        if ($ret = $this->_html->find('div#large_cover, img#cover', 1)) {
193
            $this->_res['boxcover'] = trim($ret->src);
0 ignored issues
show
Bug introduced by
It seems like $ret->src can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

193
            $this->_res['boxcover'] = trim(/** @scrutinizer ignore-type */ $ret->src);
Loading history...
194
            $this->_res['backcover'] = str_ireplace('.cover', '.back', trim($ret->src));
195
        } else {
196
            return false;
197
        }
198
199
        return $this->_res;
200
    }
201
202
    /**
203
     * Searches for match against xxx movie name.
204
     *
205
     * @param string $movie
206
     *
207
     * @return bool , true if search >= 90%
208
     */
209
    public function processSite($movie): bool
210
    {
211
        if (empty($movie)) {
212
            return false;
213
        }
214
        $this->_response = false;
215
        $this->_getLink = self::HMURL.self::TRAILINGSEARCH.urlencode($movie).self::EXTRASEARCH;
216
        $this->_response = getRawHtml($this->_getLink, $this->cookie);
217
        if ($this->_response !== false) {
218
            if ($ret = $this->_html->loadHtml($this->_response)->findOne('h3[class=title]')) {
219
                if ($ret->findOne('a[title]')) {
0 ignored issues
show
Bug introduced by
The method findOne() does not exist on voku\helper\SimpleHtmlDomNodeInterface. Did you maybe mean find()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

219
                if ($ret->/** @scrutinizer ignore-call */ findOne('a[title]')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
220
                    $ret = $ret->findOne('a[title]');
221
                    $title = trim($ret->title);
0 ignored issues
show
Bug introduced by
It seems like $ret->title can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

221
                    $title = trim(/** @scrutinizer ignore-type */ $ret->title);
Loading history...
222
                    $title = str_replace('/XXX/', '', $title);
223
                    $title = preg_replace('/\(.*?\)|[-._]/', ' ', $title);
224
                    if (! empty($title)) {
225
                        similar_text($movie, $title, $p);
226
                        if ($p >= 90) {
227
                            $this->_title = $title;
228
                            $this->_getLink = trim($ret->href);
229
                            $this->_directUrl = trim($ret->href);
230
                            unset($this->_response);
231
                            if ($this->_getLink !== false) {
232
                                $this->_response = getRawHtml($this->_getLink, $this->cookie);
233
                                $this->_html->loadHtml($this->_response);
0 ignored issues
show
Bug introduced by
It seems like $this->_response can also be of type false; however, parameter $html of voku\helper\HtmlDomParser::loadHtml() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

233
                                $this->_html->loadHtml(/** @scrutinizer ignore-type */ $this->_response);
Loading history...
234
                            } else {
235
                                $this->_response = getRawHtml($this->_directUrl, $this->cookie);
236
                                $this->_html->loadHtml($this->_response);
237
                            }
238
239
                            return true;
240
                        }
241
                    }
242
                }
243
            }
244
        } else {
245
            return false;
246
        }
247
248
        return false;
249
    }
250
}
251