Re: [問題] 如何解析youtube的網址
我之前也一度想搞 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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 5 之 6 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章