Quick piece of code that should, in theory, fetch the FLV/MP4/whatever URL of the video, given a youtube URL. The example has a hard-coded url, turn it into a function to make it a parameter instead. Also, it has absolutely no error checking, so you may wanna implement that (e.g. you should check if $r returns false and, if so, throw an error and die). $c = curl_init();curl_setopt($c, CURLOPT_URL, 'http://www.youtube.com/watch?v=sRLz4aDCAs0');curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);curl_setopt($c, CURLOPT_FAILONERROR, 1);$r = curl_exec($c);curl_close($c); preg_match_all('#url_encoded_fmt_stream_map=([^&]+)#', $r, $fvars);$fvars = explode('&', urldecode($fvars[1][0])); $results = array();$resultIndex = -1; foreach($fvars as $item){ if(strpos($item, 'url=') !== false) $resultIndex++; if(!isset($results[$resultIndex])) $results[$resultIndex] = array(); if(strpos($item, 'url=') === false) { $parse = explode('=', $item); $results[$resultIndex][$parse[0]] = urldecode($parse[1]); continue; } $parse = preg_match('#url=(.+)$#', $item, $url); $results[$resultIndex]['url'] = urldecode($url[1]);} var_dump($results); PHP: This results in an array containing arrays like so: array(5) { ["url"]=> string(419) "some_youtube_url" ["quality"]=> string(5) "small" ["fallback_host"]=> string(26) "tc.v4.cache5.c.youtube.com" ["type"]=> string(11) "video/x-flv" ["itag"]=> string(1) "5" } Code (markup): Just an example anyway, there may be an easier way to do it but this seemed logical at the time.
Thank WPC post code example, i'll post code check file HD if it exist or not exist get file flv function getYouTube($url) { $geturl = NULL; $c = curl_init(); curl_setopt($c, CURLOPT_URL,$url); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FAILONERROR, 1); $err = curl_error($c); $r = curl_exec($c); curl_close($c); if(isset($err)) { $geturl = "Link Warn Video Not Found"; }else{ preg_match_all('#url_encoded_fmt_stream_map=([^&]+)#', $r, $fvars); $fvars = explode('&', urldecode($fvars[1][0])); $results = array(); $resultIndex = -1; foreach($fvars as $item) { if(strpos($item, 'url=') !== false)$resultIndex++; if(!isset($results[$resultIndex]))$results[$resultIndex] = array(); if(strpos($item, 'url=') === false) { $parse = explode('=', $item); $results[$resultIndex][$parse[0]] = urldecode($parse[1]); continue; } $parse = preg_match('#url=(.+)$#', $item, $url); $results[$resultIndex]['url'] = urldecode($url[1]); } //video/mp4; codecs="avc1.42001E, mp4a.40.2" $searchType = "/mp4/i"; foreach($results as $test) { if(preg_match($searchType,$test["type"])) { $geturl = $test["url"]; echo "Type {$test["type"]} and link file {$test["url"]}"; break; } } if(empty($geturl)) { $geturl = $results[0]["url"]; } } return $geturl; } PHP: Call Function echo getYouTube("http://www.youtube.com/watch?v=sRLz4aDCAs0"); PHP:
This is code get url file movies let you can set embed with Flash Player like JW Payer, MP Player ...etc
If you want to embed with JW, I think you no need so much to do like that. I have done with this code: That's enough to show youtube clip on my page.
it need for working if you're want to track visits or to download that file and hide the address link movies of the file