From: Alan Jack Pippin Date: Fri, 29 Jun 2007 03:58:50 +0000 (-0600) Subject: Added support for yahoo video and metacafe.com X-Git-Tag: 1_0_4~6 X-Git-Url: http://git.pippins.net/embedvideo/static/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/%7Bupdate_month%7D?a=commitdiff_plain;h=f61667e91c20c89758911f384ec30ff9f92c49e1;p=embedvideo%2F.git Added support for yahoo video and metacafe.com --- diff --git a/ItemAddEmbedVideo.inc b/ItemAddEmbedVideo.inc index b8941f6..e5eecd1 100644 --- a/ItemAddEmbedVideo.inc +++ b/ItemAddEmbedVideo.inc @@ -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.= ''; $description.= "
$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>/', $contents, $matches); + $summary=$matches[1]; + + /* Extract the title from the webpage contents */ + $title="Unknown"; + if(preg_match('/(.+?)\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("/"/","'",$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>"; diff --git a/templates/ItemAddEmbedVideo.tpl b/templates/ItemAddEmbedVideo.tpl index 5aaaf3c..7f10a0f 100644 --- a/templates/ItemAddEmbedVideo.tpl +++ b/templates/ItemAddEmbedVideo.tpl @@ -20,8 +20,10 @@ <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>