Ver Mensaje Individual
  #6 (permalink)  
Antiguo 03/03/2010, 07:24
Avatar de Eleazan
Eleazan
 
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: Ayuda añadiendo parametro a php (creo que es muy fácil)

Código PHP:
$response=http_test_existance($uri);

if(
$response['status']==404) echo "No se encuentra en fmt=22 ;)";
else {
$uri=$response["location"];
header("location: $uri");
}
exit; 
Si no existe, devuelve 404, sino, creo q era 303 o aglo asi xD

EDIT:

Con un par de pequeños cambios, quedaría así:
Código PHP:
<?php


// call with: http://www.mydomain.com/path/YouTube_Multi-Format.php?v=K2_U1kbIcJQ&fmt=18
// JWMP code:
// 'file': encodeURIComponent('YouTube_Multi-Format.php?v=K2_U1kbIcJQ&fmt=18'),
// 'type': 'video',
// fmt=6 HQ FLV 480x360
// fmt=18 HQ MP4 480x270
// fmt=22 HQ MP4 1280x720
// fmt=35 HQ MP4 640x360

$videoid=$_GET["v"]; 
//$videoid = (isset($_GET['videoid'])) ? strval($_GET['videoid']) : '8bV0XSwnPkI';
//$fmt = (isset($_GET['fmt'])) ? intval($_GET['fmt']) : '';
$fmt 22;
parse_str(file_get_contents("http://youtube.com/get_video_info?video_id=$videoid"));
//$uri = "http://www.youtube.com/get_video.php?video_id=$videoid&t=$token";
$uri "http://www.youtube.com/get_video.php?video_id=$videoid&t=$token&fmt=";
//...debug

//$headers = get_headers($uri);
//print "<pre>\n";
//print " uri: $uri\n" ;
//print "videoid: $videoid\n";
//print " token: $token\n";
//print " fmt: $fmt\nheaders: ";
//print_r($headers);
//print "\n</pre>\n";
//exit;

//...debug


function http_test_existance(
$url,
$timeout 10
) {
$timeout = (int)round($timeout/2+0.00000000001);
$return = array();

### 1 ###
$inf parse_url($url);

if (!isset(
$inf['scheme']) or $inf['scheme'] !== 'http') return array('status' => -1);
if (!isset(
$inf['host'])) return array('status' => -2);
$host $inf['host'];

if (!isset(
$inf['path'])) return array('status' => -3);
$path $inf['path'];
if (isset(
$inf['query'])) $path .= '?'.$inf['query'];

if (isset(
$inf['port'])) $port $inf['port'];
else 
$port 80;

### 2 ###
$pointer fsockopen($host$port$errno$errstr$timeout);
if (!
$pointer) return array('status' => -4'errstr' => $errstr'errno' => $errno);
socket_set_timeout($pointer$timeout);

### 3 ###
$head =
'HEAD '.$path.' HTTP/1.1'."\r\n".
'Host: '.$host."\r\n";

if (isset(
$inf['user']))
$head .= 'Authorization: Basic '.
base64_encode($inf['user'].':'.(isset($inf['pass']) ? $inf['pass'] : ''))."\r\n";
if (
func_num_args() > 2) {
for (
$i 2$i func_num_args(); $i++) {
$arg func_get_arg($i);
if (
strpos($arg':') !== false and
strpos($arg"\r") === false and
strpos($arg"\n") === false
) {
$head .= $arg."\r\n";
}
}
}
else 
$head .=
'User-Agent: Selflinkchecker 1.0 (http://aktuell.selfhtml.org/artikel/php/existenz/)'."\r\n";

$head .=
'Connection: close'."\r\n"."\r\n";

### 4 ###
fputs($pointer$head);

$response '';

$status socket_get_status($pointer);
while (!
$status['timed_out'] && !$status['eof']) {
$response .= fgets($pointer);
$status socket_get_status($pointer);
}
fclose($pointer);
if (
$status['timed_out']) {
return array(
'status' => -5'_request' => $head);
}

### 5 ###
$res str_replace("\r\n""\n"$response);
$res str_replace("\r""\n"$res);
$res str_replace("\t"' '$res);

$ares explode("\n"$res);
$first_line explode(' 'array_shift($ares), 3);

$return['status'] = trim($first_line[1]);
$return['reason'] = trim($first_line[2]);

foreach (
$ares as $line) {
$temp explode(':'$line2);
if (isset(
$temp[0]) and isset($temp[1])) {
$return[strtolower(trim($temp[0]))] = trim($temp[1]);
}
}

//$return['_response'] = $response;
//$return['_request'] = $head;






return $return;

}

$response=http_test_existance($uri.$fmt);

if(
$response['status']==404) {
    
$fmt=18;
    
$response=http_test_existance($uri.$fmt);
    }
    
$uri=$response["location"];
print_r($response);
header("location: $uri");
exit;


?>
No lo he probado, pero creo q funcionará :)

Última edición por Eleazan; 03/03/2010 a las 07:31