MediaVimeoStreamWrapper.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * Create a Vimeo Stream Wrapper class for the Media/Resource module.
  5. */
  6. /**
  7. * Create an instance like this:
  8. * $vimeo = new ResourceVimeoStreamWrapper('vimeo://v/[video-code]');
  9. */
  10. class MediaVimeoStreamWrapper extends MediaReadOnlyStreamWrapper {
  11. static function getMimeType($uri, $mapping = NULL) {
  12. return 'video/vimeo';
  13. }
  14. /**
  15. * Call the Vimeo Simple API and fetch the video information.
  16. *
  17. * See http://vimeo.com/api/docs/simple-api
  18. *
  19. * @return
  20. * Array of properties.
  21. */
  22. static function getVideoProperties($video_id) {
  23. // The .php format returns a serialized array.
  24. $response = drupal_http_request('http://vimeo.com/api/v2/video/'. $video_id .'.php');
  25. return unserialize($response->data);
  26. }
  27. function getTarget($f) {
  28. return FALSE;
  29. }
  30. function interpolateUrl() {
  31. return 'http://vimeo.com/' . intval($this->parameters['v']);
  32. }
  33. function getOriginalThumbnailPath() {
  34. $video_properties = self::getVideoProperties($this->parameters['v']);
  35. return $video_properties[0]['thumbnail_large'];
  36. }
  37. function getLocalThumbnailPath() {
  38. $local_path = 'public://media-vimeo/' . intval($this->parameters['v']) . '.jpg';
  39. if (!file_exists($local_path)) {
  40. $dirname = drupal_dirname($local_path);
  41. file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  42. @copy($this->getOriginalThumbnailPath(), $local_path);
  43. }
  44. return $local_path;
  45. }
  46. }