Hi, im have this code: <?php function getContent($url) { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); ob_start(); curl_exec ($ch); curl_close ($ch); $string = ob_get_contents(); ob_end_clean(); return $string; } function fetch_headers($url) { $headers = array(); $url = trim($url); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_NOBODY ,1); $data = curl_exec($ch); $errormsg = curl_error($ch); curl_close($ch); $headers = explode("\n", $data); return $headers; } function getYoutubeToken($id) { $path = "http://www.youtube.com/get_video_info?"; $cont = getContent($path."&video_id=".$id); parse_str($cont, $opts); return $opts['token']; } $videoItem = trim($_GET['item']); $videoType = ""; $videoPath = "http://www.youtube.com/get_video"; if ($_GET['type'] != "0") { $videoType = "&fmt=".$_GET['type']; } if ($videoItem != "") { $videoTokn = getYoutubeToken($videoItem); $videoURL = $videoPath."?video_id=".$videoItem."&t=".$videoTokn.$videoType; $headers = fetch_headers($videoURL); for ($i=0; $i<count($headers); $i++) { if (strstr($headers[$i], "ocation:")) { $str1 = explode("ocation:", $headers[$i]); $link = trim($str1[1]); break; } } header("Location: ".$link); exit; } ?> PHP: This process this form: <form action="index.php" method="get"> <label for="item"> Video ID:</label> <input name="item" id="item" type="text" size="30"><br> <label for="type">Type:</label> <select id="type" name="type"> <option value="0">Format FLV </option> <option value="25">MP3 </option> <option value="13">Format 3GP </option> <option value="18">Format MP4</option> <option value="22">Format MP4 (HD)</option> </select> <label for="btget"> </label> <input name="btget" id="btget" type="submit" class="boton" value="Download Video"> <br> </form> PHP: But i want when the user select the option: <option value="25">MP3 </option> the process open a action diferent from the others option, i want add this: if ($option=='25') { //redirect to desired page. } else { //continue with code for options 1-4. } but when i add, and where i specified the url where have to go?
Ill just made this today for fun so you might aswell have it... It fetches to types of links flv and mp4 <?php //Global Functions File //Url Fudgers lol function makeMp4Link($args){ $Domain = 'http://youtube.com/get_video?'; $baseArgs = array('video_id' => $args['video_id'], 'fmt' => '18', 'l' => $args['l'], 'sk' => $args['sk'], 'fmt_map' => $args['fmt_map'], 't' => $args['t']); return $Domain . http_build_query($baseArgs); } function makeFlvLink($args){ $Domain = 'http://youtube.com/get_video?'; $baseArgs = array('video_id' => $args['video_id'], 'l' => $args['l'], 'sk' => $args['sk'], 'fmt_map' => $args['fmt_map'], 't' => $args['t']); return $Domain . http_build_query($baseArgs); } function GrabPage($url){ if(function_exists('curl_init')){ return _curlPage($url); }else{ return file_get_contents($url); } } function getJsArray($content){ //Used to grab the single block of js $regex = '/var swfArgs \= (.*?)\;/s'; $holder = array(); //Ok so now we can get the javascript block and follow on to parse it preg_match($regex,$content,$Script); if(function_exists('json_decode')){ //PHP > 5.2.3 ! $data = json_decode($Script[1]); $holder['video_id'] = $data->video_id; $holder['l'] = $data->l; $holder['sk'] = $data->sk; $holder['fmt_map'] = $data->fmt_map; $holder['t'] = $data->t; }else{ $data = _json_decodeTemp($Script[1]); $holder['video_id'] = $data['video_id']; $holder['l'] = $data['l']; $holder['sk'] = $data['sk']; $holder['fmt_map'] = $data['fmt_map']; $holder['t'] = $data['t']; } return $holder; } /*Private Functions*/ function _json_decodeTemp($json){ //This will replicate ('json_encode') upto about 80% $comment = false; $out = '$x='; for ($i=0; $i<strlen($json); $i++) { if (!$comment){ if ($json[$i] == '{') $out .= ' array('; else if ($json[$i] == '}') $out .= ')'; else if ($json[$i] == ':') $out .= '=>'; else $out .= $json[$i]; }else{ $out .= $json[$i]; } if($json[$i] == '"'){ $comment = !$comment; } } eval($out . ';'); return $x; } function _curlPage($url,$debug = false){ $ch = curl_init($url); //Settings $UserAgent = $_SERVER['HTTP_USER_AGENT']; $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => $UserAgent, // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl CURLOPT_SSL_VERIFYPEER => false, // No SSL Verification CURLOPT_VERBOSE => 0 // No Vorbose mode ); curl_setopt_array($ch,$options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $header = curl_getinfo($ch); curl_close($ch); if($debug){ return array( 'content' => $content, 'errno' => $err, 'errmsg' => $errmsg, 'headers' => $header ); } return $content; } $Data = GrabPage('http://www.youtube.com/watch?v=3ZxPxdZugc8'); echo makeMp4Link(GetJsArray($Data)); echo '<br />'; echo makeMp4Link(GetJsArray($Data)); //Usage explain /* First you need to grab the youtube page: $Data = GrabPage('http://www.youtube.com/watch?v=3ZxPxdZugc8'); Then you send the data to the GetJsArray to get the needed javascript variables $Data = GetJsArray($Data); Then you send the arrayed data from the javascript stripper to the link creator $MP4 = makeMp4Link($Data); $FLV = makeFlvLink($Data); Now you can just go header('Location: ',$MP4); // this will start a direct download to the high def video! */ ?> PHP: Hope you find it usefull and peace