Vex - Parse any video URL 
Vex is a PHP library to extract a video from any URL.
Supported Services
For each video-sharing website of the following list, a Platform class can identify a supported URL and extract the video data.
Installation
The recommended way to install Vex is through composer.
Just create a composer.json
file for your project:
{
"require": {
"kphoen/vex": "1.1.*"
}
}
And run these two commands to install it:
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
Now you can add the autoloader, and you will have access to the library:
<?php
require 'vendor/autoload.php';
If you don't use neither Composer nor a ClassLoader in your application, just require the provided autoloader:
<?php
require_once 'src/autoload.php';
You're done.
Usage
<?php
use Vex\Vex;
$http_adapter = new \Vex\HttpAdapter\BuzzHttpAdapter();
$platform = \Vex\Platform\RutubePlatform($adapter);
$vex = new Vex($platform);
$video = $vex->extract('https://rutube.ru/video/b5a392c180ddfe3e1ebded38f9f9dc52/');
// Show the video title
echo $video->getTitle();
// Shows the embedded video HTML
echo $video->getCode();
// Show the video link
echo $video->getLink();
// Show the video duration
echo $video->getDuration();
// Show the video thumbnail
echo $video->getThumb();
$url = $vex->reverse('<iframe width="640" height="360" src="http://rutube.ru/video/embed/6236741" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen scrolling="no"></iframe>');
// shows http://rutube.ru/video/9f4dc6bc2db6b6051ea07fb20234c6cc/
echo $url
Tests
To run unit tests, you'll need cURL and a set of dependencies you can install using Composer:
php composer.phar install --dev
Once installed, just launch the following command:
phpunit
Credits
- Kévin Gomez
- William Durand - for the
HttpAdapter
part, which was borrowed from Geocoder - Jérôme Tamarelle - to whom I borrowed this README
License
Vex is released under the MIT License. See the bundled LICENSE file for details.