LastFM Music Engine

This lightweight class makes it simple to integrate and process music info from last fm.

Buy Online for $8

This 5 tabs will show music information. The class supports Trending music, Artists search, Track search, Album search & Artist info (toptracks, bio, tags, similar artists). The fifth tab will show the setup & methods of this lightweight class.

  • Lightweight
  • 2 Lines code
  • Easy Integration
  • Return Array & HTML
  • Trending music (based on region ISO)
  • Search Artists
  • Search Tracks/Songs
  • Search Albums
  • Artist info (Top Tracks, Bio, Tags, Similar Artists)
  • Styled Items included
  • Ajax Artist/Track & Album search
  • No refresh for search needed
  • Fallback image
  • Added feature: Youtube API Tracks

Setup & Integrate


You need to have the module cUrl to be enabled (you can check this in phpinfo)

Change the APIKEY const to your API KEY in the lastfm class (lastfm.class.php), note: this api key is a dummy key so not valid. Also you can adjust the default search limit.

const APIKEY = 'b542e4633dc1c8sd452007747538';
const DEFAULT_LIMIT = 20;

Include & initalize class

include_once('lastfm.class.php');
$lstfm = new Lastfm();

Fallback Image

The fallback image can be found & adjust in the folder (img/standard_cover.png)

Functions


This lightweight class has the following functions. The trending & search methods have a optional limit paramater

The trending methods are set on the region based ISO3166-1 country names standard (Belgium, USA, Spain,...). Check the wikipedia for your countryname

$lstfm->trendingTracks('Belgium'); //gets the trending tracks based on a country
$lstfm->trendingArtists('Belgium', 10);  //gets the trending artists based on a country limited to 10 items (limit parameter)
$lstfm->searchTracks('Soldier');  //searchs tracks based on a search term
$lstfm->searchArtists('Marco Bai') //searchs artists based on a search term
$lstfm->searchArtists('Marco Bai', 20) // same with a limit of 20 results
$lstfm->searchAlbums('Half power'); //searchs albums based on the given term

$lstfm->searchArtistInfo('Eminem', array('toptracks', 'bio'));  //gets the toptracks, bio (bio text, tags & similar artists) based on a full artist name
$lstfm->showHtmlList($array, 'type'); //returns an styled unorderd (ul) html list (supports types: artists/tracks/albums)
$lstfm->findVideo($artist, $title); //returns an youtube link based on the given artist & title

Default ajax functions (artist/track/albums) will output 1 page with 10 results (ajax.functions.php) You can adjust that file in according your need

$searchTracks = $lstfm->searchTracks($trackTerm, 1 , 10);
$lstfm->showHtmlList($searchTracks, 'tracks');

The Show HTMLList method wil return a unorderd list with a structure like the example below (searchTracks)

<ul class="lastfmlist tracks">
 <li class="item">
 <div class="meta">
 <h1>Sing for Absolution</h1>
 <h2>Muse</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/61418461.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Single Ladies (Put a Ring on It)</h1>
 <h2>Beyoncé</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/93272439.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Sing for the Moment</h1>
 <h2>Eminem</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/88163203.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Sing</h1>
 <h2>Travis</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/73368188.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>And Your Bird Can Sing</h1>
 <h2>The Beatles</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/100131537.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>What Your Soul Sings</h1>
 <h2>Massive Attack</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/30959875.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Sing It Back</h1>
 <h2>Moloko</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/4576293.jpg">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Y'all Want A Single</h1>
 <h2>Korn</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/67919282.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Singapore</h1>
 <h2>Tom Waits</h2>
 </div>
 <img width="130px" src="http://userserve-ak.last.fm/serve/300x300/98058591.png">
 </li>
 <li class="item">
 <div class="meta">
 <h1>Billie Jean - Single Version</h1>
 <h2>Michael Jackson</h2>
 </div>
 <img width="130px" src="img/standard_cover.png">
 </li>
</ul>

Tracks - autocomplete ajax call


This input box does an ajax call to (ajax.functions.php) for autocompleting tracks with a term this works with (the JS file for the event handling of the inputbox)

Create an input text field with id trackSearch and a result div with id resultTrack

<input type="text" id="trackSearch" placeholder="Trackname...">
<div id="resultTrack"></div>

HTML Output (check the ajax.function.php & main.js for the response)

Minimum 3 characters.

Artists - autocomplete ajax call


This input box does an ajax call to (ajax.functions.php) for autocompleting artists with a term this works with (the JS file for the event handling of the inputbox)

Create an input text field with id artistSearch and a result div with id resultArtist

<input type="text" id="artistSearch" placeholder="Artist name...">
<div id="resultArtist"></div>

HTML Output (check the ajax.function.php & main.js for the response)

Minimum 3 characters.

Albums - autocomplete ajax call


