Как изменить этот скрипт, чтобы получить только версию файла mp4 с YouTube, зная идентификатор YouTube? - PullRequest
0 голосов
/ 04 марта 2012

Как это сделать, чтобы получить только URL версии файла mp4?

<code><?php

//$debug = true;

if(empty($debug))
    $debug = false;

if(empty($_GET['id']))
    die('no id');
if(!preg_match('/^[A-Z0-9-_]+$/i', $_GET['id']))
    die('invalid character in id');
else
    $id = $_GET['id'];

if(empty($_GET['type']))
    $type = 'mp4';
else
if(!preg_match('/^[A-Z]+$/i', $_GET['type']))
    die('invalid character in type');
else
    $type = strtolower($_GET['type']);


$url = 'http://youtube.com/get_video_info?video_id=';
$key = 'url_encoded_fmt_stream_map';
$content = file_get_contents($url.$id);
parse_str($content, $result);

if($debug)
    {
    echo $url.$id.'<br/>';
    echo $key.'<br/>';
    echo $type.'<br/>';
    echo '<pre>';
    print_r($result);
    echo '
'; } еще { заголовок ('Content-Type: application / octet-stream'); header ('Content-Disposition: attachment; filename = "videofile.'. $ type. '"'); } $ type = 'type = video /'.$ type; $ files = explode (', url =', $ result [$ key]); $ files [0] = substr ($ files [0], 4); для ($ i = 0; $ i -1; if ($ debug) { если ($ найдено) echo '[THIS]'; echo ''. $ file. '

'; } еще { если ($ найдено) { $ file = explode ('; codecs =', $ file); @readfile ($ файл [0]); перерыв; } } } ?>

Ответы [ 2 ]

2 голосов
/ 04 марта 2012

Эти 3 ссылки являются всеми ссылками mp4 с разными идентификаторами (в конце).Итаги бывают разных HD / нормальных форматов для разрешения экрана гугл их.Однако, если вы хотите приземлиться сейчас, сохраните это:

<code><?php

$debug = true;

if(empty($debug))
    $debug = false;

if(empty($_GET['id']))
    die('no id');
if(!preg_match('/^[A-Z0-9-_]+$/i', $_GET['id']))
    die('invalid character in id');
else
    $id = $_GET['id'];

if(empty($_GET['type']))
    $type = 'mp4';
else
if(!preg_match('/^[A-Z]+$/i', $_GET['type']))
    die('invalid character in type');
else
    $type = strtolower($_GET['type']);


$url = 'http://youtube.com/get_video_info?video_id=';
$key = 'url_encoded_fmt_stream_map';
$content = file_get_contents($url.$id);
parse_str($content, $result);

/*if($debug)
    {
    echo $url.$id.'<br/>';
    echo $key.'<br/>';
    echo $type.'<br/>';
    echo '<pre>';
    print_r($result);
    echo '
';} else {header ('Content-Type: application / octet-stream');header ('Content-Disposition: attachment; filename = "videofile.'. $ type. '"');} * / $ type = 'type = video /'.$ type;$ files = explode (', url =', $ result [$ key]);$ files [0] = substr ($ files [0], 4);для ($ i = 0; $ i-1;$ itag = strpos ($ file, "itag = 18")> -1;if ($ found & $ itag) {echo ''. $ file. '«;}}?>
2 голосов
/ 04 марта 2012
<code><?php

$debug = true;

if(empty($debug))
    $debug = false;

if(empty($_GET['id']))
    die('no id');
if(!preg_match('/^[A-Z0-9-_]+$/i', $_GET['id']))
    die('invalid character in id');
else
    $id = $_GET['id'];

if(empty($_GET['type']))
    $type = 'mp4';
else
if(!preg_match('/^[A-Z]+$/i', $_GET['type']))
    die('invalid character in type');
else
    $type = strtolower($_GET['type']);


$url = 'http://youtube.com/get_video_info?video_id=';
$key = 'url_encoded_fmt_stream_map';
$content = file_get_contents($url.$id);
parse_str($content, $result);

/*if($debug)
    {
    echo $url.$id.'<br/>';
    echo $key.'<br/>';
    echo $type.'<br/>';
    echo '<pre>';
    print_r($result);
    echo '
'; } еще { заголовок ('Content-Type: application / octet-stream'); header ('Content-Disposition: attachment; filename = "videofile.'. $ type. '"'); } * / $ type = 'type = video /'.$ type; $ files = explode (', url =', $ result [$ key]); $ files [0] = substr ($ files [0], 4); для ($ i = 0; $ i -1; if ($ found) { echo ''. $ file. '

'; } } ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...