MediaArchiveStreamWrapper.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * Create a Archive Stream Wrapper class for the Media/Resource module.
  5. */
  6. /**
  7. * Create an instance like this:
  8. * $archive = new ResourceArchiveStreamWrapper('archive://?v=[video-code]');
  9. */
  10. class MediaArchiveStreamWrapper extends MediaReadOnlyStreamWrapper {
  11. protected $base_url = 'http://archive.org/file';
  12. function getTarget($f) {
  13. return FALSE;
  14. }
  15. static function getMimeType($uri, $mapping = NULL) {
  16. return 'video/archive';
  17. }
  18. function getOriginalThumbnailPath() {
  19. $parts = $this->get_parameters();
  20. return 'http://www.archive.org/download/'. check_plain($parts['v']) .'/' . check_plain($parts['v']) .'.thumbs/' . check_plain($parts['org']) .'_000001.jpg';
  21. }
  22. function getLocalThumbnailPath() {
  23. $parts = $this->get_parameters();
  24. $local_path = 'public://media-archive/' . 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. }