MediaYouTubeStreamWrapper.inc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @file
  4. * Create a YouTube Stream Wrapper class for the Media/Resource module.
  5. */
  6. /**
  7. * Create an instance like this:
  8. * $youtube = new ResourceYouTubeStreamWrapper('youtube://?v=[video-code]');
  9. */
  10. class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
  11. protected $base_url = 'http://youtube.com/watch';
  12. function getTarget($f) {
  13. return FALSE;
  14. }
  15. static function getMimeType($uri, $mapping = NULL) {
  16. return 'video/youtube';
  17. }
  18. function getOriginalThumbnailPath() {
  19. $parts = $this->get_parameters();
  20. return 'http://img.youtube.com/vi/'. check_plain($parts['v']) .'/0.jpg';
  21. }
  22. function getLocalThumbnailPath() {
  23. $parts = $this->get_parameters();
  24. $local_path = 'public://media-youtube/' . check_plain($parts['v']) . '.jpg';
  25. if (!file_exists($local_path)) {
  26. $dirname = drupal_dirname($local_path);
  27. file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  28. @copy($this->getOriginalThumbnailPath(), $local_path);
  29. }
  30. return $local_path;
  31. }
  32. }