09-11-2011, 19:29
Witam, niedawno zaupiłem skrypt pobierania filmików z youtube do 3gp. Niestety takie skrypty nie działają prawidłowo zbyt długo. Czy mógłby mi ktoś pomóc/wytłumaczyć dla czego tak się dzieje? Jak należy zmodyfokowac taki skrypt aby znów działał prawidłowo?
Kod:
set_time_limit(0);
$url = parse_url(urldecode($_GET['url']));
parse_str($url['query'], $url['query']);
if(isset($url['query']['v'])) {
$id = $url['query']['v'];
unset($url);
$meta = @get_meta_tags('http://www.youtube.com/watch?v='.$id);
$code = @file_get_contents('http://www.youtube.com/watch?v='.$id);
preg_match('#"t": "([^"]*)".*?"video_id": "([^"]*)"#', $code, $match);
$title = $meta['title'];
$title = preg_replace('#[^0-9A-Za-z\-]{1,}#', '_', $title);
$url = 'http://www.youtube.com/get_video?fmt=17&video_id='.$match[2].'&t='.$match[1];
unset($match, $code, $meta);
$head = @get_headers($url, 1);
$url = isset($head['Location']) ? (is_array($head['Location']) ? $head['Location'][count($head['Location'])-1] : $head['Location']) : $url;
$length = is_array($head['Content-Length']) ? $head['Content-Length'][count($head['Content-Length'])-1] : $head['Content-Length'];
unset($head);
if((strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) && !isset($_GET['r'])) {
header('Location: '.$id.'/'.$url.'.3gp', false, 301);
} else {
header('Content-type: video/3gp', true);
header('Content-Length: '.$length, true);
header('Content-Disposition: attachment; filename="'.$title.'.3gp"', true);
@readfile($url);
}
} else {
header('Location: ./', true, 301);
}
?>