This input box does an ajax call to (ajax.functions.php) for autocompleting albums with a term this works with (the JS file for the event handling of the inputbox)

Create an input text field with id albumSearch and a result div with id resultAlbum

<input type="text" id="albumSearch" placeholder="Albumname...">
<div id="resultAlbum"></div>

Minimum 3 characters.

Artist info


This page shows the info of 1 artist with the toptracks, bio, similar artists & tags of that artist in an array

$lstfm->searchArtistInfo('Eminem', array('toptracks', 'bio')); // returns toptrack & bio
$lstfm->searchArtistInfo('Eminem', array('toptracks'), 10); //artist info without bio and only 10 toptracks
$lstfm->searchArtistInfo('Eminem' array('bio')); //artist info without toptracks and only bio
Warning: Undefined property: stdClass::$error in /customers/c/7/9/downloadmarkt.be/httpd.www/lastfm-musicengine/libraries/lastfm.class.php on line 257 Warning: Undefined property: stdClass::$error in /customers/c/7/9/downloadmarkt.be/httpd.www/lastfm-musicengine/libraries/lastfm.class.php on line 291
Bio

$artistinfo->bio->cover_image
artistinfo->bio->name
$artistinfo->bio->summary
$lstfm->showHtmlList($artistinfo->bio->similar, 'artists');
$lstfm->showHtmlList($artistinfo->bio->tags, 'tags');

Output



Eminem

Marshall Bruce Mathers III (born October 17, 1972), known professionally as Eminem (/ˌɛmɪˈnɛm/; often stylized as EMINƎM), is an American rapper. He is credited with popularizing hip-hop in the world and is regarded as one of the greatest rappers of all time. Eminem's global success and acclaimed works are widely regarded as having broken racial barriers for the acceptance of white rappers in popular music. While much of his transgressive work during the late 1990s and early 2000s made him a controversial figure Read more on Last.fm

Similar artists
  • Bad Meets Evil
  • D12
  • Obie Trice
  • Stat Quo
  • Paul Rosenberg
Tags
  • rap
  • Hip-Hop
  • Eminem
  • hip hop
  • pop
Toptracks

$lstfm->showHtmlList($artistinfo->toptracks, 'tracks');

Output

  • Without Me

    Eminem

  • The Real Slim Shady

    Eminem

  • Lose Yourself

    Eminem

  • Stan

    Eminem

  • Mockingbird

    Eminem

  • Love The Way You Lie

    Eminem

  • Not Afraid

    Eminem

  • My Name Is

    Eminem

  • Sing for the Moment

    Eminem

  • Superman

    Eminem

Output of array $artistinfo

stdClass Object
(
    [toptracks] => Array
        (
            [0] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Without Me
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [1] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => The Real Slim Shady
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [2] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Lose Yourself
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [3] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Stan
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [4] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Mockingbird
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [5] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Love The Way You Lie
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [6] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Not Afraid
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [7] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => My Name Is
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [8] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Sing for the Moment
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

            [9] => stdClass Object
                (
                    [artist] => Eminem
                    [title] => Superman
                    [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                )

        )

    [bio] => stdClass Object
        (
            [name] => Eminem
            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
            [summary] => Marshall Bruce Mathers III (born October 17, 1972), known professionally as Eminem (/ˌɛmɪˈnɛm/; often stylized as EMINƎM), is an American rapper. He is credited with popularizing hip-hop in the world and is regarded as one of the greatest rappers of all time. Eminem's global success and acclaimed works are widely regarded as having broken racial barriers for the acceptance of white rappers in popular music. While much of his transgressive work during the late 1990s and early 2000s made him a controversial figure Read more on Last.fm
            [similar] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => Bad Meets Evil
                            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                        )

                    [1] => stdClass Object
                        (
                            [name] => D12
                            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                        )

                    [2] => stdClass Object
                        (
                            [name] => Obie Trice
                            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                        )

                    [3] => stdClass Object
                        (
                            [name] => Stat Quo
                            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                        )

                    [4] => stdClass Object
                        (
                            [name] => Paul Rosenberg
                            [cover_image] => https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
                        )

                )

            [tags] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => rap
                            [url] => https://www.last.fm/tag/rap
                        )

                    [1] => stdClass Object
                        (
                            [name] => Hip-Hop
                            [url] => https://www.last.fm/tag/Hip-Hop
                        )

                    [2] => stdClass Object
                        (
                            [name] => Eminem
                            [url] => https://www.last.fm/tag/Eminem
                        )

                    [3] => stdClass Object
                        (
                            [name] => hip hop
                            [url] => https://www.last.fm/tag/hip+hop
                        )

                    [4] => stdClass Object
                        (
                            [name] => pop
                            [url] => https://www.last.fm/tag/pop
                        )

                )

        )

)