2017 © Pedro Peláez
 

library parse-youtube-id

Parse the Video ID from a YouTube URL

image

waynestate/parse-youtube-id

Parse the Video ID from a YouTube URL

  • Wednesday, March 14, 2018
  • by nickdenardis
  • Repository
  • 3 Watchers
  • 1 Stars
  • 1,396 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 91 % Grown

The README.md

Parse YouTube Video ID from URL

Master Build Status | Coverage Status, (*1)

Given a YouTube video URL, parse out the video ID., (*2)

Usage

Install the package via composer:, (*3)

composer require waynestate/parse-youtube-id

Parse full YouTube URL's, (*4)

use Waynestate\Youtube\ParseId;

...

$youtube_id = ParseId::fromUrl('https://www.youtube.com/watch?v=yCjTG0rOIXQ');
echo $youtube_id; // 'yCjTG0rOIXQ'

Parse short YouTube URL's, (*5)

$youtube_id = ParseId::fromUrl('https://youtu.be/yCjTG0rOIXQ');
echo $youtube_id; // 'yCjTG0rOIXQ'

Null strings or non-YouTube URL's return an empty string, (*6)

$youtube_id = ParseId::fromUrl('');
echo $youtube_id; // ''

See /tests/UrlParseTest.php for all supported URL variations., (*7)

Regex

$pattern = '#^(?:https?://|//)?' # Optional URL scheme. Either http, or https, or protocol-relative.
         . '(?:www\.|m\.)?'      #  Optional www or m subdomain.
         . '(?:'                 #  Group host alternatives:
         .   'youtu\.be/'        #    Either youtu.be,
         .   '|youtube\.com/'    #    or youtube.com
         .     '(?:'             #    Group path alternatives:
         .       'embed/'        #      Either /embed/,
         .       '|v/'           #      or /v/,
         .       '|watch\?v='    #      or /watch?v=,
         .       '|watch\?.+&v=' #      or /watch?other_param&v=
         .     ')'               #    End path alternatives.
         . ')'                   #  End host alternatives.
         . '([\w-]{11})'         # 11 characters (Length of Youtube video ids).
         . '(?![\w-])#';         # Rejects if overlong id.

Tests

composer test

Contributing

See CONTRIBUTING.md for details, (*8)

Credit

Adapted from Stephan Schmitz at https://3v4l.org/GEDT0, (*9)

About

Wayne State University (WSU) is an urban public research university located in Detroit, Michigan., (*10)

The Versions

14/03 2018

dev-develop

dev-develop https://github.com/waynestate/parse-youtube-id

Parse the Video ID from a YouTube URL

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

url youtube waynestate

14/03 2018

dev-master

9999999-dev https://github.com/waynestate/parse-youtube-id

Parse the Video ID from a YouTube URL

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

url youtube waynestate

14/03 2018

1.0.0

1.0.0.0 https://github.com/waynestate/parse-youtube-id

Parse the Video ID from a YouTube URL

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

url youtube waynestate

14/03 2018

dev-release/1.0.0

dev-release/1.0.0 https://github.com/waynestate/parse-youtube-id

Parse the Video ID from a YouTube URL

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

url youtube waynestate