示例#1
0
 /**
  * Get product data
  *
  * @param string $productUrl Product URL
  *
  * @return array
  */
 public function getProductData($productUrl)
 {
     $productData = [];
     $response = $this->_getCleanHttpClient($productUrl)->send();
     if ($response->getStatusCode() == Response::STATUS_CODE_200) {
         $body = $response->getBody();
         $parser = new Parser();
         $productData = $parser->getProductData($body);
     }
     return $productData;
 }
 /**
  * Helper to download the video.
  *
  * @param $name
  * @param $path
  * @param $saveTo
  */
 private function downloadLessonFromPath($path, $saveTo)
 {
     $response = $this->client->get($path, ['cookies' => $this->cookie]);
     $downloadUrl = Parser::getDownloadLink($response->getBody()->getContents());
     $viemoUrl = $this->getRedirectUrl($downloadUrl);
     $finalUrl = $this->getRedirectUrl($viemoUrl);
     $this->bench->start();
     $this->client->get($finalUrl, ['save_to' => $saveTo]);
     $this->bench->end();
     Utils::write(sprintf("Elapsed time: %s, Memory: %s", $this->bench->getTime(), $this->bench->getMemoryUsage()));
 }
 /**
  * Helper to download the video.
  *
  * @param $html
  * @param $saveTo
  * @return bool
  */
 private function downloadLessonFromPath($html, $saveTo)
 {
     try {
         $downloadUrl = Parser::getDownloadLink($html);
     } catch (NoDownloadLinkException $e) {
         Utils::write(sprintf("Can't download this lesson! :( No download button"));
         return false;
     }
     $viemoUrl = $this->getRedirectUrl($downloadUrl);
     $finalUrl = $this->getRedirectUrl($viemoUrl);
     $this->bench->start();
     $req = $this->client->createRequest('GET', $finalUrl, ['save_to' => $saveTo, 'verify' => false]);
     if (php_sapi_name() == "cli") {
         //on cli show progress
         $req->getEmitter()->on('progress', function (ProgressEvent $e) {
             printf("> Total: %d%% Downloaded: %s of %s     \r", Utils::getPercentage($e->downloaded, $e->downloadSize), Utils::formatBytes($e->downloaded), Utils::formatBytes($e->downloadSize));
         });
     }
     $this->client->send($req);
     $this->bench->end();
     Utils::write(sprintf("Elapsed time: %s, Memory: %s", $this->bench->getTime(), $this->bench->getMemoryUsage()));
     return true;
 }