Added support for yahoo video and metacafe.com
authorAlan Jack Pippin <ajp@pippin.(none)>
Fri, 29 Jun 2007 03:58:50 +0000 (21:58 -0600)
committerAlan J. Pippin <ajp@pippins.net>
Fri, 29 Jun 2007 03:58:50 +0000 (21:58 -0600)
ItemAddEmbedVideo.inc
templates/ItemAddEmbedVideo.tpl

index b8941f60e09fcc5409f20bec9ea527629f35eea1..e5eecd1552acde47caac0a76b47401ee4c5086a8 100644 (file)
@@ -78,10 +78,22 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
           $flvThumbnail = $this->getParameter($ItemAddEmbedVideo, 'flvThumbnail');
 
           /* Store other string constants we'll use later */
+         
+          /* youtube */
           $youtubeUrlPattern="youtube.com";
           $youtubeApiUrl="http://www.youtube.com/api2_rest";
+
+          /* google */
           $googleUrlPattern="video.google.com";
           $googlePlayer="http://video.google.com/googleplayer.swf";
+
+          /* yahoo */
+          $yahooUrlPattern="video.yahoo.com";
+          $yahooThumbnailUrl="http://thmg01.video.search.yahoo.com/image/";
+          
+          /* metacafe */
+          $metacafeUrlPattern="metacafe.com";
+          $metacafeThumbnailUrl="http://www.metacafe.com/thumb/";
           
           /* Gallery2 specific paths and variables */
           $urlGenerator =& $gallery->getUrlGenerator();
@@ -210,6 +222,94 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
               $description.= 'src="'.$googlePlayer.'?docId='.$doc_id.'"> ';
               $description.= '</embed>';
               $description.= "<br>$summary";
+
+          /*
+           **********************************
+           * Embed a Yahoo Video
+           **********************************
+            */
+          } else if(preg_match("/$yahooUrlPattern/",$url)) {
+
+              /* Make sure we can extract a vidID */
+              if(preg_match("/vid=(.*)/",$url,$matches)) {
+                  $vid_id = $matches[1];
+              } else {
+                  return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+                               "Unable to extract vid id from url: $url"),null,null);
+              }
+
+              /* Grab the contents of the webpage used to display the video on video.google.com */
+              list ($successfullyCopied, $contents, $response, $headers) =
+                GalleryCoreApi::fetchWebPage($url, $extraHeaders);
+              if (!$successfullyCopied) {
+                  return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+                               "Unable to get video information at url: $url - $response"),NULL,NULL);
+              }
+
+              /* Extract the summary from the webpage contents */
+              preg_match('/Description:<\/em><p>(.+?)<\/p>/', $contents, $matches);
+              $summary=$matches[1];
+
+              /* Extract the title from the webpage contents */
+              $title="Unknown";
+              if(preg_match('/<title>(.+?)\s+- Yahoo! Video<\/title>/i', $contents, $matches)) {
+                $title=$matches[1];
+              } else if(preg_match('/<title>(.+?)<\/title>/i', $contents, $matches)) {
+                $title=$matches[1];
+              }
+
+              /* Build the thumbnail URL from the vid_id */
+              $thumbnail=$yahooThumbnailUrl.$vid_id."_01";
+
+              /* Format the description to hold a reference to the embedded video */
+              preg_match('/(<embed src.+?<\/embed>)/', $contents, $matches);
+              $description=$matches[1];
+              $description=preg_replace("/width='\d+'/","width='".$width."'",$description);
+              $description=preg_replace("/height='\d+'/","height='".$height."'",$description);        
+              $description.= "<br>$summary";
+
+          /*
+           **********************************
+           * Embed a MetaCafe Video
+           **********************************
+            */
+          } else if(preg_match("/$metacafeUrlPattern/",$url)) {
+
+              /* Make sure we can extract a itemID */
+              if(preg_match("/\/watch\/(.+?)\/(.+?)/",$url,$matches)) {
+                  $item_id = $matches[1];
+              } else {
+                  return array(GalleryCoreApi::error(ERROR_BAD_PARAMETER,__FILE__,__LINE__,
+                               "Unable to extract item id from url: $url"),null,null);
+              }
+
+              /* Grab the contents of the webpage used to display the video on video.google.com */
+              list ($successfullyCopied, $contents, $response, $headers) =
+                GalleryCoreApi::fetchWebPage($url, $extraHeaders);
+              if (!$successfullyCopied) {
+                  return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+                               "Unable to get video information at url: $url - $response"),NULL,NULL);
+              }
+
+              /* Extract the summary from the webpage contents */
+              preg_match('/<meta name="description" content="(.+?)" \/>/i', $contents, $matches);
+              $summary=$matches[1];
+
+              /* Extract the title from the webpage contents */
+              preg_match('/<title>(.+?)<\/title>/i', $contents, $matches);
+              $title=$matches[1];
+              
+              /* Build the thumbnail URL from the item_id */
+              $thumbnail=$metacafeThumbnailUrl.$item_id.".jpg";
+
+              /* Format the description to hold a reference to the embedded video */
+              preg_match('/(embed src.+?\/embed)/', $contents, $matches);
+              $description="<".$matches[1];
+              $description=preg_replace("/&quot;/","'",$description);
+              $description=preg_replace("/width='\d+'/","width='".$width."'",$description);
+              $description=preg_replace("/height='\d+'/","height='".$height."'",$description);
+              $description.= "</embed>";
+              $description.= "<br>$summary";
         
           /*
            **********************************
@@ -366,6 +466,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
           
           /* General debug output */
           if(!strcmp($debugOutput,"true")) {
+              print "title: $title <br>";
               print "<p><a href=\"".$title."\" target=\"_blank\">";
               print "<img src=\"".$thumbnail."\">\n</a>".$summary."</p>";
               print "<p>$description</p>";
index 5aaaf3c3b587295549b60d4e83a48ab006c33c64..7f10a0f2efd9b8b122928c3362ba4d846fd4101e 100644 (file)
 
     <br> 
     <b><u>Supported Video Sites:</u></b> <br>
-    <b>YouTube:</b> http://video.google.com/videoplay?docid=xxxxxxxxxxx<br>
-    <b>GoogleVideo:</b> http://www.youtube.com/watch?v=xxxxxxxxxxx<br>
+    <b>YouTube:</b> http://www.youtube.com/watch?v=xxxxxxxxxxx<br>
+    <b>GoogleVideo:</b> http://video.google.com/videoplay?docid=xxxxxxxxxxx<br>
+    <b>YahooVideo:</b> http://video.yahoo.com/video/play?vid=xxxxxx<br>
+    <b>Metacafe:</b> http://www.metacafe.com/watch/xxxxxx/xxxxxx<br>
     <br>
     <b><u>Supported File Types:</u></b><br>
     <b>FlashVideo (.flv):</b> http://aaa.bbb.ccc/video.flv<br>