- Estréllate y Arde - https://www.estrellateyarde.org -
Ejemplo de mashup con Last.fm y YouTube
Vamos a ver un pequeño ejemplo de aplicación web híbrida (mashup).
Veamos el código:
include('downloads/lastfm-youtube.php');
<?php $artista = "Metallica"; //URL del feed 'artista' de Last.fm $feed = "http://ws.audioscrobbler.com/2.0/artist/".$artista."/info.xml"; //volcar el feed en un objeto SimpleXML $xml = simplexml_load_file($feed); //extraer datos del feed $name = $xml->name; $url = $xml->url; $biosummary = $xml->bio->summary; foreach ($xml->image as $image) { switch((string) $image['size']) { case 'large': $imagelarge = $image; break; default: break; } } ?> <h3><a href="<?php echo $url; ?>" ><?php echo $name; ?></a></h3> <p><?php echo $biosummary; ?></p> <p><img src="<?php echo $imagelarge; ?>" /></p> <?php //URL del feed 'toptracks' de Last.fm $feed = "http://ws.audioscrobbler.com/2.0/artist/".$artista."/toptracks.xml"; //volcar el feed en un objeto SimpleXML $xml = simplexml_load_file($feed); //extraer datos del feed foreach ($xml->track as $track) { $trackname = $track->name; $trackurl = $track->url; $playcount = $track->playcount; ?> <p>Canción más reproducida en Last.fm: <a href="<?php echo $trackurl; ?>" ><?php echo $trackname; ?></a> (<?php echo $playcount; ?> reproducciones)</p> <?php break; } //URL del feed 'Search' de YouTube $search = $artista."-".$trackname."&max-results=1"; $feed = "http://gdata.youtube.com/feeds/api/videos?vq=".$search; //volcar el feed en un objeto SimpleXML $xml = simplexml_load_file($feed); //extraer datos del feed foreach ($xml->entry as $entry) { // player url $media = $entry->children('http://search.yahoo.com/mrss/'); $watch = $media->group->player->attributes()->url; // thumbnail $media = $entry->children('http://search.yahoo.com/mrss/'); $thumbnail = $media->group->thumbnail[0]->attributes()->url; // <yt:duration> $media = $entry->children('http://search.yahoo.com/mrss/'); $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $length = $yt->duration->attributes()->seconds; // <yt:stats> $yt = $entry->children('http://gdata.youtube.com/schemas/2007'); $viewcount = $yt->statistics->attributes()->viewCount; // <gd:rating> $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $rating = $gd->rating->attributes()->average; } else { $rating = 0; } ?> <p>Vídeo de YouTube de <a href="<?php echo $watch; ?>"> <?php echo $artista; ?> - <?php echo $trackname; ?></a> (<?php echo $viewcount; ?> reproducciones)<br/> <a href="<?php echo $watch; ?>"> <img src="<?php echo $thumbnail; ?>" /></a><br/> Duración: <?php echo $length; ?> segundos.<br/> Valoración: <?php echo $rating; ?></p> <?php } ?>
Article printed from Estréllate y Arde: https://www.estrellateyarde.org
URL to article: https://www.estrellateyarde.org/discover/mashup-lastfm-youtube
Click here to print.
Copyright © 2010 Estrellate y Arde