From 58470609a07a71507e09f2a35b9bdbfbc2d02148 Mon Sep 17 00:00:00 2001
From: andrew morton <drewish@katherinehouse.com>
Date: Fri, 23 Mar 2012 13:16:33 -0600
Subject: [PATCH 1/2] Move static functions to the top of the file.

---
 includes/MediaYouTubeStreamWrapper.inc |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/includes/MediaYouTubeStreamWrapper.inc b/includes/MediaYouTubeStreamWrapper.inc
index ad500f3..c05f683 100644
--- a/includes/MediaYouTubeStreamWrapper.inc
+++ b/includes/MediaYouTubeStreamWrapper.inc
@@ -10,16 +10,14 @@
  *  $youtube = new ResourceYouTubeStreamWrapper('youtube://?v=[video-code]');
  */
 class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
-  protected $base_url = 'http://youtube.com/watch';
+  static function getMimeType($uri, $mapping = NULL) {
+    return 'video/youtube';
+  }
 
   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';
-- 
1.7.7.4


From ba6a4f5d5fdf55f93f11d4cbbc5752e4837b307c Mon Sep 17 00:00:00 2001
From: andrew morton <drewish@katherinehouse.com>
Date: Fri, 23 Mar 2012 13:20:25 -0600
Subject: [PATCH 2/2] Make the valid_id() function static.

---
 includes/MediaInternetYouTubeHandler.inc |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/includes/MediaInternetYouTubeHandler.inc b/includes/MediaInternetYouTubeHandler.inc
index 8737938..e26af9f 100644
--- a/includes/MediaInternetYouTubeHandler.inc
+++ b/includes/MediaInternetYouTubeHandler.inc
@@ -6,6 +6,21 @@
  * @see hook_media_internet_providers().
  */
 class MediaInternetYouTubeHandler extends MediaInternetBaseHandler {
+  /**
+   * Check if a YouTube video id is valid.
+   *
+   * @return
+   *   Boolean.
+   */
+  static public function valid_id($id) {
+    $url = 'http://gdata.youtube.com/feeds/api/videos/'. $id;
+    $response = drupal_http_request($url, array('method' => 'HEAD'));
+    if ($response->code != 200) {
+      throw new MediaInternetValidationException(t('The YouTube video ID is invalid or the video was deleted.'));
+    }
+    return TRUE;
+  }
+
   public function parse($embedCode) {
     $patterns = array(
       '@youtube\.com/watch[#\?].*?v=([^"\& ]+)@i',
@@ -16,21 +31,12 @@ class MediaInternetYouTubeHandler extends MediaInternetBaseHandler {
     );
     foreach ($patterns as $pattern) {
       preg_match($pattern, $embedCode, $matches);
-      if (isset($matches[1]) && $this->valid_id($matches[1])) {
+      if (isset($matches[1]) && self::valid_id($matches[1])) {
         return file_stream_wrapper_uri_normalize('youtube://v/' . $matches[1]);
       }
     }
   }
 
-  public function valid_id($id) {
-    $url = 'http://gdata.youtube.com/feeds/api/videos/'. $id;
-    $response = drupal_http_request($url, array('method' => 'HEAD'));
-    if ($response->code != 200) {
-      throw new MediaInternetValidationException(t('The YouTube video ID is invalid or the video was deleted.'));
-    }
-    return TRUE;
-  }
-
   public function claim($embedCode) {
     if ($this->parse($embedCode)) {
       return TRUE;
-- 
1.7.7.4

