Skip to content

Commit c9da906

Browse files
finalization of readme
1 parent 7d35f75 commit c9da906

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
# 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+
356

457
# TODO List goals for release 1.0:
558

src/Detector/VideoDetector.php renamed to src/Detector/VideoServiceDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @author Ricardo Fiorani
1212
*/
13-
class VideoDetector
13+
class VideoServiceDetector
1414
{
1515
/**
1616
* @var array

src/Exception/NotEmbedableException.php renamed to src/Exception/NotEmbeddableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use Exception;
1313

14-
class NotEmbedableException extends Exception
14+
class NotEmbeddableException extends Exception
1515
{
1616

1717
}

0 commit comments

Comments
 (0)