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

Youtube Utils Bundle Laravel Package

aldaflux/youtube-utils-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require aldaflux/youtube-utils-bundle
    

    Ensure your config/bundles.php includes:

    return [
        // ...
        Aldaflux\YoutubeUtilsBundle\AldafluxYoutubeUtilsBundle::class => ['all' => true],
    ];
    
  2. Configuration Add to config/packages/aldaflux_youtube_utils.yaml:

    aldaflux_youtube_utils:
        api_key: "%env(YOUTUBE_API_KEY)%"  # Required
        default_language: "en-US"         # Optional
    
  3. First Use Case: Fetch Video Info Inject the service in a controller:

    use Aldaflux\YoutubeUtilsBundle\Service\YoutubeService;
    
    class VideoController extends AbstractController
    {
        public function show(YoutubeService $youtube): Response
        {
            $video = $youtube->getVideoDetails('dQw4w9WgXcQ');
            return $this->render('video/show.html.twig', ['video' => $video]);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Video Metadata Retrieval

    $details = $youtube->getVideoDetails('VIDEO_ID');
    // Returns: title, description, publishedAt, viewCount, etc.
    
  2. Search Functionality

    $results = $youtube->searchVideos('laravel tutorial', ['maxResults' => 5]);
    // Returns: array of video/snippet data
    
  3. Channel Management

    $channel = $youtube->getChannelDetails('UC_x5XG1OV2P6uZZ5FSM9Ttw');
    // Returns: channel stats, uploads, etc.
    
  4. Twig Integration

    {% for video in videos %}
        <h3>{{ video.snippet.title }}</h3>
        <iframe width="560" height="315"
                src="https://www.youtube.com/embed/{{ video.id.videoId }}"
                frameborder="0"></iframe>
    {% endfor %}
    

Advanced Patterns

  • Rate-Limited Calls Use dependency injection to wrap calls in a retry mechanism:

    $youtube->withRetry(3, 1000)->getVideoDetails('VIDEO_ID');
    
  • Caching Responses Decorate the service to cache API responses:

    $youtube->setCache(new SymfonyCacheAdapter());
    
  • Event-Driven Updates Subscribe to youtube.utils.video.fetched events for post-processing:

    $dispatcher->addListener('youtube.utils.video.fetched', function ($event) {
        // Log, transform, or store data
    });
    

Gotchas and Tips

Common Pitfalls

  1. API Key Restrictions

    • Ensure your YouTube API key has enabled APIs for:
      • YouTube Data API v3
      • YouTube Analytics API (if needed)
    • Debug Tip: Check 403 Forbidden errors in logs for missing scopes.
  2. Quota Limits

    • Default quota: 10,000 units/day (varies by endpoint).
    • Tip: Monitor usage via Google Cloud Console.
    • Implement exponential backoff for 429 Too Many Requests.
  3. Deprecated Endpoints

    • Avoid videos.list(by=rating) (deprecated). Use commentThreads.list instead.
  4. Twig Template Caching

    • Clear cache after updating aldaflux_youtube_utils.yaml:
      php bin/console cache:clear
      

Debugging Tips

  • Enable Verbose Logging

    aldaflux_youtube_utils:
        debug: true
    

    Logs API calls to var/log/dev.log.

  • Validate Responses Always check $youtube->getLastResponse() for errors:

    if ($youtube->hasErrors()) {
        throw new \RuntimeException($youtube->getErrorMessage());
    }
    

Extension Points

  1. Custom Response Mappers Override default response handling:

    $youtube->setResponseMapper(new CustomVideoMapper());
    
  2. Add New Endpoints Extend YoutubeService and register as a decorator:

    services:
        app.youtube.decorated:
            decorates: aldaflux.youtube.utils.service
            arguments: ['@app.youtube.decorated.inner']
    
  3. Webhook Integration Use youtube.utils.webhook.received events to process real-time updates (e.g., new uploads).

Configuration Quirks

  • Language Codes Use RFC 5646 codes (e.g., en-US, es-MX). Avoid en alone—it defaults to en-US.

  • Pagination Always check pageToken in responses for multi-page results:

    do {
        $results = $youtube->searchVideos('query', ['pageToken' => $pageToken]);
        $pageToken = $results['nextPageToken'];
    } while ($pageToken);
    
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle