Weave 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

Symfony bundle for YouTube API v3 integration, offering services to fetch video, channel, and playlist data, extract video IDs from URLs, a form type for YouTube links, and profiler integration for API requests.

View on GitHub
Deep Wiki
Context7

AldafluxYoutubeUtilsBundle

Symfony Bundle for YouTube API v3 integration and utilities.

Features

  • 🎥 YouTube API Service (ApiYoutubeService): Easily fetch information about YouTube videos, channels, and playlists.
  • 🔗 YouTube ID Extraction: Automatically extract 11-character video IDs from any YouTube URL format.
  • 📝 Form Type YoutubeUrlCodeType: Custom Symfony Form Type accepting full YouTube URLs and transforming them into 11-character video IDs.
  • 📊 Web Profiler Integration (DataCollector): View all YouTube API requests and potential errors directly inside the Symfony Web Debug Toolbar and Profiler.

Installation

Add the package via Composer:

composer require aldaflux/youtube-utils-bundle

Configuration

Create the configuration file config/packages/aldaflux_youtube_utils.yaml and specify your YouTube API key:

aldaflux_youtube_utils:
    youtube_api_key: '%env(YOUTUBE_API_KEY)%'

Add your API key to your .env or .env.local file:

YOUTUBE_API_KEY="your_youtube_v3_api_key"

Usage

1. Service ApiYoutubeService

Inject ApiYoutubeService into your controllers or services:

use Aldaflux\YoutubeUtilsBundle\Utils\ApiYoutubeService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class VideoController extends AbstractController
{
    public function show(ApiYoutubeService $youtubeService, string $videoId)
    {
        // Get a video by its ID
        $video = $youtubeService->getVideo($videoId);

        // Get a channel by its ID
        $channel = $youtubeService->getChannel('UC...');

        // Get a playlist by its ID
        $playlist = $youtubeService->getPlaylist('PL...');

        // Extract YouTube ID from a full URL
        $id = $youtubeService->getYoutubeIdFromUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); // returns "dQw4w9WgXcQ"
    }
}

2. Form Type YoutubeUrlCodeType

Use YoutubeUrlCodeType in your FormBuilders. Users can enter a full YouTube URL or just the video ID, and the DataTransformer will store only the 11-character video ID.

use Aldaflux\YoutubeUtilsBundle\Form\Type\YoutubeUrlCodeType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class ArticleType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('youtubeVideoId', YoutubeUrlCodeType::class, [
                'label' => 'YouTube Video (URL or ID)',
                'required' => false,
            ]);
    }
}

3. Web Debug Toolbar & Profiler

This bundle automatically registers a DataCollector in Symfony. In development environment (APP_ENV=dev), calls to the YouTube API are logged and displayed inside the Web Profiler panel.


License

GPL-3.0+

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.
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names