Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2.  
  3. declare(strict_types = 1);
  4.  
  5. namespace App\WwwModule\Presenter;
  6.  
  7. final class RecordPresenter extends \Nepttune\Presenter\BaseAuthPresenter
  8. {
  9. private $videoTable;
  10.  
  11. public function __construct(\App\Table\VideoTable $videoTable)
  12. {
  13. $this->videoTable = $videoTable;
  14. }
  15.  
  16. public function actionGetThumbnail(?int $id) : \App\Database\Row
  17. {
  18. $row = $this->videoTable->findById($id)->fetch();
  19.  
  20. if (strpos($row->url, 'youtube.com')) {
  21.  
  22. $id = explode('?v=', $row->url);
  23. $img = 'http://img.youtube.com/vi/'.$id[1].'/maxresdefault.jpg';
  24.  
  25. return $img;
  26.  
  27. }
  28. elseif (strpos($row->url, 'vimeo.com')) {
  29.  
  30. $id = explode('vimeo.com/', $row->url);
  31. $url = 'https://player.vimeo.com/video/'.$id[1];
  32. $data = json_decode(file_get_contents('http://vimeo.com/api/oembed.json?url='.$url));
  33. $img = $data->thumbnail_url;
  34.  
  35. return $img;
  36. }
  37. else {
  38.  
  39. throw new \Nette\Application\BadRequestException('Video not found', 404);
  40. }
  41. }
  42.  
  43. public function actionGetUrl(?int $id)
  44. {
  45. $row = $this->videoTable->findById($id)->fetch();
  46.  
  47. if (strpos($row->url, 'youtube.com')) {
  48.  
  49. $id = explode('?v=', $row->url);
  50. $url = 'https://www.youtube.com/embed/'.$id[1];
  51.  
  52. return $url;
  53.  
  54. }
  55. elseif (strpos($row->url, 'vimeo.com')) {
  56.  
  57. $id = explode('vimeo.com/', $row->url);
  58. $url = 'https://player.vimeo.com/video/'.$id[1];
  59.  
  60. return $url;
  61. }
  62. else {
  63.  
  64. throw new \Nette\Application\BadRequestException('Video not found', 404);
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement