|
1 | 1 | # PHP Video URL Parser
|
2 |
| -Simple Video Parser in PHP |
| 2 | +PHP Video URL Parser receives an video service URL (Like Youtube or VIMEO) and returns an object containing some video info |
| 3 | +such as Thumnail's, Video Title, Video Description. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Install the latest version with |
| 8 | + |
| 9 | +```bash |
| 10 | +$ composer require ricardofiorani/ricardofiorani/php-video-url-parser |
| 11 | +``` |
| 12 | + |
| 13 | +## Basic Usage |
| 14 | + |
| 15 | +```php |
| 16 | +<?php |
| 17 | +use RicardoFiorani\Detector\VideoServiceDetector; |
| 18 | + |
| 19 | +require __DIR__ . '/vendor/autoload.php'; |
| 20 | + |
| 21 | +$vsd = new VideoServiceDetector(); |
| 22 | + |
| 23 | +//Detects wich service the url belongs to and returns the service's implementation |
| 24 | +//of RicardoFiorani\Adapter\VideoAdapterInterface |
| 25 | +$video = $vsd->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw'); |
| 26 | + |
| 27 | +//Checks if service provides embeddable videos (most services does) |
| 28 | +if ($video->isEmbeddable()) { |
| 29 | + //Will echo the embed html element with the size 200x200 |
| 30 | + echo $video->getEmbedCode(200, 200); |
| 31 | + |
| 32 | + //Returns the embed html element with the size 1920x1080 and autoplay enable |
| 33 | + echo $video->getEmbedCode(1920, 1080, true); |
| 34 | +} |
| 35 | + |
| 36 | +//If you don't want to check if service provides embeddable videos you can try/catch |
| 37 | +try { |
| 38 | + echo $video->getEmbedUrl(); |
| 39 | +} catch (\RicardoFiorani\Exception\NotEmbeddableException $e) { |
| 40 | + die(sprintf("The URL %s service does not provide embeddable videos.", $video->getRawUrl())); |
| 41 | +} |
| 42 | + |
| 43 | +//Gets URL of the smallest thumbnail size available |
| 44 | +echo $video->getSmallThumbnail(); |
| 45 | + |
| 46 | +//Gets URL of the largest thumbnail size available |
| 47 | +//Note some services (such as Youtube) does not provide the largest thumbnail for some low quality videos (like the one used in this example) |
| 48 | +echo $video->getLargestThumbnail(); |
| 49 | +``` |
| 50 | + |
| 51 | +## Registering your own service video (it's easy !) |
| 52 | +If you want to register an implementation of some service your class just needs to implement the "RicardoFiorani\Adapter\VideoAdapterInterface" or extend the RicardoFiorani\Adapter\AbstractServiceAdapter |
| 53 | + |
| 54 | +A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/example/RegisteringANewService.md) |
| 55 | + |
3 | 56 |
|
4 | 57 | # TODO List goals for release 1.0:
|
5 | 58 |
|
|
0 commit comments