azaw/yt-toolkit 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

azaw/yt-toolkit

最新稳定版本:v1.0.4

Composer 安装命令:

composer require azaw/yt-toolkit

包简介

Youtube toolkit

README 文档

README

A Symfony bundle for interacting with the YouTube Data API v3.

Installation

composer require azaw/yt-toolkit

Register the bundle in config/bundles.php:

return [
    YtToolkit\YtToolkitPackBundle::class => ['all' => true],
];

Configuration

Set your YouTube Data API key as an environment variable:

YOUTUBE_API_KEY=your_api_key_here

The default YoutubeClientSecretProvider reads $_ENV['YOUTUBE_API_KEY']. To use a custom source, implement YoutubeClientSecretProviderInterface and bind it as the alias in your app's service configuration:

services:
  YtToolkit\Contracts\YoutubeClientSecretProviderInterface:
    alias: App\YourCustomSecretProvider

Services

FetchVideosService

Fetches videos from a YouTube channel.

use YtToolkit\Service\FetchVideosService;

$response = $fetchVideosService->fetchVideos(
    channelId: 'UCxxxxxxxxxxxxxxxxxxxxxx',
    maxResults: 25,        // optional, default 25
    pageToken: null,       // optional, for pagination
);

// $response is VideoSearchListResponse
foreach ($response->items as $result) {
    echo $result->id->videoId;
}

// Paginate
$nextPage = $fetchVideosService->fetchVideos('UCxxx', pageToken: $response->nextPageToken);

FetchChannelService

Fetches a channel by its handle (e.g. @channelname).

use YtToolkit\Service\FetchChannelService;

$response = $fetchChannelService->fetchChannelByHandle('@channelname');

// $response is ChannelListResponse
foreach ($response->items as $channel) {
    echo $channel->id;
}

YoutubeParser

Extracts a YouTube video ID from various URL formats (standard, short, embed, live).

use YtToolkit\Parser\YoutubeParser;

$parser = new YoutubeParser();

$videoId = $parser->getCodeFromLink('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// 'dQw4w9WgXcQ'

$videoId = $parser->getCodeFromLink('https://youtu.be/dQw4w9WgXcQ');
// 'dQw4w9WgXcQ'

$videoId = $parser->getCodeFromLink('https://www.youtube.com/embed/dQw4w9WgXcQ');
// 'dQw4w9WgXcQ'

$videoId = $parser->getCodeFromLink('https://www.youtube.com/live/dQw4w9WgXcQ');
// 'dQw4w9WgXcQ'

Returns null if no video ID is found.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-04