Supports youtube https now directly.

This commit is contained in:
Grischa Brockhaus 2011-12-20 12:12:21 +01:00
parent 212047df90
commit f01953cf7c
3 changed files with 4 additions and 89 deletions

View file

@ -3,7 +3,8 @@ Version 1.01 (brockhaus)
* Added "generic providers" embed.ly and oohembed.com.
* Removed the depending definitions in providers.xml
* New providers via noembed: GitHub Commit, GitHub Gist and Beer Advocate (Yeah!) ;D
* Reverted Smarty Security Disabling (tested with 1.6/1.7 blogs
* Reverted Smarty Security Disabling (tested with 1.6/1.7 blogs)
* Supports youtube https now directly.
Version 1.00 (brockhaus)
-----------------------

View file

@ -1,80 +0,0 @@
<?php
class YouTubeProvider extends EmbedProvider {
public function match($url){
return preg_match('/youtube.com\/watch\?v=([\w-]+)/',$url) || preg_match('/youtu.be\/([\w-]+)/',$url); // http://youtu.be/8UVNT4wvIGY
}
public function getEmbed($url){
$urlArray=array();
if(preg_match("/(www.)?youtube.com\/watch\?v=([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
else if(preg_match("/(www.)?youtu.be\/([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
$myEmbed = new VideoEmbed();
$myEmbed->type='video';
$myEmbed->version='1.0';
$myEmbed->provider_name="Youtube";
$myEmbed->provider_url="http://youtube.com";
$myEmbed->resource_url=$url;
$xml = new DOMDocument;
if(@($xml->load('http://gdata.youtube.com/feeds/api/videos/'.$video_id))) {
@$guid = $xml->getElementsByTagName("guid")->item(0)->nodeValue;
$link = str_replace("http://www.youtube.com/watch?v=","http://bergengocia.net/indavideobombyoutubemashup/view.php?id=",$guid);
$myEmbed->title =$xml->getElementsByTagName("title")->item(0)->nodeValue;
$myEmbed->description =$xml->getElementsByTagNameNS("*","description")->item(0)->nodeValue;
$myEmbed->author_name =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("name")->item(0)->nodeValue;
$myEmbed->author_url =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("uri")->item(0)->nodeValue;
$myEmbed->thumbnail_url =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("url");
$myEmbed->thumbnail_width =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("width");
$myEmbed->thumbnail_height =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("height");
$med_content_url=$xml->getElementsByTagNameNS("http://search.yahoo.com/mrss/","content")->item(0)->getAttribute("url");
$myEmbed->html=
'<object width="425" height="350">'."\n".
' <param name="movie" value="'.$med_content_url.'"></param>'."\n".
' <embed src="'.$med_content_url.'"'.
' type="application/x-shockwave-flash" width="425" height="350">'."\n".
' </embed>'."\n".
'</object>'; // according to http://code.google.com/apis/youtube/developers_guide_protocol.html#Displaying_information_about_a_video
$myEmbed->width="425";
$myEmbed->height="350"; // same as in the html
//$myEmbed->duration=$xml->getElementsByTagNameNS($xml->lookupNamespaceURI("*"),"content")->item(0)->getAttribute("duration");
//$time = floor($duration / 60) . ":" . $duration % 60;
return $myEmbed;
} else throw new Exception404("xxx");
}
private function provideXML($url){
$string="";
foreach($this->getEmbed($url) as $key=>$value){
if(isset($value)&& $value!="") $string.=" <".$key.">".$value."</".$key.">\n";
}
$string="<oembed>\n".$string."</oembed>";
return $string;
}
private function provideObject($url){
return $this->getEmbed($url);
}
private function provideJSON($url){
return json_encode($this->getEmbed($url));
}
private function provideSerialized($url){
return serialize($this->getEmbed($url));
}
public function provide($url,$format="json"){
if($format=="xml"){
return $this->provideXML($url);
} else if ($format=="object"){
return $this->provideObject($url);
} else if ($format=="serialized"){
return $this->provideSerialized($url);
} else {
return $this->provideJSON($url);;
}
}
public function __construct($config,$maxwidth=null, $maxheight=null){
parent::__construct("http://youtube.com","", $maxwidth, $maxheight);
}
}

View file

@ -20,20 +20,14 @@
<url>http://*.vimeo.com/*</url>
<endpoint>http://vimeo.com/api/oembed.{format}</endpoint>
</provider>
<!--
<provider>
<url>http://*.youtube.*/*</url>
<class>YouTubeProvider</class>
</provider>
-->
<provider>
<name>Youtube</name>
<url>http://*.youtube.com/*</url>
<url>https?://*.youtube.com/*</url>
<endpoint>http://www.youtube.com/oembed</endpoint>
</provider>
<provider>
<name>Youtube short link</name>
<url>http://*.youtu.be/*</url>
<url>https?://*.youtu.be/*</url>
<endpoint>http://www.youtube.com/oembed</endpoint>
</provider>
<provider>