WaveVideo.php
| 1 | <?php |
| 2 | /** |
| 3 | * WaveVideo.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Embera\Provider; |
| 14 | |
| 15 | use Embera\Url; |
| 16 | |
| 17 | /** |
| 18 | * WaveVideo Provider |
| 19 | * Make your own videos and host them with Wave.video. Build your entire video funnel. Sign up now... |
| 20 | * |
| 21 | * @link https://wave.video |
| 22 | * |
| 23 | */ |
| 24 | class WaveVideo extends ProviderAdapter implements ProviderInterface |
| 25 | { |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected $endpoint = 'https://embed.wave.video/oembed?format=json'; |
| 28 | |
| 29 | /** inline {@inheritdoc} */ |
| 30 | protected static $hosts = [ |
| 31 | 'watch.wave.video', |
| 32 | 'embed.wave.video' |
| 33 | ]; |
| 34 | |
| 35 | /** inline {@inheritdoc} */ |
| 36 | protected $responsiveSupport = false; |
| 37 | |
| 38 | /** inline {@inheritdoc} */ |
| 39 | public function validateUrl(Url $url) |
| 40 | { |
| 41 | return (bool) (preg_match('~(watch|embed)\.wave\.video/([^/]+)$~i', (string) $url)); |
| 42 | } |
| 43 | |
| 44 | /** inline {@inheritdoc} */ |
| 45 | public function normalizeUrl(Url $url) |
| 46 | { |
| 47 | $url->convertToHttps(); |
| 48 | $url->removeQueryString(); |
| 49 | $url->removeLastSlash(); |
| 50 | |
| 51 | return $url; |
| 52 | } |
| 53 | |
| 54 | /** inline {@inheritdoc} */ |
| 55 | public function getFakeResponse() |
| 56 | { |
| 57 | preg_match('~/([a-z0-9_\-]+)$~i', (string) $this->url, $matches); |
| 58 | |
| 59 | $embedUrl = 'https://embed.wave.video/' . $matches['0']; |
| 60 | |
| 61 | $attr = []; |
| 62 | $attr[] = 'src="' . $embedUrl . '"'; |
| 63 | $attr[] = 'height="{height}"'; |
| 64 | $attr[] = 'width="{width}"'; |
| 65 | $attr[] = 'frameborder="0"'; |
| 66 | $attr[] = 'allow="autoplay; fullscreen'; |
| 67 | |
| 68 | return [ |
| 69 | 'type' => 'video', |
| 70 | 'provider_name' => 'WaveVideo', |
| 71 | 'provider_url' => 'https://wave.video', |
| 72 | 'title' => 'Unknown title', |
| 73 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 74 | ]; |
| 75 | } |
| 76 | |
| 77 | } |
| 78 |