Re: [問題] 如何解析youtube的網址

看板PHP作者 (瑋哥)時間13年前 (2012/02/28 11:39), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/6 (看更多)
我之前也一度想搞 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: 125.228.164.65
文章代碼(AID): #1FJ4nPsb (PHP)
文章代碼(AID): #1FJ4nPsb (PHP)