17 Ocak 2010 Pazar

Youtube class

Geçenlerde Yazmış olduğum youtube sınıfını sizlerle paylaşıyorum.
Youtube Class

  1. /*
  2. Youtube Class
  3. Kodlama By s4l1h
  4. http://pehepe.blogspot.com/
  5. */
  6. class Youtube{
  7. /*
  8. Link Tutucu
  9. */
  10. function link_tut($link){
  11. $x=parse_url($link);
  12. parse_str($x['query'],$y);
  13. $this->id=$y['v'];
  14. $this->link='http://www.youtube.com/watch?v='.$y['v'];
  15. $this->resim='http://img.youtube.com/vi/'.$y['v'].'/default.jpg';
  16. }
  17. /*
  18. ID tutucu
  19. */
  20. function id_tut($id){
  21. $this->link='http://www.youtube.com/watch?v='.$id;
  22. $this->id=$id;
  23. $this->resim='http://img.youtube.com/vi/'.$id.'/default.jpg';
  24. }
  25. /*
  26. Bağlantı
  27. */
  28. function baglan($link){
  29. $ch=curl_init();
  30. curl_setopt($ch,CURLOPT_URL,$link);
  31. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  32. curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
  33. curl_setopt($ch,CURLOPT_REFERER,'http://www.youtube.com/');
  34. curl_setopt($ch,CURLOPT_HEADER,true);
  35. $sonuc=curl_exec($ch);
  36. curl_close($ch);
  37. return $sonuc;
  38. }
  39. /*
  40. t değerini buluyoruz.
  41. */
  42. function bul(){
  43. $kaynak=$this->baglan($this->link);
  44. preg_match("|\|",$kaynak,$isim);
  45. $this->ad=trim($isim['1']);
  46. preg_match("|\"t\": \"(.*?)\"|",$kaynak,$t);
  47. $sonuc = "http://www.youtube.com/get_video?video_id=".$this->id."&t=".$t['1'];
  48. return $sonuc;
  49. }
  50. /*
  51. Flv Adresini buluyoruz.
  52. */
  53. function flv(){
  54. $link=$this->bul();
  55. $kaynak=$this->baglan($link);
  56. preg_match("|Location:(.*?)\\n|",$kaynak,$cik);
  57. $this->flv=trim($cik['1']);
  58. return $this->flv;
  59. }
  60. /*
  61. Video İd'sini ekrana yazdırmak için
  62. */
  63. function id(){
  64. return $this->id;
  65. }
  66. /*
  67. Video Adı
  68. */
  69. function ad(){
  70. if(!$this->ad){
  71. $this->bul();
  72. }
  73. return $this->ad;
  74. }
  75. /*
  76. Video Thumbnail
  77. */
  78. function resim(){
  79. return $this->resim;
  80. }
  81. /*
  82. Video Link
  83. */
  84. function adres(){
  85. return $this->link;
  86. }
  87. /*
  88. Video Kaynak kodları playerde oynatmak için.
  89. */
  90. function flv_data(){
  91. if(!$this->flv){
  92. $this->flv();
  93. }
  94. header('Pragma: public');
  95. header('Expires: 0');
  96. header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
  97. header('Cache-Control: private',False);
  98. header('Content-Type: video/flv');
  99. header('Content-Disposition: attachment; filename='.$this->id.'.flv;');
  100. header('Content-Transfer-Encoding: binary');
  101. readfile($this->flv);
  102. }
  103. /*
  104. Video Resim tarayıcıda göstermek için
  105. */
  106. function resim_data(){
  107. if(!$this->flv){
  108. $this->flv();
  109. }
  110. header("Content-type: image/jpeg");
  111. readfile($this->resim);
  112. }
  113. }

Örnek Kullanım
  1. require_once('youtube.class.php'); // Sınıf dosyamızı ekliyoruz.
  2. /*
  3. Youtube Class Örnek Kullanım
  4. Kodlama By s4l1h
  5. http://pehepe.blogspot.com/
  6. */
  7. $video=new Youtube(); // Sınıfımızı çağırıyoruz ve $video değişkenine atıyoruz.
  8. $video->link_tut('http://www.youtube.com/watch?v=gzqpEWykqEs&feature=related'); // Video linki tutuyoruz.
  9. //$video->id_tut('gzqpEWykqEs'); //Üst satır ile aynı şey
  10. if($_GET['olay']=='indir.flv'){// Video indirilmek istenirse index.php?olay=indir.flv
  11. echo $video->flv_data(); // Video Kaynak Kodları
  12. }elseif($_GET['olay']=='resim.jpg'){ // Resimi tarayıcıda göstermek istenirse index.php?olay=resim.jpg
  13. echo $video->resim_data(); // Resim Tarayıcıda Gösterilir
  14. }else{ // Eğer sadece index.php diye çağrılırsa
  15. header('Content-Type: text/html; charset=utf-8');
  16. echo '
    ';  
  17. echo 'Flv Adresi: '.$video->flv(); // Flv adresi.
  18. echo "\n";
  19. echo 'İD: '.$video->id(); // Video ID
  20. echo "\n";
  21. echo 'Resim: '.$video->resim(); // Video Thumbnail
  22. echo "\n";
  23. echo 'Video Adresi: '.$video->adres(); // Video Adresi
  24. echo "\n";
  25. echo 'Video Adı: '.$video->ad(); // Video Adı
  26. echo "\n";
  27. echo '.$video->ad().'"/>';
  28. echo "\n";
  29. echo '.$video->ad().' Video Dosyasını İndir">Video Dosyasını İndir';
  30. echo '';
  31. /*
  32. Playerde Oynatalım.
  33. Playerde Çalışabilmesi için aşşağıdaki $site değişkenini düzenleyin
  34. */
  35. $site='http://www.dl21.org/index.php';// Buraya Scriptin bulunduğu adresi yazıyoruz.
  36. echo <<
  37. "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/">
  38. HTML;
  39. }
  40. ?>

Screen Shot
Youtube Class

Hiç yorum yok:

Yorum Gönder

 

mp3 indirmp3mp3 dinle