Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinNorgarb committed May 5, 2018
2 parents 17810da + f1155e5 commit 8b9dd96
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Download

public function __construct($url, $path)
{
// dd($url);
$this->youtube = new YoutubeDownloader($url);

$this->path = $path ?? storage_path("/");
Expand All @@ -23,29 +24,33 @@ public function download()
{
$this->youtube->onProgress = function ($downloadedBytes, $fileSize, $index, $count) {
if ($count > 1) {
echo '[' . $index . ' of ' . $count . ' videos] ';
// echo '[' . $index . ' of ' . $count . ' videos] ';
}
if ($fileSize > 0) {
echo "\r" . 'Downloaded ' . $downloadedBytes . ' of ' . $fileSize . ' bytes [%' . number_format($downloadedBytes * 100 / $fileSize, 2) . '].';
// echo "\r" . 'Downloaded ' . $downloadedBytes . ' of ' . $fileSize . ' bytes [%' . number_format($downloadedBytes * 100 / $fileSize, 2) . '].';
} else {
echo "\r" . 'Downloading...';
// echo "\r" . 'Downloading...';
}
};

$this->youtube->onFinalized = function ($filePath, $fileSize, $index, $count) {
if ($count > 1) {
echo '[' . $index . ' of ' . $count . ' videos] ';
// echo '[' . $index . ' of ' . $count . ' videos] ';
}
echo $filePath . ' Finalized' . PHP_EOL;
// echo $filePath . ' Finalized' . PHP_EOL;
};

$this->youtube->onComplete = function ($filePath, $fileSize, $index, $count) {
if ($count > 1) {
echo '[' . $index . ' of ' . $count . ' videos] ';
// echo '[' . $index . ' of ' . $count . ' videos] ';
}
echo 'Downloading of ' . $fileSize . ' bytes has been completed. It is saved in ' . $filePath . PHP_EOL;
// echo 'Downloading of ' . $fileSize . ' bytes has been completed. It is saved in ' . $filePath . PHP_EOL;
};

return $this->youtube->download();

return response()->streamDownload(function () {
$this->youtube->download();
}, 'laravel-readme.mp4');
// return view('welcome') ;
}
}

0 comments on commit 8b9dd96

Please sign in to comment.