9/18/2013

星期三, 9月 18, 2013

說明

因為開發的需求,茶米希望可以由 Youtube 的播放網址,直接取得 Youtube 影片的真實網址,除了可以直接化為影片的下載網址,也可以設定為一些播放器的影片來源路徑。在網址上找到了這個程式碼,實在是很好用喔!

程式碼內容

<?php
$file = $_GET["file"];
if (preg_match('/youtube\.com\/(v\/|watch\?v=)([\w\-]+)/', $file, $match)) {
    ;
    $id     = $match[2];
    $link   = "http://www.youtube.com/watch?v=" . $id;
    $html   = file_get_contents($link);
    $html   = urldecode($html);
    $h      = explode('fmt_stream_map', $html);
    $html   = urldecode($h[1]);
    $videos = explode('url=', $html);
    for ($i = 0; $i < count($videos); $i++) {
        $t1   = explode(";", $videos[$i]);
        $link = $t1[0];
        $t1   = explode("itag=", $link);
        $t2   = explode("&", $t1[1]);
        $tip  = $t2[0];
        if ($tip == "37")
            break;
        if ($tip == "22")
            break;
        if ($tip == "18")
            break;
    }
}
print $link;
?>

參考來源

http://weng32002.blogspot.tw/2012/02/aszcc-youtube-ims.html

0 意見 :

張貼留言