Youtube Class
<?php
/*
Youtube Class
Kodlama By s4l1h
http://pehepe.blogspot.com/
*/
class Youtube{
/*
Link Tutucu
*/
function link_tut($link){
$x=parse_url($link);
parse_str($x['query'],$y);
$this->id=$y['v'];
$this->link='http://www.youtube.com/watch?v='.$y['v'];
$this->resim='http://img.youtube.com/vi/'.$y['v'].'/default.jpg';
}
/*
ID tutucu
*/
function id_tut($id){
$this->link='http://www.youtube.com/watch?v='.$id;
$this->id=$id;
$this->resim='http://img.youtube.com/vi/'.$id.'/default.jpg';
}
/*
Bağlantı
*/
function baglan($link){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$link);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_REFERER,'http://www.youtube.com/');
curl_setopt($ch,CURLOPT_HEADER,true);
$sonuc=curl_exec($ch);
curl_close($ch);
return $sonuc;
}
/*
t değerini buluyoruz.
*/
function bul(){
$kaynak=$this->baglan($this->link);
preg_match("|\<meta name=\"title\" content=\"(.*?)\"\>|",$kaynak,$isim);
$this->ad=trim($isim['1']);
preg_match("|\"t\": \"(.*?)\"|",$kaynak,$t);
$sonuc = "http://www.youtube.com/get_video?video_id=".$this->id."&t=".$t['1'];
return $sonuc;
}
/*
Flv Adresini buluyoruz.
*/
function flv(){
$link=$this->bul();
$kaynak=$this->baglan($link);
preg_match("|Location:(.*?)\\n|",$kaynak,$cik);
$this->flv=trim($cik['1']);
return $this->flv;
}
/*
Video İd'sini ekrana yazdırmak için
*/
function id(){
return $this->id;
}
/*
Video Adı
*/
function ad(){
if(!$this->ad){
$this->bul();
}
return $this->ad;
}
/*
Video Thumbnail
*/
function resim(){
return $this->resim;
}
/*
Video Link
*/
function adres(){
return $this->link;
}
/*
Video Kaynak kodları playerde oynatmak için.
*/
function flv_data(){
if(!$this->flv){
$this->flv();
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Cache-Control: private',False);
header('Content-Type: video/flv');
header('Content-Disposition: attachment; filename='.$this->id.'.flv;');
header('Content-Transfer-Encoding: binary');
readfile($this->flv);
}
/*
Video Resim tarayıcıda göstermek için
*/
function resim_data(){
if(!$this->flv){
$this->flv();
}
header("Content-type: image/jpeg");
readfile($this->resim);
}
}Örnek Kullanım<?php
require_once('youtube.class.php'); // Sınıf dosyamızı ekliyoruz.
/*
Youtube Class Örnek Kullanım
Kodlama By s4l1h
http://pehepe.blogspot.com/
*/
$video=new Youtube(); // Sınıfımızı çağırıyoruz ve $video değişkenine atıyoruz.
$video->link_tut('http://www.youtube.com/watch?v=gzqpEWykqEs&feature=related'); // Video linki tutuyoruz.
//$video->id_tut('gzqpEWykqEs'); //Üst satır ile aynı şey
if($_GET['olay']=='indir.flv'){// Video indirilmek istenirse index.php?olay=indir.flv
echo $video->flv_data(); // Video Kaynak Kodları
}elseif($_GET['olay']=='resim.jpg'){ // Resimi tarayıcıda göstermek istenirse index.php?olay=resim.jpg
echo $video->resim_data(); // Resim Tarayıcıda Gösterilir
}else{ // Eğer sadece index.php diye çağrılırsa
header('Content-Type: text/html; charset=utf-8');
echo '<pre>';
echo '<b>Flv Adresi:</b> '.$video->flv(); // Flv adresi.
echo "\n";
echo '<b>İD:</b> '.$video->id(); // Video ID
echo "\n";
echo '<b>Resim:</b> '.$video->resim(); // Video Thumbnail
echo "\n";
echo '<b>Video Adresi:</b> '.$video->adres(); // Video Adresi
echo "\n";
echo '<b>Video Adı:</b> '.$video->ad(); // Video Adı
echo "\n";
echo '<img src="index.php?olay=resim.jpg" border="0" alt="'.$video->ad().'"/>';
echo "\n";
echo '<a href="index.php?olay=indir.flv" title="'.$video->ad().' Video Dosyasını İndir">Video Dosyasını İndir</a>';
echo '</pre>';
/*
Playerde Oynatalım.
Playerde Çalışabilmesi için aşşağıdaki $site değişkenini düzenleyin
*/
$site='http://www.dl21.org/index.php';// Buraya Scriptin bulunduğu adresi yazıyoruz.
echo <<<HTML
<embed name="video" width="300" height="200" allowfullscreen="true" src="http://www.onlineflvplayer.com/player.swf" flashvars="file=$site?olay=indir.flv&image=$site?olay=resim.jpg" type="application/x-shockwave-flash" pluginspage="http://get.adobe.com/flashplayer/"></embed>
HTML;
}
?>Screen Shot
Eğer screen shot görünmüyorsa sayfayı ziyaret edin.
Dosyaları toplu halde buradan indirebilirsiniz.
herkes evirip çevirip ayni kodlari ben yazdim diye forumda paylaşıp duruyor