2017 © Pedro Peláez
 

library youtube-helper

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

image

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.

  • Sunday, March 20, 2016
  • by bocharsky-bw
  • Repository
  • 1 Watchers
  • 0 Stars
  • 60 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

YoutubeHelper

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

SensioLabsInsight Build Status Scrutinizer Code Quality Code Coverage, (*2)

Installation

Install package to your project with Composer:, (*3)

``` bash $ composer require lapalabs/youtube-helper dev-master, (*4)


## Usage ### Creation You can easily create valid YouTube resource object: ``` php 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:, (*5)

  • 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

After resource was successfully created you get access to a bunch of useful methods:, (*6)

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

// 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, (*8)


You can get array of valid YouTube resource URLs which could used in `createFromUrl` method: ``` php YoutubeResource::getValidHosts(); // array of valid YouTube resource URLs

To check whether YouTube resource ID or host is valid use follow methods:, (*9)

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


You can easily get HTML code to embed YouTube resource on your page: ``` php $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., (*11)

There are a few attributes by default:, (*12)

php [ 'width' => 560, 'height' => 315, 'src' => '', // hold position for specific order 'frameborder' => 0, 'allowfullscreen' => null, ];, (*13)

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., (*14)

Feel free to create an Issue or [Pull Request][2] if you find a bug or just want to propose improvement suggestion., (*15)

Move UP, (*16)

The Versions

20/03 2016

dev-master

9999999-dev https://github.com/LapaLabs/YoutubeHelper

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by LapaLabs

youtube url builder lapalabs embed resource id extractor

13/07 2015

v0.1.0

0.1.0.0 https://github.com/LapaLabs/YoutubeHelper

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by LapaLabs

youtube url builder lapalabs embed resource id extractor

10/07 2015

v0.0.3

0.0.3.0 https://github.com/LapaLabs/YoutubeHelper

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by LapaLabs

youtube url builder lapalabs embed resource id extractor

10/07 2015

v0.0.2

0.0.2.0 https://github.com/LapaLabs/YoutubeHelper

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by LapaLabs

youtube url builder lapalabs embed resource id extractor

09/07 2015

v0.0.1

0.0.1.0 https://github.com/LapaLabs/YoutubeHelper

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by LapaLabs

youtube url builder lapalabs embed resource id extractor