youtube get_video无效

Gan*_*yak 2 youtube safari

我用http://www.youtube.com/get_video?video_id=ID&t=SIGNATURE&fmt=18替换了

ID和SIGNATURE具有适当的值.但我没有看到任何保存或下载窗口,

而是一个空白的窗口.

我在Safari平台上使用Safari浏览器.帮助感谢.

Cru*_*uel 16

获取YouTube视频信息的最简单方法是从中获取信息 http://youtube.com/get_video_info?video_id=XXXXXXXX

我将使用PHP作为处理此数据的示例.使用PHP的parse_str(),您可以将字符串的所有变量分配给一个很好的视频信息数组:

$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$id);
parse_str($content, $ytarr);
Run Code Online (Sandbox Code Playgroud)

然后所有信息都存储在$ ytarr中.感兴趣的变量是"fmt_list"和"fmt_map"(它似乎包含相同的东西).此变量包含根据此处图表提供的可用视频格式列表:http://en.wikipedia.org/wiki/Youtube#Quality_and_codecs

假设您知道要下载哪种格式,则可以使用"fmt_url_map"变量(或此示例中的$ ytarr ['fmt_url_map'])来访问指向所需格式的链接列表.

您可以使用这些链接下载任何格式的视频,但它们受youtube有限的带宽限制(youtube用于节省带宽的最佳流速)因此下载速度不会像您想象的那么快.这让我相信这些链接最适合用于流式传输而不是下载,但我不知道任何替代方案.


Ars*_*tze 6

互联网上充满了不工作的例子,所以这里有一个脚本供任何需要的人使用.flv文件有问题.他们的链接提供.txt文件,但它对webm和mp4很好.我需要那些pr0n网站太hehehe

<?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 '</pre>';
    }
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);

for($i=0; $i<count($files); $i++)
    {
    $file = urldecode($files[$i]);
    $found = strpos($file, $type) > -1;

    if ($debug)
        {
        if ($found) 
            echo '[THIS]';
        echo '<a href="'.$file.'">'.$file.'</a><br/><br/>';
        }
    else
        {
        if ($found) 
            {
            $file = explode('; codecs=', $file);
            @readfile($file[0]);
            break;
            }
        }   
    }
?>  
Run Code Online (Sandbox Code Playgroud)