var $conn = false;
var $username = "";
var $password = "";
var $error = false;
function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
function get($url)
{
$this->conn = new Curl('youtube');
$html = $this->conn->get($url);
if(strstr($html,'verify-age-thumb'))
{
$this->error = "Adult Video Detected";
return false;
}
if(strstr($html,'das_captcha'))
{
$this->error = "Captcah Found please run on diffrent server";
return false;
}
if(!preg_match('/encoded_fmt_stream_map.*/',$html,$match))
{
$this->error = "Error Locating Download URL's";
return false;
}
$fmt_url = substr(urldecode($match[0]), 1);
$urls = explode(',',$fmt_url);
$foundArray = array();
foreach($urls as $url)
{
$url_end = strstr($url, "&quality");
// $foundArray[] = $this->GetBetween($url, "&url=", "&type=");
$foundArray[substr(strstr($url_end, "&itag="), 6)] = substr( (str_replace($url_end, "", $url)), 4 );
}
$formats = array(
'5'=>array('flv','Low Quality'),
'6'=>array('flv','Low Quality'),
'13'=>array('3gp','Low Quality'),
'17'=>array('3gp','Medium Quality'),
'18'=>array('mp4','High Quality (480p)'),
'22'=>array('mp4','High Quality (720p)'),
'34'=>array('flv','High Quality (320p)'),
'35'=>array('flv','High Quality (480p)'),
'36'=>array('3gp','High Quality'),
'37'=>array('mp4','High Quality (1080p)'),
// '43'=>array('webm',''),
// '44'=>array('webm',''),
// '45'=>array('webm',''),
);
foreach ($formats as $format => $meta) {
if (isset($foundArray[$format])) {
$videos[] = array('ext' => $meta[0], 'type' => $meta[1], 'url' => urldecode($foundArray[$format]));
}
}
return ($videos);
}
我正在解析来自 youtube(YT) 的输出,以便在我的网站上播放视频。当 YT 更改其格式时,此代码一直有效。
我不理解的关于这个片段的部分来自“foreach($urls as $url)”
我知道他正在解析从 curl 请求返回的数据。我编写了“GetBetween”fxn 来挑选一些我想象的相关代码,但它仍然返回一个空数组。
有人可以解释一下分配给“$foundArray”的内容吗?还有分配给“$videos[]”数组的内容。"$meta[0]" 和 "$meta[1]" 是指数组的第一行,即 "'5'=>array('flv','Low Quality')" 还是数组的前两行大批?
您可以提供的任何帮助将不胜感激。提前致谢