Skip to content

Commit

Permalink
adding media_youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
acarlton committed Jan 31, 2012
1 parent 2b7b3d4 commit 8c07775
Show file tree
Hide file tree
Showing 21 changed files with 1,878 additions and 0 deletions.
47 changes: 47 additions & 0 deletions drupal/sites/all/modules/contrib/media_youtube/CHANGELOG.txt
@@ -0,0 +1,47 @@

Changelog for the Media: YouTube module.
========================================

by aaron: Add overlay to media browser library thumbnails.
by aaron: Begin framework for pager support.
by aaron: Add an empty message.
by aaron: Remove old tab from browser.
by aaron: Begin work on adding 'All/My Youtubes' vertical tabs.
by aaron: Add 'YouTube Library' tab to browser w/ all youtube videos.
by aaron: Allow parsing of url's like youtube.com/watch#v=...
by aaron: Fix incorrect parse to youtube from flickr.
by aaron: Implement hook_media_parse().
by aaron: Remove link behavior for the moment.
by aaron: Change tab behavior to new required format.
by aaron: Allow w/h overrides.
by aaron: Add wysiwyg tab for youtube url.
by aaron: Add style presets for youtube.
by aaron: Add action link to add youtube video from media content admin.
by aaron: Add alt/title to embed thumbnails theme.
by aaron: Refactor styles containers to match new API.
by aaron: Add preview on parsing new youtube.
by aaron: Add media_youtube.js.
by aaron: Add a weight to style containers.
by aaron: Add JS behavior to url text field.
by aaron: Browse user + all youtube videos.
by aaron: New themes for styles.
by aaron: Begin browser forms for YouTube.
by aaron: Embed themes & style callbacks.
by aaron: Define filter callbacks.
by aaron: Fix return value for hook_styles_presets().
by aaron: Implement hook_styles_presets().
by aaron: Add variables to preview theme.
by aaron: Integrate with Styles.
by aaron: Add preview theme.
by aaron: Add test default media styles.
by aaron: Parse URL correctly.
by aaron: Register the stream wrapper.
by aaron: Include stream wrapper w/ module load.
by aaron: Rename stream wrapper implementation to MediaYouTubeStreamWrapper.
by aaron: Upgrade module to DRUPAL-7.

=============
DRUPAL-7--1
=============

by aaron: Create ResourceYouTubeStreamWrapper.inc.
339 changes: 339 additions & 0 deletions drupal/sites/all/modules/contrib/media_youtube/LICENSE.txt

Large diffs are not rendered by default.

@@ -0,0 +1,8 @@
<?php

/**
* @todo Remove once usage statistics indicate that virtually everyone has
* updated to 1.0-alpha5 or later. This is retained until then, so that
* update.php can bootstrap.
*/
include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'media_youtube') . '/includes/includes/MediaYouTubeStreamWrapper.inc';
5 changes: 5 additions & 0 deletions drupal/sites/all/modules/contrib/media_youtube/README.txt
@@ -0,0 +1,5 @@

Media: YouTube

Creates a YouTube PHP Stream Wrapper for Resource and implements the various
formatter and file listing hooks in the Media module.
@@ -0,0 +1,21 @@

.media-youtube-preview-wrapper {
max-width: 100%;
min-height: 50px;
position: relative;
}

.media-youtube-preview-wrapper object,
.media-youtube-preview-wrapper iframe {
max-width: 100%;
position: relative;
}

.media-youtube-preview-wrapper .js-fallback {
left: 0;
margin-top: -0.5em;
position: absolute;
right: 0;
text-align: center;
top: 50%;
}
@@ -0,0 +1,30 @@

/**
* @file
* Overlay for YouTube thumbnails in the media library browser.
*/
#media-browser .styles-container-media_youtube {
/* Relative wrapper for the overlay. */
position: relative;
}
#media-browser .styles-container-media_youtube span {
/* Here's the overlay image. */
background: url(images/stream-youtube.png) no-repeat;

/* Absolute positioning in the relative wrapper creates the overlay. */
position: absolute;

/* Size of the overlay */
width: 69px;
height: 22px;

/* Position of the overlay */
left: 33px;
top: 80px;
}
#media-browser .styles-container-media_youtube span:hover {
/* The */
background-position: 0px -22px;
}
#media-browser .styles-container-media_youtube img {
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,84 @@
<?php

/**
* Implementation of MediaInternetBaseHandler.
*
* @see hook_media_internet_providers().
*/
class MediaInternetYouTubeHandler extends MediaInternetBaseHandler {
public function parse($embedCode) {
$patterns = array(
'@youtube\.com/watch[#\?]v=([^"\& ]+)@i',
'@youtube\.com/embed/([^"\&\? ]+)@i',
'@youtube\.com/v/([^"\&\? ]+)@i',
'@youtube\.com/\?v=([^"\& ]+)@i',
'@youtu.be/([^"\&\? ]+)@i',
);
foreach ($patterns as $pattern) {
preg_match($pattern, $embedCode, $matches);
if (isset($matches[1])) {
return file_stream_wrapper_uri_normalize('youtube://v/' . $matches[1]);
}
}
}

public function claim($embedCode) {
if ($this->parse($embedCode)) {
return TRUE;
}
}

public function save() {
$file = $this->getFileObject();
// If a user enters a duplicate YouTube URL, the object will be saved again.
// Set the timestamp to the current time, so that the media item shows up
// at the top of the media library, where they would expect to see it.
$file->timestamp = REQUEST_TIME;
file_save($file);
return $file;
}

public function getFileObject() {
$uri = $this->parse($this->embedCode);
return file_uri_to_object($uri, TRUE);
}

/**
* Returns information about the media. See http://video.search.yahoo.com/mrss.
*
* @return
* If ATOM+MRSS information is available, a SimpleXML element containing
* ATOM and MRSS elements, as per those respective specifications.
*
* @todo Would be better for the return value to be an array rather than a
* SimpleXML element, but media_retrieve_xml() needs to be upgraded to
* handle namespaces first.
*/
public function getMRSS() {
$uri = $this->parse($this->embedCode);
$video_id = arg(1, file_uri_target($uri));
$rss_url = url('http://gdata.youtube.com/feeds/api/videos/' . $video_id, array('query' => array('v' => '2')));
// @todo Use media_retrieve_xml() once it's upgraded to include elements
// from all namespaces, not just the document default namespace.
$entry = simplexml_load_file($rss_url);
return $entry;
}

/**
* Returns information about the media. See http://www.oembed.com/.
*
* @return
* If oEmbed information is available, an array containing 'title', 'type',
* 'url', and other information as specified by the oEmbed standard.
* Otherwise, NULL.
*/
public function getOEmbed() {
$uri = $this->parse($this->embedCode);
$external_url = drupal_realpath($uri);
$oembed_url = url('http://www.youtube.com/oembed', array('query' => array('url' => $external_url, 'format' => 'json')));
$response = drupal_http_request($oembed_url);
if (!isset($response->error)) {
return drupal_json_decode($response->data);
}
}
}
@@ -0,0 +1,38 @@
<?php

/**
* @file
* Create a YouTube Stream Wrapper class for the Media/Resource module.
*/

/**
* Create an instance like this:
* $youtube = new ResourceYouTubeStreamWrapper('youtube://?v=[video-code]');
*/
class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
protected $base_url = 'http://youtube.com/watch';

function getTarget($f) {
return FALSE;
}

static function getMimeType($uri, $mapping = NULL) {
return 'video/youtube';
}

function getOriginalThumbnailPath() {
$parts = $this->get_parameters();
return 'http://img.youtube.com/vi/'. check_plain($parts['v']) .'/0.jpg';
}

function getLocalThumbnailPath() {
$parts = $this->get_parameters();
$local_path = 'public://media-youtube/' . check_plain($parts['v']) . '.jpg';
if (!file_exists($local_path)) {
$dirname = drupal_dirname($local_path);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
@copy($this->getOriginalThumbnailPath(), $local_path);
}
return $local_path;
}
}
@@ -0,0 +1,45 @@
<?php

/**
* @file
* Styles class implementation for Media: YouTube.
*/

class MediaYouTubeStyles extends FileStyles {
public $autoplay;
public $fullscreen;

function getAutoplay() {
return $this->get('autoplay');
}
function setAutoplay($value) {
return $this->set('autoplay', $value);
}
function getFullscreen() {
return $this->get('fullscreen');
}
function setFullscreen($value) {
return $this->set('fullscreen', $value);
}

function getImageUri() {
if ($image_uri = $this->get('imageUri')) {
return $image_uri;
}
$object = $this->getObject();
if ($object->uri) {
$wrapper = file_stream_wrapper_get_instance_by_uri($object->uri);
return $wrapper->getLocalThumbnailPath();
}
}
function video($effect) {
$variables = array(
'uri' => $this->getUri(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'autoplay' => $this->getAutoplay(),
'fullscreen' => $this->getFullscreen(),
);
$this->setOutput(theme('media_youtube_video', $variables));
}
}

0 comments on commit 8c07775

Please sign in to comment.