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

AEBN::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Blacklight\processing\adult;
4
5
use voku\helper\SimpleHtmlDomNodeBlank;
6
7
class AEBN extends AdultMovies
8
{
9
    /**
10
     * Keyword to search.
11
     *
12
     * @var string
13
     */
14
    public $searchTerm = '';
15
16
    /**
17
     * Url Constants used within this class.
18
     */
19
    private const AEBNSURL = 'http://straight.theater.aebn.net';
20
    private const TRAILINGSEARCH = '/dispatcher/fts?theaterId=13992&genreId=101&locale=en&count=30&imageType=Large&targetSearchMode=basic&isAdvancedSearch=false&isFlushAdvancedSearchCriteria=false&sortType=Relevance&userQuery=title%3A+%2B';
21
    private const TRAILERURL = '/dispatcher/previewPlayer?locale=en&theaterId=13992&genreId=101&movieId=';
22
23
    /**
24
     * Direct Url in getAll method.
25
     *
26
     * @var string
27
     */
28
    protected $_directUrl = '';
29
30
    /**
31
     * Raw Html response from curl.
32
     */
33
    protected $_response;
34
35
    /**
36
     * @var string
37
     */
38
    protected $_trailerUrl = '';
39
40
    /**
41
     * Returned results in all methods except search/geturl.
42
     *
43
     * @var array
44
     */
45
    protected $_res = [
46
        'backcover'   => [],
47
        'boxcover'    => [],
48
        'cast'        => [],
49
        'director'    => [],
50
        'genres'      => [],
51
        'productinfo' => [],
52
        'synopsis'    => [],
53
        'trailers'    => ['url' => []],
54
    ];
55
56
    /**
57
     * Sets title in getAll method.
58
     *
59
     * @var string
60
     */
61
    protected $_title = '';
62
63
    /**
64
     * Gets Trailer URL .. will be processed in XXX insertswf.
65
     *
66
     *
67
     * @return array|mixed
68
     */
69
    protected function trailers()
70
    {
71
        $ret = $this->_html->find('a[itemprop=trailer]', 0);
72
        if (! empty($ret) && preg_match('/movieId=(?<movieid>\d+)&/', trim($ret->href), $matches)) {
0 ignored issues
show
Bug introduced by
It seems like $ret->href 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

72
        if (! empty($ret) && preg_match('/movieId=(?<movieid>\d+)&/', trim(/** @scrutinizer ignore-type */ $ret->href), $matches)) {
Loading history...
73
            $movieid = $matches['movieid'];
74
            $this->_res['trailers']['url'] = self::AEBNSURL.self::TRAILERURL.$movieid;
75
        }
76
77
        return $this->_res;
78
    }
79
80
    /**
81
     * Gets the front and back cover of the box.
82
     *
83
     * @return array
84
     */
85
    protected function covers()
86
    {
87
        $ret = $this->_html->find('div#md-boxCover, img[itemprop=thumbnailUrl]', 1);
88
        if ($ret !== false) {
0 ignored issues
show
introduced by
The condition $ret !== false is always true.
Loading history...
89
            $ret = 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

89
            $ret = trim(/** @scrutinizer ignore-type */ $ret->src);
Loading history...
90
            if (strpos($ret, '//') === 0) {
91
                $ret = 'https:'.$ret;
92
            }
93
            $this->_res['boxcover'] = str_ireplace('160w.jpg', 'xlf.jpg', $ret);
94
            $this->_res['backcover'] = str_ireplace('160w.jpg', 'xlb.jpg', $ret);
95
        }
96
97
        return $this->_res;
98
    }
99
100
    /**
101
     * Gets the Genres "Categories".
102
     *
103
     * @return array
104
     */
105
    protected function genres()
106
    {
107
        if ($ret = $this->_html->findOne('div.md-detailsCategories')) {
108
            foreach ($ret->find('a[itemprop=genre]') as $genre) {
109
                $this->_res['genres'][] = trim($genre->plaintext);
110
            }
111
        }
112
        if (! empty($this->_res['genres'])) {
113
            $this->_res['genres'] = array_unique($this->_res['genres']);
114
        }
115
116
        return $this->_res;
117
    }
118
119
    /**
120
     * Gets the Cast Members "Stars" and Director if any.
121
     *
122
     * @return array
123
     */
124
    protected function cast()
125
    {
126
        $this->_res = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type array of property $_res.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
127
        $ret = $this->_html->findOne('div.starsFull');
128
        if (! $ret instanceof SimpleHtmlDomNodeBlank) {
129
            foreach ($ret->find('span[itemprop=name]') as $star) {
130
                $this->_res['cast'][] = trim($star->plaintext);
131
            }
132
        } else {
133
            $ret = $this->_html->findOne('div.detailsLink');
134
            if (! $ret instanceof SimpleHtmlDomNodeBlank) {
135
                foreach ($ret->find('span') as $star) {
136
                    if (strpos($star->plaintext, '/More/') !== false && strpos($star->plaintext, '/Stars/') !== false) {
137
                        $this->_res['cast'][] = trim($star->plaintext);
138
                    }
139
                }
140
            }
141
        }
142
143
        return $this->_res;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_res returns the type false which is incompatible with the documented return type array.
Loading history...
144
    }
145
146
    /**
147
     * Gets the product information.
148
     *
149
     * @param bool $extras
150
     *
151
     * @return array
152
     */
153
    protected function productInfo($extras = false)
154
    {
155
        if ($ret = $this->_html->find('div#md-detailsLeft', 0)) {
156
            foreach ($ret->find('div') as $div) {
157
                foreach ($div->find('span') as $span) {
158
                    $text = rawurldecode($span->plaintext);
159
                    $text = preg_replace('/&nbsp;/', '', $text);
160
                    $this->_res['productinfo'][] = trim($text);
161
                }
162
            }
163
            if (false !== $key = array_search('Running Time:', $this->_res['productinfo'], false)) {
164
                unset($this->_res['productinfo'][$key + 2]);
165
            }
166
            if (false !== $key = array_search('Director:', $this->_res['productinfo'], false)) {
167
                $this->_res['director'] = $this->_res['productinfo'][$key + 1];
168
                unset($this->_res['productinfo'][$key], $this->_res['productinfo'][$key + 1]);
169
            }
170
            $this->_res['productinfo'] = array_chunk($this->_res['productinfo'], 2, false);
171
        }
172
173
        return $this->_res;
174
    }
175
176
    /**
177
     * Gets the synopsis "plot".
178
     *
179
     * @return array
180
     */
181
    protected function synopsis()
182
    {
183
        if ($ret = $this->_html->findOne('span[itemprop=about]')) {
184
            if ($ret === null) {
185
                if ($ret = $this->_html->findOne('div.movieDetailDescription')) {
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
186
                    $this->_res['synopsis'] = preg_replace('/Description:\s/', '', $this->_res['plot']);
187
                }
188
            } else {
189
                $this->_res['synopsis'] = trim($ret->plaintext);
190
            }
191
        }
192
193
        return $this->_res;
194
    }
195
196
    /**
197
     * Searches for a XXX name.
198
     *
199
     * @param string $movie
200
     *
201
     * @return bool
202
     */
203
    public function processSite($movie): bool
204
    {
205
        if (empty($movie)) {
206
            return false;
207
        }
208
        $this->_trailerUrl = self::TRAILINGSEARCH.urlencode($movie);
209
        $this->_response = getRawHtml(self::AEBNSURL.$this->_trailerUrl, $this->cookie);
0 ignored issues
show
Bug Best Practice introduced by
The property cookie does not exist on Blacklight\processing\adult\AEBN. Did you maybe forget to declare it?
Loading history...
210
        if ($this->_response !== false) {
211
            $i = 1;
212
            foreach ($this->_html->loadHtml($this->_response)->find('div.movie') as $mov) {
213
                $string = 'a#FTSMovieSearch_link_title_detail_'.$i;
214
                if ($ret = $mov->findOne($string)) {
215
                    $title = str_replace('/XXX/', '', $ret->title);
216
                    $title = trim(preg_replace('/\(.*?\)|[-._]/', ' ', $title));
217
                    similar_text(strtolower($movie), strtolower($title), $p);
218
                    if ($p >= 90) {
219
                        $this->_title = trim($ret->title);
220
                        $this->_trailerUrl = html_entity_decode($ret->href);
221
                        $this->_directUrl = self::AEBNSURL.$this->_trailerUrl;
222
                        unset($this->_response);
223
                        $this->_response = getRawHtml(self::AEBNSURL.$this->_trailerUrl, $this->cookie);
224
                        $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

224
                        $this->_html->loadHtml(/** @scrutinizer ignore-type */ $this->_response);
Loading history...
225
226
                        return true;
227
                    }
228
                    continue;
229
                }
230
                $i++;
231
            }
232
        }
233
234
        return false;
235
    }
236
}
237