|
|
|
@ -3,11 +3,9 @@ |
|
|
|
class Download { |
|
|
|
public $_id; |
|
|
|
public $timestamp; |
|
|
|
public $ip; |
|
|
|
public $url; |
|
|
|
public $premURL; |
|
|
|
public $filename; |
|
|
|
public $state; |
|
|
|
public $cstate; |
|
|
|
|
|
|
|
/** |
|
|
|
* Retourne les infos sur le prochain fichier a telecharger |
|
|
|
@ -18,28 +16,68 @@ class Download { |
|
|
|
{ |
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->download; |
|
|
|
// TODO : en plus faudrait rajouter une colonne histo pour avoir l'histo de ce fichier
|
|
|
|
$dbRet = $coll->findAndModify( |
|
|
|
['state' => 'added'], |
|
|
|
['$set' => ['state' => 'dlprogress']], |
|
|
|
null, |
|
|
|
['sort' => ["timestamp" => 1]] |
|
|
|
$dbRet = $coll->findOne( |
|
|
|
['cstate' => 'added'] |
|
|
|
); |
|
|
|
var_dump($dbRet); |
|
|
|
$myDownload = new Download(); |
|
|
|
$myDownload->db2Inst($dbRet); |
|
|
|
$myDownload->addEvent([ |
|
|
|
'timestamp' => time(), |
|
|
|
'state' => 'downloading' |
|
|
|
]); |
|
|
|
return $myDownload; |
|
|
|
} |
|
|
|
|
|
|
|
static function addDownload($url) |
|
|
|
{ |
|
|
|
$premInfos = PremiumizeMe::getLink($url); |
|
|
|
$myTime = time(); |
|
|
|
$myDownload = new Download(); |
|
|
|
|
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->download; |
|
|
|
|
|
|
|
$values = [ |
|
|
|
'_id' => new MongoId(), |
|
|
|
'timestamp' => $myTime, |
|
|
|
'premURL' => $premInfos['location'], |
|
|
|
'filename' => $premInfos['filename'], |
|
|
|
'cstate' => 'added' |
|
|
|
]; |
|
|
|
|
|
|
|
// TODO : verifier le retour
|
|
|
|
$coll->insert($values); |
|
|
|
|
|
|
|
$myDownload->db2Inst($values); |
|
|
|
|
|
|
|
$myDownload->addEvent([ |
|
|
|
'timestamp' => $myTime, |
|
|
|
'ip' => $_SERVER['REMOTE_ADDR'], |
|
|
|
'url' => $url, |
|
|
|
'state' => 'added' |
|
|
|
]); |
|
|
|
|
|
|
|
return $myDownload; |
|
|
|
} |
|
|
|
|
|
|
|
private function db2Inst($dbRet) |
|
|
|
{ |
|
|
|
$this->_id = $dbRet['_id']; |
|
|
|
$this->timestamp = $dbRet['timestamp']; |
|
|
|
$this->ip = $dbRet['ip']; |
|
|
|
$this->url = $dbRet['url']; |
|
|
|
$this->premURL = $dbRet['premURL']; |
|
|
|
$this->filename = $dbRet['filename']; |
|
|
|
$this->state = $dbRet['state']; |
|
|
|
$this->cstate = $dbRet['cstate']; |
|
|
|
} |
|
|
|
|
|
|
|
private function addEvent($event) |
|
|
|
{ |
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->download; |
|
|
|
$dbRet = $coll->update( |
|
|
|
['_id' => $this->_id], |
|
|
|
['$push' => ['event' => $event]] |
|
|
|
); |
|
|
|
file_put_contents('toto', print_r($dbRet, true)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -61,14 +99,28 @@ class Download { |
|
|
|
fclose($fp); |
|
|
|
|
|
|
|
// TODO : verifier le retour ?
|
|
|
|
// TODO : ajouter les infos sur le dl
|
|
|
|
$this->addEvent([ |
|
|
|
'timestamp' => time(), |
|
|
|
'state' => 'downloaded', |
|
|
|
'curlinfo' => [ |
|
|
|
'http_code' => $retour['http_code'], |
|
|
|
'total_time' => $retour['total_time'], |
|
|
|
'namelookup_time' => $retour['namelookup_time'], |
|
|
|
'connect_time' => $retour['connect_time'], |
|
|
|
'pretransfer_time' => $retour['pretransfer_time'], |
|
|
|
'size_download' => $retour['size_download'], |
|
|
|
'speed_download' => $retour['speed_download'], |
|
|
|
'starttransfer_time' => $retour['starttransfer_time'] |
|
|
|
] |
|
|
|
]); |
|
|
|
|
|
|
|
$db = DbMongo::get(); |
|
|
|
$coll = $db->download; |
|
|
|
$coll->findAndModify( |
|
|
|
$dbRet = $coll->update( |
|
|
|
['_id' => $this->_id], |
|
|
|
['$set' => ['state' => 'downloaded']] |
|
|
|
['$set' => ['cstate' => 'downloaded']] |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return $retour; |
|
|
|
} |
|
|
|
|
|
|
|
|