simple-lastfm

simple last.fm api for node.js

#Simple-Lastfm

A simple nodejs library to interface with the last.fm API

Installation

npm install simple-lastfm

Examples

First, you'll need to get an API key from last.fm: http://www.last.fm/api/account.

Once you have your API key and API secret, you'll need to generate a session key, after which you can then start to scrobble:

var Lastfm = require('simple-lastfm');

var lastfm = new Lastfm({
    api_key: 'xxx',
    api_secret: 'xxx',
    username: 'xxx',
    password: 'xxx'
});

lastfm.getSessionKey(function(result) {
    console.log("session key = " + result.session_key);
    if(result.success) {
        lastfm.scrobbleNowPlayingTrack({
            artist: 'Ratatat',
            track: 'Seventeen Years',
            callback: function(result) {
                console.log("in callback, finished: ", result);
            }
        });
        lastfm.scrobbleTrack({
            artist: 'Bonobo',
            track: 'Black Sands',
            callback: function(result) {
                console.log("in callback, finished: ", result);
            }
        });
        lastfm.loveTrack({
            artist: 'Electrelane',
            track: 'Suitcase',
            callback: function(result) {
                console.log("in callback, finished: ", result);
            }
        });
        lastfm.unloveTrack({
            artist: 'something crap',
            track: 'no thanks',
            callback: function(result) {
                console.log("in callback, finished: ", result);
            }
        });
    } else {
        console.log("Error: " + result.error);
    }
});

#Documentation

init ( options )

options must be an object with the following required keys:

  • api_key
  • api_secret
  • username
  • password

Optional parameters:

  • session_key
  • debug

I recommend you save the session key and reuse it when possible. Debug should be true or false. By default it is false. Set it to true to have some console commands outputted.

getSessionKey ( callback )

callback: A function which receives a single object. On success, this object looks like:

{
        success: true,
        session_key: 'xxx'
    }

On failure:

{
        success: false,
        error: 'A text description of the error from last.fm'
    }

Note:Right now When a session key is successfully received, it automatically gets saved into the lastfm instance (in the above code, you could access it as lastfm.session_key)

scrobbleTrack ( options )

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, error: 'text description of the error']}.
  • timestamp: The timestamp for this scrobble. If omitted, uses the current date/time. Use number of seconds (NOT milliseconds!) since the UNIX epoch.

loveTrack (options)

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, error: 'text description of the error']}.

unloveTrack (options)

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, error: 'text description of the error']}.

getArtistInfo (options)

Required parameters:

  • artist

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, artistInfo: {}, error: 'text description of the error']}.

getTrackInfo (options)

Required parameters:

  • artist
  • track

Optional parameters:

  • callback: A function which receives a single object, of the form { success: true|false[, trackInfo: {}, error: 'text description of the error']}.

getTags (options)

Required parameters:

  • artist

Optional parameters:

  • track
  • callback: A function which receives a single object, of the form { success: true|false[, tags: {}, error: 'text description of the error']}.

getPlays (options)

Required parameters:

  • artist

Optional parameters:

  • track: The name of the track. If ommitted, method will return number of artist plays.
  • callback: A function which receives a single object, of the form { success: true|false[, plays: #, error: 'text description of the error']}.

Repository

https://github.com/atomjack/simple-lastfm


上一篇:json-bignum
下一篇:ttapi

相关推荐

  • 每日一道算法题 - SimpleSymbols(easy-5)

    虽然都是很简单的算法,每个都只需5分钟左右,但写起来总会遇到不同的小问题,希望大家能跟我一起每天进步一点点。 更多的小算法练习,可以查看我的文章。 规则 Using the JavaScript...

    2 年前
  • 基于vue-cli-simple、ElementUI的TODOS案例

    案例以教程的一个vue项目作为基础进行改造,包括通过使用ElementUI进行页面布局改造,使用了其中的tab、按钮、table、提示等组件。 另外调整使用了vuemoment,可以不用自己写日期的转...

    2 年前
  • 在 Vue-CLI 中引入 simple-mock 快速实现简易的 API Mock 接口数据模拟

    你可能只是需要一个简单省事的 API Mock 方案,那么不如试试 simple mock? 本文以 为例介绍引入 实现前端开发数据模拟的步骤。 本质上这里介绍的是在 中配置 实现 API...

    1 年前
  • webpack-simple-progress-plugin

    webpack plugin for showing simple progress bar webpacksimpleprogressplugin webpacksimpleprogresspl...

    1 年前
  • typescript-simple

    Simple API to compile TypeScript code string to JavaScript. That's all typescriptsimple ====== Sim...

    1 年前
  • ts-simple-ast

    TypeScript compiler wrapper for static analysis and code manipulation. tssimpleast ============= ...

    2 年前
  • simplex-noise

    simplexnoise is a fast simplex noise implementation in Javascript. Works in node and in the browser....

    2 年前
  • simpleui

    A simple UI framework for building simple web projects. Simple UI A simple UI framework for buil...

    2 年前
  • simpletime

    Convert to and from various time formats. Get manipulated time values. simpletime ========== (c)Bum...

    6 个月前
  • simplestatemanager

    SimpleStateManager is a library that allows you to enable and disable JavaScript based on the charac...

    2 年前

官方社区

扫码加入 JavaScript 社区