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

ADE::genres()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
namespace Blacklight\processing\adult;
4
5
/**
6
 * Class ADE
7
 */
8
class ADE extends AdultMovies
9
{
10
    /**
11
     * If a direct link is given parse it rather then search.
12
     * @var string
13
     */
14
    protected $directLink = '';
15
16
    /**
17
     * Search keyword.
18
     * @var string
19
     */
20
    protected $searchTerm = '';
21
22
    /**
23
     * Define ADE Url here.
24
     */
25
    private const ADE = 'http://www.adultdvdempire.com';
26
27
    /**
28
     * Direct Url returned in getAll method.
29
     *
30
     * @var string
31
     */
32
    protected $_directUrl = '';
33
34
    /**
35
     * Sets the title in the getAll method.
36
     *
37
     * @var string
38
     */
39
    protected $_title = '';
40
41
    /** Trailing urls */
42
    protected $_dvdQuery = '/dvd/search?q=';
43
    protected $_scenes = '/scenes';
44
    protected $_boxCover = '/boxcover';
45
    protected $_backCover = '/backcover';
46
    protected $_reviews = '/reviews';
47
    protected $_trailers = '/trailers';
48
49
    protected $_url;
50
    protected $_response;
51
    protected $_res = [];
52
    protected $_tmpResponse;
53
    protected $_ch;
54
55
    /**
56
     * Gets Trailer Movies.
57
     * @return array - url, streamid, basestreamingurl
58
     */
59
    protected function trailers()
60
    {
61
        $this->_response = getRawHtml(self::ADE.$this->_trailers.$this->_directUrl);
62
        $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

62
        $this->_html->loadHtml(/** @scrutinizer ignore-type */ $this->_response);
Loading history...
63
        if (preg_match("/(\"|')(?P<swf>[^\"']+.swf)(\"|')/i", $this->_response, $matches)) {
0 ignored issues
show
Bug introduced by
It seems like $this->_response can also be of type false; however, parameter $subject of preg_match() 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

63
        if (preg_match("/(\"|')(?P<swf>[^\"']+.swf)(\"|')/i", /** @scrutinizer ignore-type */ $this->_response, $matches)) {
Loading history...
64
            $this->_res['trailers']['url'] = self::ADE.trim(trim($matches['swf']), '"');
65
            if (preg_match(
66
                '#(?:streamID:\s\")(?P<streamid>[0-9A-Z]+)(?:\")#',
67
                $this->_response,
68
                $matches
69
            )
70
            ) {
71
                $this->_res['trailers']['streamid'] = trim($matches['streamid']);
72
            }
73
            if (preg_match(
74
                '#(?:BaseStreamingUrl:\s\")(?P<baseurl>[\d]+.[\d]+.[\d]+.[\d]+)(?:\")#',
75
                $this->_response,
76
                $matches
77
            )
78
            ) {
79
                $this->_res['trailers']['baseurl'] = $matches['baseurl'];
80
            }
81
        }
82
83
        return $this->_res;
84
    }
85
86
    /**
87
     * Gets cover images for the xxx release.
88
     * @return array - Boxcover and backcover
89
     */
90
    protected function covers()
91
    {
92
        if ($ret = $this->_html->find('div#Boxcover, img[itemprop=image]', 1)) {
93
            $this->_res['boxcover'] = preg_replace('/m\.jpg/', 'h.jpg', $ret->src);
94
            $this->_res['backcover'] = preg_replace('/m\.jpg/', 'bh.jpg', $ret->src);
95
        }
96
97
        return $this->_res;
98
    }
99
100
    /**
101
     * Gets the synopsis.
102
     *
103
     * @return array - plot
104
     */
105
    protected function synopsis()
106
    {
107
        $ret = $this->_html->findOne('meta[name=og:description]')->content;
108
        if ($ret !== false) {
0 ignored issues
show
introduced by
The condition $ret !== false is always true.
Loading history...
109
            $this->_res['synopsis'] = trim($ret);
0 ignored issues
show
Bug introduced by
It seems like $ret 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

109
            $this->_res['synopsis'] = trim(/** @scrutinizer ignore-type */ $ret);
Loading history...
110
        }
111
112
        return $this->_res;
113
    }
114
115
    /**
116
     * Gets the cast members and/or awards.
117
     *
118
     *
119
     * @return array - cast, awards
120
     */
121
    protected function cast()
122
    {
123
        $cast = [];
124
        foreach ($this->_html->find('h3') as $a) {
125
            if ($a->plaintext !== false) {
126
                $cast[] = trim($a->plaintext);
127
            }
128
        }
129
        $this->_res['cast'] = $cast;
130
131
        return $this->_res;
132
    }
133
134
    /**
135
     * Gets Genres, if exists return array else return false.
136
     * @return mixed array - Genres
137
     */
138
    protected function genres()
139
    {
140
        $genres = [];
141
        foreach ($this->_html->find('[Label="Category"]') as $a) {
142
            if ($a->plaintext !== false) {
143
                $genres[] = trim($a->plaintext);
144
            }
145
        }
146
        $this->_res['genres'] = $genres;
147
148
        return $this->_res;
149
    }
150
151
    /**
152
     * Gets Product Information and/or Features.
153
     *
154
     * @param bool $extras
155
     * @return array - ProductInfo/Extras = features
156
     */
157
    protected function productInfo($extras = false)
158
    {
159
        $dofeature = null;
160
        $this->_tmpResponse = str_ireplace('Section ProductInfo', 'spdinfo', $this->_response);
161
        $this->_html->loadHtml($this->_tmpResponse);
162
        if ($ret = $this->_html->findOne('div[class=spdinfo]')) {
163
            $this->_tmpResponse = trim($ret->outertext);
164
            $ret = $this->_html->loadHtml($this->_tmpResponse);
165
            foreach ($ret->find('text') as $strong) {
166
                if (trim($strong->innertext) === 'Features') {
167
                    $dofeature = true;
168
                }
169
                if ($dofeature !== true) {
170
                    if (trim($strong->innertext) !== '&nbsp;') {
171
                        $this->_res['productinfo'][] = trim($strong->innertext);
172
                    }
173
                } else {
174
                    if ($extras === true) {
175
                        $this->_res['extras'][] = trim($strong->innertext);
176
                    }
177
                }
178
            }
179
180
            array_shift($this->_res['productinfo']);
181
            array_shift($this->_res['productinfo']);
182
            $this->_res['productinfo'] = array_chunk($this->_res['productinfo'], 2, false);
183
        }
184
185
        return $this->_res;
186
    }
187
188
    /**
189
     * Searches xxx name.
190
     *
191
     * @param string $movie
192
     *
193
     * @return bool - True if releases has 90% match, else false
194
     */
195
    public function processSite($movie): bool
196
    {
197
        if (empty($movie)) {
198
            return false;
199
        }
200
        $this->_response = getRawHtml(self::ADE.$this->_dvdQuery.rawurlencode($movie));
201
        if ($this->_response !== false) {
202
            if ($res = $this->_html->loadHtml($this->_response)->find('a[class=fancybox-button]')) {
203
                foreach ($res as $ret) {
204
                    $title = $ret->title;
205
                    $title = str_replace('/XXX/', '', $title);
206
                    $title = preg_replace('/\(.*?\)|[-._]/', ' ', $title);
207
                    $url = trim($ret->href);
208
                    similar_text(strtolower($movie), strtolower($title), $p);
209
                    if ($p >= 90) {
210
                        $this->_directUrl = self::ADE.$url;
211
                        $this->_title = trim($title);
212
                        unset($this->_response);
213
                        $this->_response = getRawHtml($this->_directUrl);
214
                        $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

214
                        $this->_html->loadHtml(/** @scrutinizer ignore-type */ $this->_response);
Loading history...
215
216
                        return true;
217
                    }
218
                }
219
220
                return false;
221
            }
222
223
            return false;
224
        }
225
226
        return false;
227
    }
228
}
229