Re: [問題] 如何解析youtube的網址
目前下載的概念是先下載 get_video_info 檔案
然後再用 curl 下載影片的 url
exec('curl "http://www.youtube.com/get_video_info?video_id=57zrn_M5bE8" >
/tmp/youtube.tmp');
exec('curl "'.$max["url"].'" > a.webm');
這同一段程式碼有時候成功有時候失敗
而且學網很慢= =a
Kej 大大有看到文章的話
能指導一下有沒有更好的下載方式?
或者分享一下你的網站上面運作的機制,設計方式是什麼等等
※ 引述《kusoayan (瑋哥)》之銘言:
: 我之前也一度想搞 youtube 的#@$@#$#^…
: 有在國外論壇找到這個以下程式碼
: 還堪用啦XD
: 不過不知道是不是你想做的那樣就是了
: /*********************************************************
: *
: *
: * Author: Vick@PHPCanyon.net
: *
: * Site : www.PHPCanyon.net
: *
: * Date : 28/11/2011
: *
: * Notes : This doesn't just download MP4, It Downloads *
: * either mp4, flv, which ever is better. *
: *
: *
: * How to use?
: *
: * YouTubeToMP4("videoidhere"); *
: * ^ Outputs Direct Link to Download. *
: *
: *
: * BE AWARE YOUTUBE MIGHT
: *
: * BAN/BLOCK YOUR IP IF YOU
: *
: * MISS-USE/MASS USE THIS SCRIPT *
: * THIS SCRIPT COMES "AS-IS" AND *
: * YOU ARE RESPONSIBLE FOR YOUR *
: * OWN ACTIONS AND HOW-EVER YOU *
: * USE THIS SCRIPT, IF YOU DISAGREE *
: * THEN CLOSE THIS TEXT EDITOR RIGHT *
: * NOW AND DELETE THIS SCRIPT ! *
: *
: *
: * FAQ
: *
: * 1. I can Only see "&title="? *
: * -> Your Banned GG.
: *
: *
: *
: **********************************************************/
: function youTubeToMP4($videoid)
: {
: // Pass VideoID into $url to create Video URL to Watch
: $url = "http://www.youtube.com/watch?v=$videoid";
: // Get Page Contents and put in Variable
: $pageSource = file_get_contents($url);
: /* Using Regex we need to grab 2 required params to
: generate a download link */
: // Get Snippet
: $snippet = '/img.src = "(.+?)";/';
: preg_match($snippet, $pageSource, $match_snippet);
: $rawSource = urldecode($match_snippet[1]);
: // Get TITLE
: $title_snippet = '/meta name="title" content="(.+?)">/';
: preg_match($title_snippet, $pageSource, $match_title_snippet);
: $title = $match_title_snippet[1];
: // Remove spaces and add '%20', theres better ways but
: // this felt easier at the time.
: $removeSpaces = " ";
: $add = "%20";
: $newTitle = str_replace($removeSpaces, $add, $title);
: // Remove '\'
: $removeThis = '\\';
: $result = str_replace($removeThis, "", $rawSource);
: $newURL = $result . "&title=$newTitle";
: // Remove 'u0026' and replace with '&'
: $andRemoveThis = 'u0026';
: $result_ = str_replace($andRemoveThis, "&", $newURL);
: // Replace link with watch link
: $Laps = "generate_204?";
: $rounds = "videoplayback?";
: $circuit = str_replace($Laps, $rounds, $result_);
: echo $circuit;
: }
: // Call this function with "videoidhere"
: $videoId = $_GET['videoId'];
: //YouTubeToMP4("ooZwmeUfuX");
: youTubeToMP4($videoId);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.87.64.222
推
03/01 12:06, , 1F
03/01 12:06, 1F
→
03/01 12:06, , 2F
03/01 12:06, 2F
→
03/01 12:07, , 3F
03/01 12:07, 3F
→
03/01 12:07, , 4F
03/01 12:07, 4F
→
03/01 12:09, , 5F
03/01 12:09, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 6 之 6 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章