asset_mediaserver_renderer.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Media Server renderer.
  4. *
  5. * Note that some videos are protected. It is therefore not possible to use the
  6. * autodiscovery feature. That is to get the web page, look at the meta data headers
  7. * and read the oembed api call. This would only work for public content/javascript
  8. * bookmarklet.
  9. *
  10. * So here we bypass the discovery service and directly call the API endpoint
  11. * with the page url to retrieve oembed metadata - which happens to be public.
  12. *
  13. * @see https://mediaserver.unige.ch
  14. *
  15. * @copyright (c) 2012 University of Geneva
  16. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  17. * @author Laurent Opprecht
  18. */
  19. class AssetMediaserverRenderer extends AssetRenderer
  20. {
  21. const API_ENDPOINT = 'http://129.194.20.121/oembed/unige-oembed-provider-test.php';
  22. /**
  23. *
  24. * @param HttpResource $asset
  25. */
  26. public function accept($asset)
  27. {
  28. return $asset->url_match('https://mediaserver.unige.ch/play/') ||$asset->url_match('http://mediaserver.unige.ch/play/');
  29. }
  30. /**
  31. *
  32. * @param HttpResource $asset
  33. */
  34. public function render($asset)
  35. {
  36. if (!$this->accept($asset))
  37. {
  38. return;
  39. }
  40. $width = (int) $asset->config('size');
  41. $width = (24 <= $width && $width <= 800) ? $width : 300;
  42. $url = $asset->url();
  43. $oembed = self::API_ENDPOINT . '?url=' . urlencode($url) . '&maxwidth=' . $width;
  44. $data = HttpResource::fetch_json($oembed);
  45. if (empty($data))
  46. {
  47. return false;
  48. }
  49. $result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : '';
  50. $result[self::TITLE] = isset($data['title']) ? $data['title'] : '';
  51. $result[self::EMBED_SNIPPET] = isset($data['html']) ? $data['html'] : '';
  52. return $result;
  53. }
  54. }