Skip to content

Commit

Permalink
Merge branch 'HEAD'
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinNorgarb committed May 5, 2018
2 parents 8b9dd96 + 07b72bd commit 23f61e3
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@

namespace DevsWebDev\DevTube;

use Illuminate\Support\Facades\Storage;
use Masih\YoutubeDownloader\YoutubeDownloader;

class Download
{
protected $youtube;
public $youtube;

protected $path;
public $path;

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

$this->path = $path ?? storage_path("/");

$this->youtube->setPath($this->path);
public function __construct($url, $path)
{
$this->url = $url;
$this->path = storage_path("app/public/music");
}

public function download()
{
$this->youtube->onProgress = function ($downloadedBytes, $fileSize, $index, $count) {
$youtube = new YoutubeDownloader($this->url);
$youtube->setPath($this->path);
$this->youtube = $youtube;

$youtube->onProgress = function ($downloadedBytes, $fileSize, $index, $count) {
if ($count > 1) {
// echo '[' . $index . ' of ' . $count . ' videos] ';
}
Expand All @@ -33,24 +37,32 @@ public function download()
}
};

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

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

public function redirect($filePath)
{
$youtube = $this->youtube;
$file = basename($filePath);


// $files = \Storage::files('public/music');
// dump($files);
session([$_SERVER['REMOTE_ADDR'] => 'app/public/music/'.$file]);

return response()->streamDownload(function () {
$this->youtube->download();
}, 'laravel-readme.mp4');
// return view('welcome') ;
// \Session::put('public/music/'.$file:'public/music/'.$file)
// dump('public/music/'.$file);
// $dl = Storage::download('public/music/'.$file);
// // return $dl;
// dump($dl);
// $contents = Storage::get('public/music/'.$file);
// // return json_encode($contents);
// // dump($contents);
// $url = \Storage::url('public/music/'.$file);
// echo $url;
}
}

0 comments on commit 23f61e3

Please sign in to comment.