PHPackages                             cable8mm/youtube - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cable8mm/youtube

ActiveLibrary[API Development](/categories/api)

cable8mm/youtube
================

Renew Laravel PHP Facade/Wrapper for the Youtube Data API v3

v5.1.0(1mo ago)1243MITPHPPHP ^8.2CI passing

Since Feb 5Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/cable8mm/Youtube)[ Packagist](https://packagist.org/packages/cable8mm/youtube)[ RSS](/packages/cable8mm-youtube/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (10)Dependencies (12)Versions (13)Used By (0)

⭐ YouTube API for Laravel
=========================

[](#-youtube-api-for-laravel)

[![code-style](https://github.com/cable8mm/Youtube/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/Youtube/actions/workflows/code-style.yml)[![run-tests](https://github.com/cable8mm/Youtube/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/Youtube/actions/workflows/run-tests.yml)[![Packagist Version](https://camo.githubusercontent.com/1e20240f4802776247ceb356640171232030c2c218c03a778137676df2b580c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361626c65386d6d2f796f7574756265)](https://packagist.org/packages/cable8mm/youtube)[![Packagist Downloads](https://camo.githubusercontent.com/9871cc09abfe6c24ad25ea5035f3b340ef8f5c1607bd628686d691d2a9f317b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361626c65386d6d2f796f7574756265)](https://packagist.org/packages/cable8mm/youtube)[![Packagist Stars](https://camo.githubusercontent.com/d2cf3a844bee2dcfd9f6e91b20c54d8704db02f5a090e2a2aacd4593d8ba90e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6361626c65386d6d2f796f7574756265)](https://packagist.org/packages/cable8mm/youtube)[![PHP Version](https://camo.githubusercontent.com/1c7e7dac6b10eab6d5c5104d4ebcec11bb7581c049d4bba9b26b43eb475e8d36/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6361626c65386d6d2f796f75747562652f706870)](https://packagist.org/packages/cable8mm/youtube)[![Laravel Version](https://camo.githubusercontent.com/9ccf2210d46438232f455bf6a051329a89e2134f5bc34d1055981dfbf3e834bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6361626c65386d6d2f796f75747562652f696c6c756d696e6174652f737570706f7274)](https://packagist.org/packages/cable8mm/youtube)[![License](https://camo.githubusercontent.com/12b1911fbece1b0c62b9327cc01d45be4338370bb667e3ad5ab359639077ea67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6361626c65386d6d2f796f7574756265)](https://packagist.org/packages/cable8mm/youtube)

> 🚀 A modern, elegant, and feature-rich Laravel wrapper for YouTube Data API v3 (Non-OAuth)

A beautifully crafted Laravel package that provides a simple, fluent interface to interact with YouTube Data API v3. Built with PHP 8.2+ features, comprehensive test coverage, and developer experience in mind.

✨ Features
----------

[](#-features)

- 🎯 **Simple &amp; Elegant API** - Clean, intuitive, and Laravel-style interface
- ⚡ **Fluent Interface** - Chain methods for better readability
- 🔒 **Type-Safe** - Full type hints and strict typing for PHP 8.2+
- 🎨 **Laravel Native** - Seamless integration with Laravel ecosystem
- 🚀 **High Performance** - Built-in response caching to reduce API calls
- ✅ **Well Tested** - 73 comprehensive tests with 100% pass rate
- 🛡️ **Custom Exceptions** - Domain-specific error handling
- 📝 **Validation Rules** - Built-in validation for YouTube URLs (Laravel 10+)
- 🔄 **Auto-Discovery** - Automatic service provider registration
- 📚 **Extensive Documentation** - Clear examples and usage guides

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, 12.x, or 13.x
- YouTube Data API v3 Key ([Get one here](https://console.developers.google.com))

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require cable8mm/youtube
```

⚙️ Configuration
----------------

[](#️-configuration)

### Step 1: Publish Configuration

[](#step-1-publish-configuration)

```
php artisan vendor:publish --provider="Cable8mm\Youtube\YoutubeServiceProvider"
```

### Step 2: Add API Key

[](#step-2-add-api-key)

Add your YouTube API key to your `.env` file:

```
YOUTUBE_API_KEY=your_api_key_here
```

Or directly in `config/youtube.php`:

```
return [
    'key' => env('YOUTUBE_API_KEY', 'YOUR_API_KEY'),
];
```

🎯 Quick Start
-------------

[](#-quick-start)

### Basic Usage

[](#basic-usage)

```
use Cable8mm\Youtube\Facades\Youtube;

// Get video information
$video = Youtube::getVideoInfo('rie-hPVJ7Sw');

// Get multiple videos
$videos = Youtube::getVideoInfo(['rie-hPVJ7Sw', 'iKHTawgyKWQ']);

// Search videos
$results = Youtube::searchVideos('Laravel Tutorial', 10);

// Get channel information
$channel = Youtube::getChannelById('UCk1SpWNzOs4MYmr0uICEntg');

// Get popular videos by country
$popular = Youtube::getPopularVideos('US', 10);
```

### Fluent Interface

[](#fluent-interface)

```
$youtube = (new Youtube($apiKey))
    ->useHttpHost(true)
    ->cache()
    ->setCacheTtl(1800);

$videos = $youtube->getPopularVideos('US', 10);
```

### With Caching (Recommended)

[](#with-caching-recommended)

Enable caching to reduce API calls and improve performance:

```
// Via constructor
$youtube = new Youtube($apiKey, [
    'cache_enabled' => true,
    'cache_ttl' => 3600, // 1 hour
]);

// Or via fluent interface
$youtube = (new Youtube($apiKey))->cache()->setCacheTtl(3600);
```

📖 API Reference
---------------

[](#-api-reference)

### Video Methods

[](#video-methods)

```
// Get single video info
$video = Youtube::getVideoInfo('video_id');

// Get multiple videos
$videos = Youtube::getVideoInfo(['id1', 'id2']);

// Get localized video info
$video = Youtube::getLocalizedVideoInfo('video_id', 'ko');

// Get popular videos by region
$videos = Youtube::getPopularVideos('KR', 20);
```

### Search Methods

[](#search-methods)

```
// General search
$results = Youtube::search('Laravel', 10);

// Search videos only
$videos = Youtube::searchVideos('Laravel', 10, 'viewCount');

// Search in specific channel
$videos = Youtube::searchChannelVideos('keyword', 'channel_id', 20);

// Advanced search with custom parameters
$results = Youtube::searchAdvanced([
    'q' => 'Laravel',
    'type' => 'video',
    'part' => 'id,snippet',
    'maxResults' => 50,
    'order' => 'date'
], true); // true = include page info
```

### Channel Methods

[](#channel-methods)

```
// Get channel by ID
$channel = Youtube::getChannelById('channel_id');

// Get channel by name
$channel = Youtube::getChannelByName('username');

// Get channel videos
$videos = Youtube::getChannelVideos('channel_id', 10, null, false, '');

// List channel videos
$videos = Youtube::listChannelVideos('channel_id', 10, 'date');
```

### Playlist Methods

[](#playlist-methods)

```
// Get playlist by ID
$playlist = Youtube::getPlaylistById('playlist_id');

// Get multiple playlists
$playlists = Youtube::getPlaylistById(['id1', 'id2']);

// Get playlists by channel
$playlists = Youtube::getPlaylistsByChannelId('channel_id');

// Get playlist items
$items = Youtube::getPlaylistItemsByPlaylistId('playlist_id', '', 50);
```

### Comment Methods

[](#comment-methods)

```
// Get comment threads by video ID
$comments = Youtube::getCommentThreadsByVideoId('video_id', 20, 'time');
```

### Activity Methods

[](#activity-methods)

```
// Get channel activities
$activities = Youtube::getActivitiesByChannelId('channel_id', 10);
```

### Utility Methods

[](#utility-methods)

```
// Parse video ID from URL
$videoId = Youtube::parseVidFromURL('https://youtu.be/rie-hPVJ7Sw');

// Get channel from URL
$channel = Youtube::getChannelFromURL('https://youtube.com/channel/...');
```

🔍 Pagination
------------

[](#-pagination)

### Basic Pagination

[](#basic-pagination)

```
$params = [
    'q' => 'Laravel',
    'type' => 'video',
    'part' => 'id,snippet',
    'maxResults' => 50
];

// Get first page
$search = Youtube::searchAdvanced($params, true);

// Get next page
if (isset($search['info']['nextPageToken'])) {
    $params['pageToken'] = $search['info']['nextPageToken'];
    $nextPage = Youtube::searchAdvanced($params, true);
}
```

### Using paginateResults()

[](#using-paginateresults)

```
$params = [
    'q' => 'Laravel',
    'type' => 'video',
    'part' => 'id,snippet',
    'maxResults' => 50
];

$pageTokens = [];

// Initial search
$search = Youtube::paginateResults($params, null);
$pageTokens[] = $search['info']['nextPageToken'];

// Navigate through pages
$page1 = Youtube::paginateResults($params, $pageTokens[0]);
$page2 = Youtube::paginateResults($params, $pageTokens[1]);

// Go back
$previousPage = Youtube::paginateResults($params, $pageTokens[0]);
```

✅ Validation Rules
------------------

[](#-validation-rules)

Validate YouTube video URLs in your Laravel forms:

```
use Cable8mm\Youtube\Rules\ValidYoutubeVideo;

$request->validate([
    'video_url' => ['bail', 'required', new ValidYoutubeVideo],
]);
```

**Supported URL formats:**

- `https://www.youtube.com/watch?v=VIDEO_ID`
- `https://youtu.be/VIDEO_ID`
- `https://www.youtube.com/embed/VIDEO_ID`

**Note:** Uses Laravel 10+ `ValidationRule` interface with closure-based error messages.

🧪 Testing
---------

[](#-testing)

Run the test suite:

```
# Run all tests
composer test

# Run with API tests enabled
YOUTUBE_ENABLED=true composer test
```

**Test Coverage:**

- ✅ 73 comprehensive tests
- ✅ Unit tests (no API key required)
- ✅ Integration tests with Orchestra Testbench (requires API key)
- ✅ 100% pass rate

📁 Package Structure
-------------------

[](#-package-structure)

```
src/
├── Youtube.php                    # Main class
├── YoutubeServiceProvider.php     # Laravel service provider
├── Facades/
│   └── Youtube.php                # Laravel facade
├── Rules/
│   └── ValidYoutubeVideo.php      # Validation rule
├── Cache/
│   └── YoutubeCache.php           # Caching layer
├── Exceptions/
│   └── YoutubeApiException.php    # Custom exceptions
└── config/
    └── youtube.php                # Configuration file

```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the project
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

📝 Changelog
-----------

[](#-changelog)

See [CHANGELOG.md](CHANGELOG.md) for recent changes.

🔗 Links
-------

[](#-links)

- 📦 [Packagist](https://packagist.org/packages/cable8mm/youtube)
- 🐛 [Issue Tracker](https://github.com/cable8mm/Youtube/issues)
- 💻 [GitHub Repository](https://github.com/cable8mm/Youtube)

🙏 Credits
---------

[](#-credits)

- Built on code from [Alaouy/youtube](https://github.com/alaouy/youtube)
- Inspired by the Laravel community

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

Made with ❤️ by [cable8mm](https://github.com/cable8mm)

 [⭐ Star us on GitHub!](https://github.com/cable8mm/Youtube)

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance94

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 53.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~80 days

Recently: every ~216 days

Total

12

Last Release

32d ago

Major Versions

v3.2.1 → v4.0.02024-02-22

v4.2.0 → v5.0.02025-12-01

PHP version history (2 changes)v3.0.0PHP ^8.0

v5.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/c910c874a0263a18f9f976273054cd45faa3ffbcba7891992f4ab52d0656dd93?d=identicon)[Sam Lee](/maintainers/Sam%20Lee)

---

Top Contributors

[![alaouy](https://avatars.githubusercontent.com/u/3118889?v=4)](https://github.com/alaouy "alaouy (97 commits)")[![cable8mm](https://avatars.githubusercontent.com/u/2672043?v=4)](https://github.com/cable8mm "cable8mm (27 commits)")[![bzbislawski](https://avatars.githubusercontent.com/u/12448772?v=4)](https://github.com/bzbislawski "bzbislawski (11 commits)")[![mahmutbayri](https://avatars.githubusercontent.com/u/1398166?v=4)](https://github.com/mahmutbayri "mahmutbayri (8 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (4 commits)")[![vishal-sancheti](https://avatars.githubusercontent.com/u/4789936?v=4)](https://github.com/vishal-sancheti "vishal-sancheti (4 commits)")[![digitalhuman](https://avatars.githubusercontent.com/u/780848?v=4)](https://github.com/digitalhuman "digitalhuman (3 commits)")[![Rpsl](https://avatars.githubusercontent.com/u/265634?v=4)](https://github.com/Rpsl "Rpsl (2 commits)")[![qWici](https://avatars.githubusercontent.com/u/11472929?v=4)](https://github.com/qWici "qWici (2 commits)")[![brunoxavier-dev](https://avatars.githubusercontent.com/u/42558239?v=4)](https://github.com/brunoxavier-dev "brunoxavier-dev (2 commits)")[![akiyamaSM](https://avatars.githubusercontent.com/u/12276076?v=4)](https://github.com/akiyamaSM "akiyamaSM (2 commits)")[![lucaspanik](https://avatars.githubusercontent.com/u/7035554?v=4)](https://github.com/lucaspanik "lucaspanik (1 commits)")[![messerli90](https://avatars.githubusercontent.com/u/3306651?v=4)](https://github.com/messerli90 "messerli90 (1 commits)")[![m-pastuszek](https://avatars.githubusercontent.com/u/32341770?v=4)](https://github.com/m-pastuszek "m-pastuszek (1 commits)")[![paoloposo](https://avatars.githubusercontent.com/u/10469413?v=4)](https://github.com/paoloposo "paoloposo (1 commits)")[![Slaver](https://avatars.githubusercontent.com/u/68165?v=4)](https://github.com/Slaver "Slaver (1 commits)")[![stickpro](https://avatars.githubusercontent.com/u/25886722?v=4)](https://github.com/stickpro "stickpro (1 commits)")[![tylergets](https://avatars.githubusercontent.com/u/9418094?v=4)](https://github.com/tylergets "tylergets (1 commits)")[![wmerfalen](https://avatars.githubusercontent.com/u/2633195?v=4)](https://github.com/wmerfalen "wmerfalen (1 commits)")[![Xartrick](https://avatars.githubusercontent.com/u/1482818?v=4)](https://github.com/Xartrick "Xartrick (1 commits)")

---

Tags

apilaravelpackagephp8youtubeyoutube-apiapilaravelvideoyoutubealaouycable8mm

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cable8mm-youtube/health.svg)

```
[![Health](https://phpackages.com/badges/cable8mm-youtube/health.svg)](https://phpackages.com/packages/cable8mm-youtube)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k99.8M341](/packages/laravel-horizon)[alaouy/youtube

Laravel PHP Facade/Wrapper for the Youtube Data API v3

8091.4M9](/packages/alaouy-youtube)[smodav/mpesa

M-Pesa API implementation

16468.7k1](/packages/smodav-mpesa)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
