最近、YouTube はビデオの直接ダウンロード リンクの動作方法を変更しました (url_encoded_fmt_stream_map にあります)。現在は署名があり、適切な署名が提示されない限りリンクは機能しません。署名は「sig」引数として存在するため、簡単に取得できます。リンクを構築すると機能しますが、この署名が表示されて以来、リンクは何らかの形でユーザーのブラウザにもロックされています
つまり、サーバー側で「http://youtube.com/get_video_info」を調べて署名付きのリンクを作成し、ユーザーがリンクをクリックしたときにそれをリンクとして印刷すると、黒いページが開きますが、しようとするとサーバー側でビデオをダウンロードすると動作します。これは、リンクが何らかの理由でロックされており、「http://youtube.com/get_video_info」を開いたユーザーのものであることを意味します。
この状況の問題点は、ビデオをストリーミングするには、最初にサーバーにダウンロードする必要があることです。
リンクが特定のユーザーにロックされている方法を知っている人はいますか?それを回避する方法はありますか?
アイデアは、たとえば、サーバー側でリンクを取得し、クロムレスプレーヤーを使用する代わりに、それをフラッシュプレーヤーにフィードします
以下は、php を使用したコード例です。
<?
$video_id = $_GET['id']; //youtube video id
// geting the video info
$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$video_id);
parse_str($content, $ytarr);
// getting the links
$links = explode(',',$ytarr['url_encoded_fmt_stream_map']);
// formats you would like to use
$formats = array(35,34,6,5);
//loop trough the links to find the one you need
foreach($links as $link){
parse_str($link, $args);
if(in_array($args['itag'],$formats)){
//right link found since the links are in hi-to-low quality order
//the match will be the one with highest quality
$video_url = $args['url'];
// add signature to the link
if($args['sig']){
$video_url .= '&signature='.$args['sig'];
}
/*
* What follows is three ways of proceeding with the link,
* note they are not supposed to work all together but one at a time
*/
//download the video and output to browser
@readfile($video_url); // this works fine
exit;
//show video as link
echo '<a href="'.$video_url.'">link for '.$args['itag'].'</a>'; //this won't work
exit;
//redirect to video
header("Location: $video_url"); // this won't work
exit;
}
}
?>