index.php
<?php
if(isset($_POST['submit']))
{
$url = $_POST['down'];
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Youtube Video Details Class Example</title>
<style type="text/css">
body{ background-color: #FBFBFB; font-family: Arial; font-size: 12px; color: #333; line-height: 20px; }
.box { background-color: #fff; border: 1px solid #e2e2e2; width: 730px; padding: 10px; margin: 0px auto;}
</style>
</head>
<body>
<div class="box">
<form action="" method="post">
<input value="<? echo $url; ?>" autocomplete="off" id="ind" type="text" name="down" style="float:left;height:50px;width:800px;border:2px solid #06bfea;font-size:20px;padding-left:10px;">
<input type="submit" id="mb" style="background:#06bfea;
margin-left:-1px;
font-weight:700;
font-size:15px;
width:150px;
height:56px;
color:#fff;
text-shadow:0 1px 0 #338bb1;
cursor:pointer;
-webkit-box-shadow:0 2px 5px #c5dfea;
-moz-box-shadow:0 2px 5px #c5dfea;
-moz-border-radius:0 3px 3px 0;
-webkit-border-radius:0 3px 3px 0;
-khtml-border-radius:0 3px 3px 0;
border-radius:0 3px 3px 0;
padding:7px 14px;" name="submit" value="GO !" />
</form>
<? if($url){
?>
<?php
include('curl.php');
include('youtube.php');
$tube = new youtube();
$links = $tube->get('http://www.youtube.com/watch?v='.$my_array_of_vars['v']);
if($links) {
$x = 0;
foreach($links as $key){
echo '<a href="'.$links[$x]['url'].'">'.$links[$x]['ext'].' '.$links[$x]['type'].'</a><br>';
$x = $x + 1;
}
}
} else {
echo $tube->error;
}
?>
</div>
</body>
</html>
curl.php
<?php
class Curl {
var $callback = false;
var $secure = false;
var $conn = false;
function Curl($u = false) {
$this->conn = curl_init();
}
function doRequest($method, $url, $vars) {
$ch = $this->conn;
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_URL, $url);
if ($this->header) {
curl_setopt($ch, CURLOPT_HEADER, 1);
} else {
curl_setopt($ch, CURLOPT_HEADER, 0);
}
curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if ($data) {
if ($this->callback)
{
$callback = $this->callback;
$this->callback = false;
return call_user_func($callback, $data);
} else {
return $data;
}
} else {
return false;
}
}
function get($url) {
return $this->doRequest('GET', $url, 'NULL');
}
}
?>
и файл youtube.php
<?php
class youtube {
var $conn = false;
var $username = "";
var $password = "";
var $error = false;
function get($url)
{
$this->conn = new Curl('youtube');
$html = $this->conn->get($url);
if(!preg_match('/stream_map=(.[^&]*?)&/i',$html,$match))
{
$this->error = "Error Locating Downlod URL's";
return false;
}
if(!preg_match('/stream_map=(.[^&]*?)(?:\\\\|&)/i',$html,$match))
{
return false;
}
$fmt_url = urldecode($match[1]);
$urls = explode(',',$fmt_url);
$foundArray = array();
foreach($urls as $url)
{
if(preg_match('/itag=([0-9]+)/',$url,$tm) && preg_match('/sig=(.*?)&/', $url , $si) && preg_match('/url=(.*?)&/', $url , $um))
{
$u = urldecode($um[1]);
$foundArray[$tm[1]] = $u.'&signature='.$si[1];
}
}
$typeMap = array();
$typeMap[13] = array("13", "3GP", "176x144");
$typeMap[17] = array("17", "3GP", "176x144");
$typeMap[36] = array("36", "3GP", "320x240");
$typeMap[5] = array("5", "FLV", "400x226");
$typeMap[6] = array("6", "FLV", "640x360");
$typeMap[34] = array("34", "FLV", "640x360");
$typeMap[35] = array("35", "FLV", "854x480");
$typeMap[43] = array("43", "WEBM", "640x360");
$typeMap[44] = array("44", "WEBM", "854x480");
$typeMap[45] = array("45", "WEBM", "1280x720");
$typeMap[18] = array("18", "MP4", "480x360");
$typeMap[22] = array("22", "MP4", "1280x720");
$typeMap[37] = array("37", "MP4", "1920x1080");
$typeMap[33] = array("38", "MP4", "4096x230");
$videos = array();
foreach($typeMap as $format => $meta) {
if (isset($foundArray[$format])) {
$videos[] = array('ext' => strtolower($meta[1]) , 'type' => $meta[2], 'url' => $foundArray[$format]);
}
}
if(empty($videos)){$this->get($url);}else{return $videos;}
}
}
так вот в чём проблема вбейте туда ссылку http://www.youtube.com/watch?v=c23ttMF8ZAU он выведет ссылки! иногда выведет иногда возвращает пустой массив! вот я не понимаю почему иногда пустой возвращает что делать что и как дописать? Надеюсь знатоки помогут!