Installation:
composer require darkanakin41/video-bundle
Ensure darkanakin41/api-bundle is also installed (dependency).
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.
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).
Channel Integration:
Darkanakin41\VideoBundle\Contracts\VideoProvider.fetch() and validate() methods for the provider.Event Handling:
IsLiveEvent for live video detection:
Event::listen(IsLiveEvent::class, function ($event) {
// Trigger notifications, update UI, etc.
});
Batch Processing:
VideoService::fetchAll() for bulk video retrieval (if supported by the provider):
$videos = $videoService->fetchAll('youtube', 'channel_id', ['video_id_1', 'video_id_2']);
Caching:
config/video.php):
'cache_enabled' => env('VIDEO_CACHE_ENABLED', true),
'cache_ttl' => env('VIDEO_CACHE_TTL', 3600), // 1 hour
GuzzleHttp\Client with middleware).use Darkanakin41\VideoBundle\Http\Resources\VideoResource;
route('videos.show', function (VideoResource $video) {
return response()->json($video);
});
IsLiveEvent in real-time:
Echo.channel('videos')
.listen('IsLiveEvent', (event) => {
console.log('Live video detected:', event.video);
});
Deprecated Dependencies:
darkanakin41/api-bundle, which may have outdated Laravel compatibility (tested up to Laravel 5.x). Verify compatibility with your Laravel version.Event Dispatching:
IsLiveEvent is only triggered for YouTube live videos. Custom providers must manually dispatch events for their live streams.Darkanakin41\VideoBundle\Events\BaseVideoEvent for provider-specific events.API Key Management:
.env or a secrets manager.config/video.php:
'api_keys' => [
'youtube' => env('YOUTUBE_API_KEY'),
],
Error Handling:
try {
$video = $videoService->fetch('youtube', 'channel_id', 'video_id');
} catch (\Darkanakin41\VideoBundle\Exceptions\VideoException $e) {
Log::error('Video fetch failed: ' . $e->getMessage());
}
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:
Darkanakin41\VideoBundle\Providers\YouTubeProvider for hardcoded logic (e.g., live stream detection thresholds).Custom Fields:
Video model (if using Eloquent) to add provider-specific metadata:
class Video extends Model
{
protected $casts = [
'youtube_stats' => 'array',
'vimeo_privacy' => 'string',
];
}
Webhook Support:
Route::post('/webhooks/youtube', [VideoWebhookController::class, 'handle']);
Queue Jobs:
VideoJob::dispatch('youtube', 'channel_id', 'video_id')->onQueue('videos');
How can I help you explore Laravel packages today?