var SpotifySearch = require( 'spotify-metadata-search' ),
    LastfmAPI = require('lastfmapi'),
    async = require('async');


var errorHandler = function ( err, res ) {
    console.log( err );
    res.send( 500 );
};


var LastFM = new LastfmAPI({
    api_key : process.env.LAST_FM_KEY,
    secret : process.env.LAST_FM_SECRET
});


exports.byArtistURI = function ( req, res ) {

    var uri = req.query.uri;

    var search = SpotifySearch();
    search.lookup( uri, [ "albumdetail" ], function ( err, data ) {
        if ( err ) {
            return errorHandler( err, res );
        }
        // start building the output object
        var output = {
            name: data.artist.name,
            href: data.artist.href,
            albums: data.artist.albums
        };
        // Get more interesting data from other services
        var tasks = {
            lastFmArtist: function ( callback ) {
                var params = {
                    artist: data.artist.name
                };
                LastFM.artist.getInfo( params, function ( err, artist ) {
                    if ( err ) {
                        return callback( err );
                    }
                    callback( null, artist );
                } );
            }
        };
        async.parallel( tasks, function ( err, results ) {
            // artist profile image
            var biggestImage = results.lastFmArtist.image.pop();
            output.image = biggestImage['#text'];
            // 
            output.bio = results.lastFmArtist.bio.summary;
            if ( err ) {
                return errorHandler( err, res );
            }
            return res.json( output );
        } );

    } );

};


exports.byAlbumURI = function ( req, res ) {

};


exports.byURI = function ( req, res ) {

    var uri = req.query.uri;
    var extras = req.query.extras;

    if ( extras ) {
        extras = extras.split( "," );
    }

    var search = SpotifySearch();
    search.lookup( uri, extras, function ( err, data ) {
        if ( err ) {
            return errorHandler( err, res );
        }
        // start building the output object
        var output = {
            artist: {
                name: data.artist.name,
                href: data.artist.href
            }
        };

        // Get more interesting data from other services
        var tasks = {
            lastFmArtist: function ( callback ) {
                var params = {
                    artist: data.artist.name
                };
                LastFM.artist.getInfo( params, function ( err, artist ) {
                    if ( err ) {
                        return callback( err );
                    }
                    callback( null, artist );
                } );
            }
        };
        async.parallel( tasks, function ( err, results ) {
            output.artist.image = results.lastFmArtist.image[2]['#text'];
            if ( err ) {
                return errorHandler( err, res );
            }
            return res.json( output );
        } );

    } );

};

@@ -1752,16 +1752,1451 @@
 es ) %7B%0A%0A
+    var uri = req.query.uri;%0A%0A    var search = SpotifySearch();%0A    search.lookup( uri, %5B %22track%22 %5D, function ( err, data ) %7B%0A        if ( err ) %7B%0A            return errorHandler( err, res );%0A        %7D%0A        // start building the output object%0A        var output = %7B%0A            name: data.album.name,%0A            href: data.album.href,%0A            artist: %7B%0A                name: data.album.artist,%0A                href: data.album%5B%22artist-id%22%5D%0A            %7D,%0A            tracks: data.album.tracks%0A        %7D;%0A        var tasks = %7B%0A            lastFmAlbum: function ( callback ) %7B%0A                var params = %7B%0A                    artist: data.album.artist,%0A                    album: data.album.name%0A                %7D;%0A                LastFM.album.getInfo( params, function ( err, album ) %7B%0A                    if ( err ) %7B%0A                        return callback( err );%0A                    %7D%0A                    callback( null, album );%0A                %7D );%0A            %7D%0A        %7D;%0A        async.parallel( tasks, function ( err, results ) %7B%0A            if ( err ) %7B%0A                return errorHandler( err, res );%0A            %7D%0A            var biggestImage = results.lastFmAlbum.image.pop();%0A            output.image = biggestImage%5B%22#text%22%5D;%0A            output.released = results.lastFmAlbum.releasedate;%0A            output.wiki = results.lastFmAlbum.wiki.content;%0A            return res.json( output );%0A        %7D );%0A    %7D );%0A%0A
 %7D;%0A%0A%0Aexp

Build out album specific lookup route