Install System Dependencies:
sudo apt install ffmpeg youtube-dl # For Ubuntu/Debian
Verify paths with:
which ffmpeg youtube-dl
Install Laravel Package:
composer require devswebdev/devtube
Publish Configuration:
php artisan vendor:publish --provider="DevsWebDev\DevTube\DevTubeServiceProvider"
Update config/devtube.php with correct paths:
'bin_path' => '/usr/bin/youtube-dl', // Match `which youtube-dl`
'ffmpeg_path' => '/usr/bin/ffmpeg', // Match `which ffmpeg`
First Use Case: In a controller or route:
use DevsWebDev\DevTube\Download;
Route::get('/download', function () {
$dl = new Download(
url: "https://www.youtube.com/watch?v=example",
format: "mp4",
download_path: "storage/app/videos"
);
$media = $dl->download()->first();
return response()->download($media['file']->getPathname());
});
Basic Download:
$dl = new Download($url, $format, $path);
$media = $dl->download(); // Returns Collection of media info
Format Conversion (FFmpeg):
$dl = new Download($url, "mp3", $path); // Requires FFmpeg
Queue-Based Processing: Create a job:
php artisan make:job DownloadVideoJob
Dispatch in controller:
DownloadVideoJob::dispatch($url, $format, $path);
Job handler:
public function handle() {
$dl = new Download($this->url, $this->format, $this->path);
$dl->download();
}
Metadata Extraction:
$media = $dl->download()->first();
$title = $media['title'];
$duration = $media['duration'];
$path = storage_path('app/videos/' . $filename);
$url = filter_var($request->url, FILTER_VALIDATE_URL);
try {
$dl->download();
} catch (\Exception $e) {
Log::error("Download failed: " . $e->getMessage());
}
Custom Formats:
Extend the Download class to support additional formats:
class CustomDownload extends Download {
protected $customFormats = ['webm', 'mkv'];
// Override download logic
}
Platform-Specific Logic:
Use youtube-dl’s --list-formats to filter by platform:
$dl->setOptions(['--list-formats']);
Database Tracking:
Add a media table and log downloads:
Media::create([
'url' => $url,
'path' => $media['file']->getPathname(),
'format' => $format,
]);
Dependency Paths:
youtube-dl/ffmpeg not found.devtube.php match which output. Use absolute paths.FFmpeg Missing Codecs:
sudo apt install ffmpeg libx264-dev
Blocking Requests:
max_execution_time in php.ini.Outdated Package:
Download class for modern PHP.Legal Risks:
youtube-dl Output:
$dl->setVerbose(true); // If supported
chmod -R 755 storage/app/videos
Default Formats:
mp4 and mp3 are common, but youtube-dl may require specific format codes (e.g., bestvideo+bestaudio).FFmpeg Path:
VOLUME /usr/bin/ffmpeg:/usr/bin/ffmpeg
Download Path:
storage_path():
$path = storage_path('app/videos');
if (!file_exists($path)) mkdir($path, 0755, true);
Custom Download Logic:
Override the download() method in a child class:
class MyDownload extends Download {
public function download() {
// Custom logic (e.g., pre-process URL)
return parent::download();
}
}
Add Metadata Fields:
Extend the media_info array returned by download():
$media['custom_field'] = $this->extractCustomData($media['url']);
Support Additional Platforms:
Modify the Download class to handle platform-specific options:
$dl->setOptions(['--extract-audio', '--audio-format', 'mp3']);
Async with Laravel Horizon: Configure a queue worker to process downloads:
php artisan queue:work --queue=downloads
How can I help you explore Laravel packages today?