1
|
|
|
<?php |
2
|
|
|
namespace Tartana\Host; |
3
|
|
|
|
4
|
|
|
use GuzzleHttp\Psr7\Request; |
5
|
|
|
use Tartana\Entity\Download; |
6
|
|
|
use Tartana\Host\Common\Http; |
7
|
|
|
|
8
|
|
|
class Rapidgatornet extends Http |
9
|
|
|
{ |
10
|
|
|
|
11
|
4 |
|
public function fetchDownloadInfo(array $downloads) |
12
|
|
|
{ |
13
|
4 |
|
if (!$this->login()) { |
14
|
1 |
|
foreach ($downloads as $download) { |
15
|
1 |
|
$download->setState(Download::STATE_DOWNLOADING_ERROR); |
16
|
1 |
|
$download->setMessage('TARTANA_DOWNLOAD_MESSAGE_INVALID_LOGIN'); |
17
|
|
|
} |
18
|
1 |
|
return; |
19
|
|
|
} |
20
|
|
|
|
21
|
3 |
|
$sid = $this->getCookie('PHPSESSID')->getValue(); |
22
|
3 |
|
foreach ($downloads as $download) { |
23
|
|
|
try { |
24
|
|
|
// Getting the link information |
25
|
3 |
|
$res = $this->getClient()->request('get', 'https://rapidgator.net/api/file/info?sid=' . $sid . '&url=' . $download->getLink()); |
26
|
2 |
|
$info = json_decode($res->getBody()->getContents()); |
27
|
2 |
|
if (isset($info->response_status) && $info->response_status == 200) { |
28
|
1 |
|
$download->setFileName($info->response->filename); |
29
|
1 |
|
$download->setSize($info->response->size); |
30
|
1 |
|
$download->setHash($info->response->hash); |
31
|
|
|
} else { |
32
|
1 |
|
$download->setMessage('TARTANA_DOWNLOAD_MESSAGE_INVALID_URL'); |
33
|
2 |
|
$download->setState(Download::STATE_DOWNLOADING_ERROR); |
34
|
|
|
} |
35
|
1 |
|
} catch (\Exception $e) { |
36
|
1 |
|
$this->log('Exception fetching file info for connection test: ' . $e->getMessage()); |
37
|
1 |
|
$download->setMessage('TARTANA_DOWNLOAD_MESSAGE_INVALID_URL'); |
38
|
3 |
|
$download->setState(Download::STATE_DOWNLOADING_ERROR); |
39
|
|
|
} |
40
|
|
|
} |
41
|
3 |
|
} |
42
|
|
|
|
43
|
2 |
|
protected function getUrlToDownload(Download $download) |
44
|
|
|
{ |
45
|
2 |
|
$sid = $this->getCookie('PHPSESSID') ? $this->getCookie('PHPSESSID')->getValue() : ''; |
46
|
|
|
|
47
|
2 |
|
$res = $this->getClient()->request('get', 'https://rapidgator.net/api/file/download?sid=' . $sid . '&url=' . $download->getLink()); |
48
|
2 |
|
$info = json_decode($res->getBody()->getContents()); |
49
|
2 |
|
if (isset($info->response_status) && $info->response_status == 200) { |
50
|
1 |
|
$this->log('Rapidgator net real url: ' . $info->response->url); |
51
|
1 |
|
return $info->response->url; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
return null; |
55
|
|
|
} |
56
|
|
|
|
57
|
6 |
|
protected function login() |
58
|
|
|
{ |
59
|
6 |
|
if ($this->getCookie('PHPSESSID')) { |
60
|
4 |
|
return true; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$args = [ |
64
|
2 |
|
'username' => trim($this->getConfiguration()->get('rapidgatornet.username')), |
65
|
2 |
|
'password' => trim($this->getConfiguration()->get('rapidgatornet.password')) |
66
|
|
|
]; |
67
|
|
|
|
68
|
2 |
|
if (!$args['username']) { |
69
|
1 |
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
$res = $this->getClient()->request( |
73
|
1 |
|
'get', |
74
|
1 |
|
'https://rapidgator.net/api/user/login?username=' . $args['username'] . '&password=' . $args['password'] |
75
|
|
|
); |
76
|
1 |
|
$html = $res->getBody()->getContents(); |
77
|
1 |
|
$response = json_decode($html); |
78
|
1 |
|
return isset($response->response_status) && $response->response_status == 200; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|