PHPackages                             lapalabs/youtube-helper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lapalabs/youtube-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lapalabs/youtube-helper
=======================

A tiny package to convenience work with YouTube media resources. Allow to extract ID from resource URL and build valid resource URLs.

v0.1.0(10y ago)089MITPHPPHP &gt;=5.4.0

Since Jul 9Pushed 10y ago1 watchersCompare

[ Source](https://github.com/LapaLabs/YoutubeHelper)[ Packagist](https://packagist.org/packages/lapalabs/youtube-helper)[ Docs](https://github.com/LapaLabs/YoutubeHelper)[ RSS](/packages/lapalabs-youtube-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

YoutubeHelper
=============

[](#youtubehelper)

A tiny package to convenience work with YouTube media resources. Allow to extract ID from resource URL and build valid resource URLs.

[![SensioLabsInsight](https://camo.githubusercontent.com/6c672bad3218daa3aa9174ab43b47ca8a04b3aa83f2f7980b9b663fb2e850473/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37336234623237612d313536642d346561372d393235612d3830376263313865353839382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/73b4b27a-156d-4ea7-925a-807bc18e5898)[![Build Status](https://camo.githubusercontent.com/de23ad8b88e53d5bd69c198695ed35b8c10c862d641624bfe890e5ded022e122/68747470733a2f2f7472617669732d63692e6f72672f4c6170614c6162732f596f757475626548656c7065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/LapaLabs/YoutubeHelper)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/89437c84057b66ce78ee1bb13841b227e847400a60cecec4492ef5027c5d3723/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c6170614c6162732f596f757475626548656c7065722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/LapaLabs/YoutubeHelper/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/656b44c483793d463b1179413f9a112ac65ea0c3a14cc61ea7266d118051e3ba/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c6170614c6162732f596f757475626548656c7065722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/LapaLabs/YoutubeHelper/?branch=master)

Installation
------------

[](#installation)

Install package to your project with `Composer`:

```
$ composer require lapalabs/youtube-helper dev-master
```

Usage
-----

[](#usage)

### Creation

[](#creation)

You can easily create valid YouTube resource object:

```
use LapaLabs\YoutubeExtractor\Resource\YoutubeResource;

// Build resource object from valid YouTube resource ID
$resource = new YoutubeResource('5qanlirrRWs');
// or with static method
$resource = YoutubeResource::create('5qanlirrRWs');

// or create from valid YouTube resource URL
$resource = YoutubeResource::createFromUrl('https://www.youtube.com/watch?v=5qanlirrRWs');
```

There are a few valid YouTube resource URLs, supported by this library, that should be used in `YoutubeResource::createFromUrl()` method:

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

### Advanced usage

[](#advanced-usage)

After resource was successfully created you get access to a bunch of useful methods:

```
$resource->getId();           // 5qanlirrRWs
$resource->buildEmbedUrl();   // https://www.youtube.com/embed/5qanlirrRWs

// other useful methods to build various valid URLs
$resource->buildUrl();        // shortcut alias for buildDefaultUrl
$resource->buildDefaultUrl(); // https://www.youtube.com/watch?v=5qanlirrRWs
$resource->buildAliasUrl();   // https://youtube.com/watch?v=5qanlirrRWs
$resource->buildMobileUrl();  // https://m.youtube.com/watch?v=5qanlirrRWs
$resource->buildShortUrl();   // https://youtu.be/5qanlirrRWs
```

You can get array of valid YouTube resource URLs which could used in `createFromUrl` method:

```
YoutubeResource::getValidHosts(); // array of valid YouTube resource URLs
```

To check whether YouTube resource ID or host is valid use follow methods:

```
YoutubeResource::isValidId('5qanlirrRWs'); // return true if ID is valid
YoutubeResource::isValidHost('youtu.be');  // return true if host is valid
```

You can easily get HTML code to embed YouTube resource on your page:

```
$resource->buildEmbedCode(); // with default attributes returns:

// to pass any other parameters or override defaults with your own use:
$resource->buildEmbedCode([
    'width' => 800,     // override default 560
    'height' => 600,    // override default 315
    'class' => 'video', // add new attribute
]);
```

> The passed attributes to `buildEmbedCode()` methods applies for current embed HTML code only. To change default attributes globally for specific resource you should pass an array of attributes to `setAttributes()` method. To get current default HTML attributes of specific resource use `getAttributes()` method.

There are a few attributes by default:

```
[
    'width'           => 560,
    'height'          => 315,
    'src'             => '', // hold position for specific order
    'frameborder'     => 0,
    'allowfullscreen' => null,
];
```

> **NOTE:** The `src` attribute is only required for building embed HTML code and will be injected automatically by calling `buildEmbedUrl()` method behind the scenes. So every given `src` value to `buildEmbedCode()` or `setAttributes()` will be ignoring and replacing with correct URL for current resource. You could give it like in example above to point its position in HTML code.

Links
-----

[](#links)

Feel free to create an [Issue](https://github.com/LapaLabs/YoutubeHelper/issues) or [Pull Request](https://github.com//LapaLabs/YoutubeHelper/pulls) if you find a bug or just want to propose improvement suggestion.

[Move UP](#youtubehelper)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

4

Last Release

3962d ago

PHP version history (2 changes)v0.0.1PHP &gt;=5.3.0

v0.1.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce9dde2c8d3d5fcfdbb5427f981df17123b54b410e21e4dfc933f07983eefeba?d=identicon)[bocharsky-bw](/maintainers/bocharsky-bw)

---

Top Contributors

[![bocharsky-bw](https://avatars.githubusercontent.com/u/3317635?v=4)](https://github.com/bocharsky-bw "bocharsky-bw (34 commits)")

---

Tags

youtubelapalabsurl builderembed resourceid extractor

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.4k48.6M278](/packages/hashids-hashids)[norkunas/youtube-dl-php

youtube-dl / yt-dlp wrapper for php

512323.2k15](/packages/norkunas-youtube-dl-php)[aalaap/faker-youtube

Faker provider for generating fake YouTube video URLs

2288.6k](/packages/aalaap-faker-youtube)[light/hashids

Hashids for Yii2

1120.2k](/packages/light-hashids)

PHPackages © 2026

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