Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Devtube Laravel Package

devswebdev/devtube

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install System Dependencies:

    sudo apt install ffmpeg youtube-dl  # For Ubuntu/Debian
    

    Verify paths with:

    which ffmpeg youtube-dl
    
  2. Install Laravel Package:

    composer require devswebdev/devtube
    
  3. 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`
    
  4. 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());
    });
    

Implementation Patterns

Core Workflows

  1. Basic Download:

    $dl = new Download($url, $format, $path);
    $media = $dl->download();  // Returns Collection of media info
    
  2. Format Conversion (FFmpeg):

    $dl = new Download($url, "mp3", $path);  // Requires FFmpeg
    
  3. 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();
    }
    
  4. Metadata Extraction:

    $media = $dl->download()->first();
    $title = $media['title'];
    $duration = $media['duration'];
    

Integration Tips

  • Storage: Use Laravel’s filesystem:
    $path = storage_path('app/videos/' . $filename);
    
  • Validation: Sanitize URLs and paths:
    $url = filter_var($request->url, FILTER_VALIDATE_URL);
    
  • Error Handling: Wrap downloads in try-catch:
    try {
        $dl->download();
    } catch (\Exception $e) {
        Log::error("Download failed: " . $e->getMessage());
    }
    
  • Async: Offload to queues for long-running downloads.

Advanced Patterns

  1. Custom Formats: Extend the Download class to support additional formats:

    class CustomDownload extends Download {
        protected $customFormats = ['webm', 'mkv'];
        // Override download logic
    }
    
  2. Platform-Specific Logic: Use youtube-dl’s --list-formats to filter by platform:

    $dl->setOptions(['--list-formats']);
    
  3. Database Tracking: Add a media table and log downloads:

    Media::create([
        'url' => $url,
        'path' => $media['file']->getPathname(),
        'format' => $format,
    ]);
    

Gotchas and Tips

Pitfalls

  1. Dependency Paths:

    • Issue: youtube-dl/ffmpeg not found.
    • Fix: Verify paths in devtube.php match which output. Use absolute paths.
  2. FFmpeg Missing Codecs:

    • Issue: Conversion fails with "codec not found".
    • Fix: Install additional FFmpeg packages:
      sudo apt install ffmpeg libx264-dev
      
  3. Blocking Requests:

    • Issue: Timeouts on large files.
    • Fix: Use queues or increase max_execution_time in php.ini.
  4. Outdated Package:

    • Issue: Compatibility with Laravel 8+/9+.
    • Fix: Fork the package or patch the Download class for modern PHP.
  5. Legal Risks:

    • Issue: Downloading copyrighted content.
    • Fix: Restrict to whitelisted domains or add user agreements.

Debugging Tips

  • Log youtube-dl Output:
    $dl->setVerbose(true);  // If supported
    
  • Check File Permissions:
    chmod -R 755 storage/app/videos
    
  • Test with Simple URLs: Start with short videos (e.g., YouTube ads) to validate the pipeline.

Configuration Quirks

  1. Default Formats:

    • mp4 and mp3 are common, but youtube-dl may require specific format codes (e.g., bestvideo+bestaudio).
  2. FFmpeg Path:

    • If using Docker, map the host’s FFmpeg to the container:
      VOLUME /usr/bin/ffmpeg:/usr/bin/ffmpeg
      
  3. Download Path:

    • Ensure the directory exists or use Laravel’s storage_path():
      $path = storage_path('app/videos');
      if (!file_exists($path)) mkdir($path, 0755, true);
      

Extension Points

  1. 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();
        }
    }
    
  2. Add Metadata Fields: Extend the media_info array returned by download():

    $media['custom_field'] = $this->extractCustomData($media['url']);
    
  3. Support Additional Platforms: Modify the Download class to handle platform-specific options:

    $dl->setOptions(['--extract-audio', '--audio-format', 'mp3']);
    
  4. Async with Laravel Horizon: Configure a queue worker to process downloads:

    php artisan queue:work --queue=downloads
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle