athlon1600/youtube-downloader
Pure-PHP YouTube downloader library that fetches direct stream links (audio-only and combined audio+video) without shelling out to youtube-dl or using JS interpreters. Simple API: getDownloadLinks() and pick the best format URL.
Pros:
youtube-dl) and shell dependencies.YouTubeDownloader, YouTubeStreamer, SignatureLinkParser) enables granular integration (e.g., only use download logic without streaming).DownloadOptions, VideoInfo) maps cleanly to Laravel’s Eloquent models or DTOs for further processing.youtube-dl).Cons:
player_response, signatureCipher), which may break with YouTube’s frequent changes (e.g., issue #120).yt-dlp’s broader scope), requiring separate tools for other platforms.ffmpeg CLI), adding complexity to pipelines.composer require athlon1600/youtube-downloader "^4.0" aligns with Laravel’s dependency management.getDownloadLinks() can be offloaded to Laravel Queues for async processing (e.g., background video downloads).Route::post('/download', [DownloadController::class, 'handle'])) for internal tools.VideoInfo objects can be serialized and stored in Laravel’s database (e.g., json column) for analytics or caching.failed_jobs table or a custom table for auditing.YouTubeStreamer enables direct video playback from Laravel’s server (e.g., embedded in Blade templates or SPAs via signed URLs).High:
retry helper).delay(60) for staggered downloads).Browser::setProxy()).yt-dlp (PHP wrapper) or direct API calls.Medium:
php-curl-file-downloader (added in v3.0.0) may introduce compatibility issues. Pin versions in composer.json.session() or a dedicated cookie service.ffmpeg CLI, adding deployment complexity (e.g., Docker, server-side installation).Low:
Use Case Clarity:
Scalability Needs:
Legal Compliance:
Maintenance Plan:
getDownloadLinks() are recommended.Alternatives:
spatie/yt-dlp leverage the Python tool via CLI, offering broader platform support.Laravel Ecosystem:
config/app.php to set default options (e.g., user-agent, cookie path).composer require athlon1600/youtube-downloader "^4.0"
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton(YouTubeDownloader::class, function () {
$youtube = new YouTubeDownloader();
$youtube->getBrowser()->setUserAgent(config('services.youtube.user_agent'));
return $youtube;
});
}
// app/Jobs/DownloadYouTubeVideo.php
public function handle()
{
$youtube = app(YouTubeDownloader::class);
$downloadOptions = $youtube->getDownloadLinks($this->url);
// Save to storage or process further
}
Database:
VideoInfo objects for analytics or caching:
$videoInfo = $downloadOptions->getVideoInfo();
Video::create([
'title' => $videoInfo->title,
'duration' => $videoInfo->lengthSeconds,
'metadata' => json_encode($videoInfo),
]);
failed_jobs or a custom table:
try {
$youtube->download($url, storage_path('videos'));
} catch (YouTubeException $e) {
DownloadLog::create([
'url' => $url,
'error' => $e->getMessage(),
]);
}
Frontend:
YouTubeStreamer to embed videos in Blade templates:
// routes/web.php
Route::get('/stream/{url}', function ($url) {
$streamer = new YouTubeStreamer();
return response()->stream(function () use ($streamer, $url) {
$streamer->stream($url);
});
});
How can I help you explore Laravel packages today?