- Can I use this package directly in a Laravel controller without blocking the request?
- No, this package performs synchronous downloads, which will block Laravel’s request lifecycle. For production, offload downloads to Laravel Queues (e.g., `ShouldQueue` jobs) or use Artisan commands for CLI-triggered processing.
- How do I install this in Laravel and avoid dependency conflicts with Guzzle?
- Add `masih/youtubedownloader` to `composer.json` and pin Guzzle versions explicitly. Example: `"guzzlehttp/guzzle": "^7.2"` in `require`, then use `"replace": { "guzzlehttp/guzzle": "guzzlehttp/guzzle:^7.2" }` to force compatibility.
- Does this package support Laravel’s service container or Facades?
- No, it lacks native Laravel integration. You’ll need to wrap the downloader in a service class or Artisan command to use Laravel’s DI container. Example: Bind the downloader to a custom Facade or inject it via constructor.
- What’s the best way to store downloaded videos in Laravel?
- Use Laravel’s Filesystem (e.g., `storage/app/youtube`) or S3 for cloud storage. Configure the downloader’s path via `$youtube->setPath(storage_path('app/youtube'))` and ensure the directory is writable (e.g., `chmod 777`).
- Is this package compliant with YouTube’s Terms of Service?
- No, automated downloads violate YouTube’s Automated Systems Policy unless you have explicit permission. For production, use the official [YouTube Data API](https://developers.google.com/youtube/v3) or restrict usage to internal, opt-in workflows.
- How do I handle failed downloads or rate limits in production?
- Wrap calls in `try-catch` blocks and log failures to Sentry/Monolog. For rate limits, implement retries with exponential backoff in your queued job or use proxies if YouTube blocks your IP. Monitor for HTTP 403/429 errors.
- Can I download playlists or just individual videos?
- Yes, the package supports both. Pass a playlist URL (e.g., `https://youtube.com/playlist?list=PL...`) or ID to download all videos in the playlist. Example: `$youtube->download('playlist_url_here')`.
- What Laravel versions does this package support?
- The package itself requires PHP 5.5+, but Laravel compatibility depends on your PHP version. For Laravel 8/9, use PHP 8.0+ to avoid deprecated features. Test thoroughly in a sandbox project due to potential Guzzle/Symfony conflicts.
- How do I trigger downloads via a web form or API endpoint?
- Create a Laravel controller/service to instantiate the downloader, then dispatch a queued job (e.g., `YoutubeDownloadJob`) with the video URL. Example: `YoutubeDownloadJob::dispatch($request->url)->onQueue('youtube');`
- Are there alternatives for Laravel that avoid YouTube’s automation restrictions?
- Yes, consider the [YouTube Data API](https://developers.google.com/youtube/v3) for compliant video metadata or streaming. For downloads, explore self-hosted solutions like [youtube-dl](https://ytdl-org.github.io/youtube-dl/) (via Symfony Process) or paid APIs like Mux or Cloudflare Stream.