Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #- extraer primer resultado de youtube
- function videoYoutube($n){
- #- parseador html (?)
- function parsear($a,$b,$c){
- $x = @explode($a, $c);
- $y = @explode($b,$x[1]);
- return $y[0];
- }
- #- url
- $url = 'https://www.youtube.com/results?search_query='.str_replace(' ', '+', $n);
- #- html
- $html = explode('<h3 class="yt-lockup-title">', @file_get_contents($url));
- #- datos
- $datos = array(
- 'titulo'=>@parsear('title="','"',$html[3]),
- 'imagen'=>'http://img.youtube.com/vi/'.substr(@parsear('<a href="/watch?v=','" class="yt-uix-sessionlink',$html[3]),0,11).'/mqdefault.jpg',
- 'url'=>'http://www.youtube.com/watch?v='.substr(@parsear('<a href="/watch?v=','" class="yt-uix-sessionlink',$html[3]),0,11)
- );
- #- devuelve el array
- return $datos;
- }
- #-----------------------------------------------------------------------------#
- #-----------------------------------------------------------------------------#
- #-----------------------------------------------------------------------------#
- #ejemplo (?)
- $tema = 'Quenn - Love of my life (acoustic)';
- print_r(videoYoutube($tema));
- #resultado:
- Array
- (
- [titulo] => Queen - Love of my life (Rock Montreal 1981) - HD 720
- [imagen] => http://img.youtube.com/vi/vNsEEvRMtGI/mqdefault.jpg
- [url] => http://www.youtube.com/watch?v=vNsEEvRMtGI
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement