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

Video Bundle Laravel Package

darkanakin41/video-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require darkanakin41/video-bundle
    

    Ensure darkanakin41/api-bundle is also installed (dependency).

  2. Configuration: Publish the bundle config:

    php artisan vendor:publish --provider="Darkanakin41\VideoBundle\VideoBundle" --tag="config"
    

    Update config/video.php with API keys (e.g., YouTube) and registered channels.

  3. First Use Case: Fetch a video from a registered channel:

    use Darkanakin41\VideoBundle\Services\VideoService;
    
    $videoService = app(VideoService::class);
    $video = $videoService->fetch('youtube', 'channel_id', 'video_id');
    

    Verify the response structure (e.g., title, duration, isLive).


Implementation Patterns

Core Workflows

  1. Channel Integration:

    • Register new video sources (e.g., Vimeo) by extending Darkanakin41\VideoBundle\Contracts\VideoProvider.
    • Implement fetch() and validate() methods for the provider.
  2. Event Handling:

    • Subscribe to IsLiveEvent for live video detection:
      Event::listen(IsLiveEvent::class, function ($event) {
          // Trigger notifications, update UI, etc.
      });
      
  3. Batch Processing:

    • Use VideoService::fetchAll() for bulk video retrieval (if supported by the provider):
      $videos = $videoService->fetchAll('youtube', 'channel_id', ['video_id_1', 'video_id_2']);
      
  4. Caching:

    • Leverage Laravel’s cache to store API responses (configure in config/video.php):
      'cache_enabled' => env('VIDEO_CACHE_ENABLED', true),
      'cache_ttl'     => env('VIDEO_CACHE_TTL', 3600), // 1 hour
      

Integration Tips

  • API Rate Limits:
    • Implement retry logic for failed API calls (e.g., using GuzzleHttp\Client with middleware).
  • Model Binding:
    • Bind videos to Eloquent models for seamless ORM integration:
      use Darkanakin41\VideoBundle\Http\Resources\VideoResource;
      
      route('videos.show', function (VideoResource $video) {
          return response()->json($video);
      });
      
  • Frontend Sync:
    • Use Laravel Echo/Pusher to broadcast IsLiveEvent in real-time:
      Echo.channel('videos')
          .listen('IsLiveEvent', (event) => {
              console.log('Live video detected:', event.video);
          });
      

Gotchas and Tips

Pitfalls

  1. Deprecated Dependencies:

    • The bundle relies on darkanakin41/api-bundle, which may have outdated Laravel compatibility (tested up to Laravel 5.x). Verify compatibility with your Laravel version.
    • Fix: Fork the bundle and update dependencies if needed.
  2. Event Dispatching:

    • IsLiveEvent is only triggered for YouTube live videos. Custom providers must manually dispatch events for their live streams.
    • Tip: Extend Darkanakin41\VideoBundle\Events\BaseVideoEvent for provider-specific events.
  3. API Key Management:

    • Hardcoded API keys in config are insecure. Use Laravel’s .env or a secrets manager.
    • Tip: Add validation in config/video.php:
      'api_keys' => [
          'youtube' => env('YOUTUBE_API_KEY'),
      ],
      
  4. Error Handling:

    • The bundle lacks detailed error messages for API failures. Wrap service calls in try-catch:
      try {
          $video = $videoService->fetch('youtube', 'channel_id', 'video_id');
      } catch (\Darkanakin41\VideoBundle\Exceptions\VideoException $e) {
          Log::error('Video fetch failed: ' . $e->getMessage());
      }
      

Debugging

  • Log API Responses: Enable debug mode in config/video.php:

    'debug' => env('VIDEO_DEBUG', false),
    

    Logs will appear in storage/logs/laravel.log.

  • Provider-Specific Issues:

    • Check the Darkanakin41\VideoBundle\Providers\YouTubeProvider for hardcoded logic (e.g., live stream detection thresholds).

Extension Points

  1. Custom Fields:

    • Extend the Video model (if using Eloquent) to add provider-specific metadata:
      class Video extends Model
      {
          protected $casts = [
              'youtube_stats' => 'array',
              'vimeo_privacy' => 'string',
          ];
      }
      
  2. Webhook Support:

    • Add webhook endpoints to update videos in real-time (e.g., for live status changes):
      Route::post('/webhooks/youtube', [VideoWebhookController::class, 'handle']);
      
  3. Queue Jobs:

    • Offload video fetching to queues for long-running tasks:
      VideoJob::dispatch('youtube', 'channel_id', 'video_id')->onQueue('videos');
      
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware