2015-04-27 2 views
1

Привет всем Я новичок в php. Мне нужна помощь. Я анализирую и исследования, которые YouTube есть два типа видео идКак запускать видео на YouTube

1) HPEeQwbTLT8
2) ijLZ9-rlEhg

№ 1 работает хорошо в моем прокси-скрипт.

http://experiment.letwatchus.com/videos/getvideo.php?videoid=HPEeQwbTLT8&type=Download

No. 2, которые имеют дефис (-) мой PHP скрипт не может загрузить эти типы идентификаторов видео

http://experiment.letwatchus.com/videos/getvideo.php?videoid=ijLZ9-rlEhg&type=Download

если вы проверяете выше ссылка 2 ссылка не скачать но первая ссылка будет работать хорошо.

и еще один прокси-сервер хорошо управляют этими двумя идентификаторами. Этот прокси-сервер работает хорошо с выше обоих идентификаторов.

needunblock.com

Я не знаю, как они могут обработать № 2 тире идентификатор типа видео, пожалуйста, помогите мне и дать мне представление о том, что происходит.

Код файла getvideo.php выглядит следующим образом.

<?php 
include_once('config.php'); 
ob_start();// if not, some servers will show this php warning: header is already set in line 46... 

function clean($string) { 
    $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. 
    return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. 
} 

function formatBytes($bytes, $precision = 2) { 
    $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); 
    $bytes = max($bytes, 0); 
    $pow = floor(($bytes ? log($bytes) : 0)/log(1024)); 
    $pow = min($pow, count($units) - 1); 
    $bytes /= pow(1024, $pow); 
    return round($bytes, $precision) . '' . $units[$pow]; 
} 
function is_chrome(){ 
    $agent=$_SERVER['HTTP_USER_AGENT']; 
    if(preg_match("/like\sGecko\)\sChrome\//", $agent)){ // if user agent is google chrome 
     if(!strstr($agent, 'Iron')) // but not Iron 
      return true; 
    } 
    return false; // if isn't chrome return false 
} 

if(isset($_REQUEST['videoid'])) { 
    $my_id = $_REQUEST['videoid']; 
    if(strlen($my_id)>11){ 
     $url = parse_url($my_id); 
     $my_id = NULL; 
     if(is_array($url) && count($url)>0 && isset($url['query']) && !empty($url['query'])){ 
      $parts = explode('&',$url['query']); 
      if(is_array($parts) && count($parts) > 0){ 
       foreach($parts as $p){ 
        $pattern = '/^v\=/'; 
        if(preg_match($pattern, $p)){ 
         $my_id = preg_replace($pattern,'',$p); 
         break; 
        } 
       } 
      } 
      if(!$my_id){ 
       echo '<p>No video id passed in</p>'; 
       exit; 
      } 
     }else{ 
      echo '<p>Invalid url</p>'; 
      exit; 
     } 
    } 
} else { 
    echo '<p>No video id passed in</p>'; 
    exit; 
} 

if(isset($_REQUEST['type'])) { 
    $my_type = $_REQUEST['type']; 
} else { 
    $my_type = 'redirect'; 
} 

if ($my_type == 'Download') { 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 

    <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
    <style type="text/css"> 
     body { 
      padding-top: 40px; 
      padding-bottom: 40px; 
      background-color: #f5f5f5; 
    } 

    .download { 
      max-width: 300px; 
      padding: 19px 29px 29px; 
      margin: 0 auto 20px; 
      background-color: #fff; 
      border: 1px solid #e5e5e5; 
      -webkit-border-radius: 5px; 
       -moz-border-radius: 5px; 
        border-radius: 5px; 
      -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05); 
       -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05); 
        box-shadow: 0 1px 2px rgba(0,0,0,.05); 
     } 

     .download .download-heading { 
      text-align:center; 
      margin-bottom: 10px; 
     } 

     .mime, .itag { 
      width: 75px; 
     display: inline-block; 
     } 

     .itag { 
      width: 15px; 
     } 

     .size { 
      width: 20px; 
     } 

     .userscript { 
      float: right; 
      margin-top: 5px 
     } 

     #info { 
      padding: 0 0 0 130px; 
      position: relative; 
      height:100px; 
     } 

     #info img{ 
      left: 0; 
      position: absolute; 
      top: 0; 
      width:120px; 
      height:90px 
     } 
    </style> 
    </head> 
<body> 
    <div class="download"> 
<?php 
} // end of if for type=Download 

/* First get the video info page for this video id */ 
//$my_video_info = 'http://www.youtube.com/get_video_info?&video_id='. $my_id; 
$my_video_info = 'http://www.youtube.com/get_video_info?&video_id='. $my_id.'&asv=3&el=detailpage&hl=en_US'; //video details fix *1 

$my_video_info = curlGet($my_video_info); 

/* TODO: Check return from curl for status code */ 

$thumbnail_url = $title = $url_encoded_fmt_stream_map = $type = $url = ''; 

parse_str($my_video_info); 

echo '<div id="info">'; 
switch($config['ThumbnailImageMode']) 
{ 
    case 2: echo '<a href="getimage.php?videoid='. $my_id .'&sz=hd" target="_blank"><img src="getimage.php?videoid='. $my_id .'" border="0" hspace="2" vspace="2"></a>'; break; 
    case 1: echo '<a href="getimage.php?videoid='. $my_id .'&sz=hd" target="_blank"><img src="'. $thumbnail_url .'" border="0" hspace="2" vspace="2"></a>'; break; 
    case 0: default: // nothing 
} 
echo '<p>'.$title.'</p>'; 
echo '</div>'; 

$my_title = $title; 
$cleanedtitle = clean($title); 

if(isset($url_encoded_fmt_stream_map)) { 
    /* Now get the url_encoded_fmt_stream_map, and explode on comma */ 
    $my_formats_array = explode(',',$url_encoded_fmt_stream_map); 
    if($debug) { 
     echo '<pre>'; 
     print_r($my_formats_array); 
     echo '</pre>'; 
    } 
} else { 
    echo '<p>No encoded format stream found.</p>'; 
    echo '<p>Here is what we got from YouTube:</p>'; 
    echo $my_video_info; 
} 
if (count($my_formats_array) == 0) { 
    echo '<p>No format stream map found - was the video id correct?</p>'; 
    exit; 
} 

/* create an array of available download formats */ 
$avail_formats[] = ''; 
$i = 0; 
$ipbits = $ip = $itag = $sig = $quality = ''; 
$expire = time(); 

foreach($my_formats_array as $format) { 
    parse_str($format); 
    $avail_formats[$i]['itag'] = $itag; 
    $avail_formats[$i]['quality'] = $quality; 
    $type = explode(';',$type); 
    $avail_formats[$i]['type'] = $type[0]; 
    $avail_formats[$i]['url'] = urldecode($url) . '&signature=' . $sig; 
    parse_str(urldecode($url)); 
    $avail_formats[$i]['expires'] = date("G:i:s T", $expire); 
    $avail_formats[$i]['ipbits'] = $ipbits; 
    $avail_formats[$i]['ip'] = $ip; 
    $i++; 
} 

