1 | <?php |
||
12 | class WeburgClient |
||
13 | { |
||
14 | /** |
||
15 | * @var ClientInterface |
||
16 | */ |
||
17 | private $httpClient; |
||
18 | |||
19 | private $requestDelay; |
||
20 | |||
21 | /** |
||
22 | * WeburgClient constructor. |
||
23 | * @param ClientInterface $httpClient |
||
24 | * @param int $requestDelay |
||
25 | */ |
||
26 | public function __construct(ClientInterface $httpClient, $requestDelay = 0) |
||
31 | |||
32 | /** |
||
33 | * @param $movieId |
||
34 | * @return array |
||
35 | * @throws GuzzleException |
||
36 | */ |
||
37 | public function getMovieInfoById($movieId) |
||
45 | |||
46 | /** |
||
47 | * @param $movieId |
||
48 | * @return array urls of movie (not series) |
||
49 | * @throws GuzzleException |
||
50 | */ |
||
51 | public function getMovieTorrentUrlsById($movieId) |
||
58 | |||
59 | /** |
||
60 | * @param $movieId |
||
61 | * @param $hashes array hashes of torrents from movieInfo |
||
62 | * @param int $daysMax torrents older last days will not matched |
||
63 | * @param int $allowedMisses after x misses next checks will broken |
||
64 | * @return array urls of matched torrent files |
||
65 | * @throws GuzzleException |
||
66 | */ |
||
67 | public function getSeriesTorrents($movieId, $hashes, $daysMax = 1, $allowedMisses = 0) |
||
91 | |||
92 | /** |
||
93 | * @param string $moviesUrl |
||
94 | * @return array |
||
95 | * @throws GuzzleException |
||
96 | */ |
||
97 | public function getMoviesIds($moviesUrl = 'https://weburg.net/movies/new/?clever_title=1&template=0&last=0') |
||
115 | |||
116 | /** |
||
117 | * @param $q |
||
118 | * @return bool|string |
||
119 | * @throws GuzzleException |
||
120 | */ |
||
121 | public function getMovieIdByQuery($q) |
||
131 | |||
132 | /** |
||
133 | * @param $q |
||
134 | * @return mixed |
||
135 | * @throws GuzzleException |
||
136 | */ |
||
137 | public function movieQuery($q) |
||
151 | |||
152 | public static function getMovieUrl($movieId) |
||
156 | |||
157 | /** |
||
158 | * @param $url |
||
159 | * @param array $headers |
||
160 | * @return ResponseInterface |
||
161 | * @throws RuntimeException |
||
162 | * @throws GuzzleException |
||
163 | */ |
||
164 | private function getUrl($url, $headers = []) |
||
181 | |||
182 | /** |
||
183 | * @param string $url |
||
184 | * @param array $headers |
||
185 | * @return StreamInterface |
||
186 | * @throws RuntimeException |
||
187 | * @throws GuzzleException |
||
188 | */ |
||
189 | public function getUrlBody($url, $headers = []) |
||
195 | |||
196 | /** |
||
197 | * @param $url |
||
198 | * @param $torrentsDir |
||
199 | * @return string path to downloaded file |
||
200 | * @throws RuntimeException |
||
201 | * @throws GuzzleException |
||
202 | */ |
||
203 | public function downloadTorrent($url, $torrentsDir) |
||
217 | |||
218 | public function isTorrentPopular($movieInfo, $commentsMin, $imdbMin, $kinopoiskMin, $votesMin) |
||
225 | |||
226 | public function cleanMovieId($idOrUrl) |
||
235 | |||
236 | private static function getMovieTorrentUrl($movieId, $hash = '') |
||
242 | |||
243 | private static function getMovieInfo($body) |
||
265 | |||
266 | /** |
||
267 | * @param $body |
||
268 | * @param $fromTimestamp |
||
269 | * @return bool|string date if matched, false if not |
||
270 | */ |
||
271 | private static function checkTorrentDate($body, $fromTimestamp) |
||
281 | |||
282 | private static function getInfoUrls($body) |
||
288 | |||
289 | /** |
||
290 | * @param $body |
||
291 | * @return array |
||
292 | */ |
||
293 | private static function getTorrentsUrls($body) |
||
300 | } |
||
301 |