Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. #- extraer primer resultado de youtube
  2. function videoYoutube($n){
  3.     #- parseador html (?)
  4.     function parsear($a,$b,$c){
  5.         $x = @explode($a, $c);
  6.         $y = @explode($b,$x[1]);
  7.         return $y[0];
  8.     }
  9.     #- url
  10.     $url = 'https://www.youtube.com/results?search_query='.str_replace(' ', '+', $n);
  11.     #- html
  12.     $html = explode('<h3 class="yt-lockup-title">', @file_get_contents($url));
  13.     #- datos
  14.     $datos = array(
  15.             'titulo'=>@parsear('title="','"',$html[3]),
  16.             'imagen'=>'http://img.youtube.com/vi/'.substr(@parsear('<a href="/watch?v=','" class="yt-uix-sessionlink',$html[3]),0,11).'/mqdefault.jpg',
  17.             'url'=>'http://www.youtube.com/watch?v='.substr(@parsear('<a href="/watch?v=','" class="yt-uix-sessionlink',$html[3]),0,11)
  18.         );
  19.     #- devuelve el array
  20.     return $datos;
  21. }
  22. #-----------------------------------------------------------------------------#
  23. #-----------------------------------------------------------------------------#
  24. #-----------------------------------------------------------------------------#
  25. #ejemplo (?)
  26. $tema = 'Quenn - Love of my life (acoustic)';
  27.  
  28. print_r(videoYoutube($tema));
  29.  
  30. #resultado:
  31. Array
  32. (
  33.     [titulo] => Queen - Love of my life (Rock Montreal 1981) - HD 720
  34.     [imagen] => http://img.youtube.com/vi/vNsEEvRMtGI/mqdefault.jpg
  35.     [url] => http://www.youtube.com/watch?v=vNsEEvRMtGI
  36. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement