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.
Symfony Bundle for YouTube API v3 integration and utilities.
ApiYoutubeService): Easily fetch information about YouTube videos, channels, and playlists.YoutubeUrlCodeType: Custom Symfony Form Type accepting full YouTube URLs and transforming them into 11-character video IDs.Add the package via Composer:
composer require aldaflux/youtube-utils-bundle
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"
ApiYoutubeServiceInject 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"
}
}
YoutubeUrlCodeTypeUse 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,
]);
}
}
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.
GPL-3.0+
How can I help you explore Laravel packages today?