
18/11/2009, 07:34
|
| | Fecha de Ingreso: octubre-2004 Ubicación: Uruguay
Mensajes: 386
Antigüedad: 20 años, 5 meses Puntos: 4 | |
Respuesta: Expresion regular videos youtube
Código:
youtube.class.php
<?php
# YouTube PHP class
# used for embedding videos as well as video screenies on web page without single line of HTML code
#
# Dedicated to my beloved brother FILIP. Rest in peace!
#
# by Avram, www.avramovic.info
class YouTube {
function _GetVideoIdFromUrl($url) {
$parts = explode('?v=',$url);
if (count($parts) == 2) {
$tmp = explode('&',$parts[1]);
if (count($tmp)>1) {
return $tmp[0];
} else {
return $parts[1];
}
} else {
return $url;
}
}
function EmbedVideo($videoid,$width = 425,$height = 350) {
$videoid = $this->_GetVideoIdFromUrl($videoid);
return '<object width="'.$width.'" height="'.$height.'"><param name="movie" value="http://www.youtube.com/v/'.$videoid.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$videoid.'" type="application/x-shockwave-flash" wmode="transparent" width="'.$width.'" height="'.$height.'"></embed></object>';
}
function GetImg($videoid,$imgid = 1) {
$videoid = $this->_GetVideoIdFromUrl($videoid);
return "http://img.youtube.com/vi/$videoid/$imgid.jpg";
}
function ShowImg($videoid,$imgid = 1,$alt = 'Video screenshot') {
return "<img src='".$this->GetImg($videoid,$imgid)."' width='130' height='97' border='0' alt='".$alt."' title='".$alt."' />";
}
}
?>
tester.php
Código:
include "youtube.class.php";
$video="http://www.youtube.com/watch?v=dBoMvJM2tIY";
$jutjub = new YouTube();
$imagen1= $jutjub->GetImg($video,2);
$ch = curl_init($imagen1);
if ($ch){
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html = htmlentities(curl_exec($ch));
$info= curl_getinfo($ch);
curl_close($ch);
if ($info['content_type'] != "image/jpeg")
{$error="yes"; }
} else { $error="yes";}
?><? if ($error!="yes") { ?><?=$jutjub->GetImg($video,2);?><?=$jutjub->GetImg($video,2);?>
<? echo $jutjub->EmbedVideo($video,550,350);?>
<? } ?>
|