if ($debug) { 
    echo '<p>These links will expire at '. $avail_formats[0]['expires'] .'</p>'; 
    echo '<p>The server was at IP address '. $avail_formats[0]['ip'] .' which is an '. $avail_formats[0]['ipbits'] .' bit IP address. '; 
    echo 'Note that when 8 bit IP addresses are used, the download links may fail.</p>'; 
} 
if ($my_type == 'Download') { 
    echo '<p align="center">List of available formats for download:</p> 
     <ul>'; 

    /* now that we have the array, print the options */ 
    for ($i = 0; $i < count($avail_formats); $i++) { 
     echo '<li>'; 
     echo '<span class="itag">' . $avail_formats[$i]['itag'] . '</span> '; 
     if($config['VideoLinkMode']=='direct'||$config['VideoLinkMode']=='both') 
      echo '<a href="' . $avail_formats[$i]['url'] . '&title='.$cleanedtitle.'" class="mime">' . $avail_formats[$i]['type'] . '</a> '; 
     else 
      echo '<span class="mime">' . $avail_formats[$i]['type'] . '</span> '; 
     echo '<small>(' . $avail_formats[$i]['quality']; 
     if($config['VideoLinkMode']=='proxy'||$config['VideoLinkMode']=='both') 
      echo '/' . '<a href="download.php?mime=' . $avail_formats[$i]['type'] .'&title='. urlencode($my_title) .'&token='.base64_encode($avail_formats[$i]['url']) . '" class="dl">download</a>'; 
     echo ')</small> '. 
      '<small><span class="size">' . formatBytes(get_size($avail_formats[$i]['url'])) . '</span></small>'. 
     '</li>'; 
    } 
    //echo '</ul><small>Note that you initiate download either by clicking video format link or click "download" to use this server as proxy.</small>'; 

// if(($config['feature']['browserExtensions']==true)&&(is_chrome())) 
    // echo '<a href="ytdl.user.js" class="userscript btn btn-mini" title="Install chrome extension to view a \'Download\' link to this application on Youtube video pages."> Install Chrome Extension </a>'; 
?> 

</body> 
</html> 

<?php 

} else { 

/* In this else, the request didn't come from a form but from something else 
* like an RSS feed. 
* As a result, we just want to return the best format, which depends on what 
* the user provided in the url. 
* If they provided "format=best" we just use the largest. 
* If they provided "format=free" we provide the best non-flash version 
* If they provided "format=ipad" we pull the best MP4 version 
* 
* Thanks to the python based youtube-dl for info on the formats 
*        http://rg3.github.com/youtube-dl/ 
*/ 

$format = $_REQUEST['format']; 
$target_formats = ''; 
switch ($format) { 
    case "best": 
     /* largest formats first */ 
     $target_formats = array('38', '37', '46', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13'); 
     break; 
    case "free": 
     /* Here we include WebM but prefer it over FLV */ 
     $target_formats = array('38', '46', '37', '45', '22', '44', '35', '43', '34', '18', '6', '5', '17', '13'); 
     break; 
    case "ipad": 
     /* here we leave out WebM video and FLV - looking for MP4 */ 
     $target_formats = array('37','22','18','17'); 
     break; 
    default: 
     /* If they passed in a number use it */ 
     if (is_numeric($format)) { 
      $target_formats[] = $format; 
     } else { 
      $target_formats = array('38', '37', '46', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13'); 
     } 
    break; 
} 

/* Now we need to find our best format in the list of available formats */ 
$best_format = ''; 
for ($i=0; $i < count($target_formats); $i++) { 
    for ($j=0; $j < count ($avail_formats); $j++) { 
     if($target_formats[$i] == $avail_formats[$j]['itag']) { 
      //echo '<p>Target format found, it is '. $avail_formats[$j]['itag'] .'</p>'; 
      $best_format = $j; 
      break 2; 
     } 
    } 
} 

//echo '<p>Out of loop, best_format is '. $best_format .'</p>'; 
if((isset($best_format)) && 
    (isset($avail_formats[$best_format]['url'])) && 
    (isset($avail_formats[$best_format]['type'])) 
) { 
    $redirect_url = $avail_formats[$best_format]['url'].'&title='.$cleanedtitle; 
    $content_type = $avail_formats[$best_format]['type']; 
} 
if(isset($redirect_url)) { 
    header("Location: $redirect_url"); 
} 

} 
?> 

код download.php:

**

<?php 
include_once('config.php'); 
// Check download token 
if (empty($_GET['mime']) OR empty($_GET['token'])) 
{ 
    exit('Invalid download token 8{'); 
} 
// Set operation params 
$mime = filter_var($_GET['mime']); 
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/')); 
$url = base64_decode(filter_var($_GET['token'])); 
$name = urldecode($_GET['title']). '.' .$ext; 
// Fetch and serve 
if ($url) 
{ 
    $size=get_size($url); 
    // Generate the server headers 
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== TRUE) 
    { 
     header('Content-Type: "' . $mime . '"'); 
     header('Content-Disposition: attachment; filename="' . $name . '"'); 
     header('Expires: 0'); 
     header('Content-Length: '.$size); 
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
     header("Content-Transfer-Encoding: binary"); 
     header('Pragma: public'); 
    } 
    else 
    { 
     header('Content-Type: "' . $mime . '"'); 
     header('Content-Disposition: attachment; filename="' . $name . '"'); 
     header("Content-Transfer-Encoding: binary"); 
     header('Expires: 0'); 
     header('Content-Length: '.$size); 
     header('Pragma: no-cache'); 
    } 
    readfile($url); 
    exit; 
} 
// Not found 
exit('File not found 8{'); 

**

Друзья я отладки мой код и когда я ударил нет. 1 id size, но в no.2 я did'nt получить размер Я думаю, что почему 2-го типа ссылки не загружены. вот моя функция получения размера.

function get_size($url) { 
    $my_ch = curl_init(); 
    curl_setopt($my_ch, CURLOPT_URL,$url); 
    curl_setopt($my_ch, CURLOPT_HEADER,   true); 
    curl_setopt($my_ch, CURLOPT_NOBODY,   true); 
    curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($my_ch, CURLOPT_TIMEOUT,  10); 
    $r = curl_exec($my_ch); 
    foreach(explode("\n", $r) as $header) { 
     if(strpos($header, 'Content-Length:') === 0) { 
      return trim(substr($header,16)); 
     } 
    } 
    return ''; 
} 
+1

Включите некоторые из кода – Epodax

+0

ок я добавлять мой get_video.php –

+0

@Epodax я добавил мой код и я также отлаживаю его во втором типе youtube video id мой код не возвращает размер файла, я думаю, именно поэтому он не загружается –

ответ

-1
<embed width="420" height="315" 
src="http://www.youtube.com/v/wHdSkyhuocM"> 
0

PHP-пример для извлечения идентификатора видео выглядит следующим образом:

<?php 
    preg_match(
     '/[\\?\\&]v=([^\\?\\&]+)/', 
     'http://www.youtube.com/watch?v=OzHvVoUGTOM&feature=channel', 
     $matches 
    ); 
    // $matches[1] should contain the youtube id 
?> 
Смежные вопросы