Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types = 1);
- namespace App\WwwModule\Presenter;
- final class RecordPresenter extends \Nepttune\Presenter\BaseAuthPresenter
- {
- private $videoTable;
- public function __construct(\App\Table\VideoTable $videoTable)
- {
- $this->videoTable = $videoTable;
- }
- public function actionGetThumbnail(?int $id) : \App\Database\Row
- {
- $row = $this->videoTable->findById($id)->fetch();
- if (strpos($row->url, 'youtube.com')) {
- $id = explode('?v=', $row->url);
- $img = 'http://img.youtube.com/vi/'.$id[1].'/maxresdefault.jpg';
- return $img;
- }
- elseif (strpos($row->url, 'vimeo.com')) {
- $id = explode('vimeo.com/', $row->url);
- $url = 'https://player.vimeo.com/video/'.$id[1];
- $data = json_decode(file_get_contents('http://vimeo.com/api/oembed.json?url='.$url));
- $img = $data->thumbnail_url;
- return $img;
- }
- else {
- throw new \Nette\Application\BadRequestException('Video not found', 404);
- }
- }
- public function actionGetUrl(?int $id)
- {
- $row = $this->videoTable->findById($id)->fetch();
- if (strpos($row->url, 'youtube.com')) {
- $id = explode('?v=', $row->url);
- $url = 'https://www.youtube.com/embed/'.$id[1];
- return $url;
- }
- elseif (strpos($row->url, 'vimeo.com')) {
- $id = explode('vimeo.com/', $row->url);
- $url = 'https://player.vimeo.com/video/'.$id[1];
- return $url;
- }
- else {
- throw new \Nette\Application\BadRequestException('Video not found', 404);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement