factormystic / lastfm

Portable Last.fm SDK for modern .NET platforms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inflatable Last.fm .NET SDK Build status

MIT licensed. Maintained by @rikkilt.

Feature request? Bug? Or just wanna help out? Check out the issues on GitHub.

If you have comments or need some help, post to our chat room on ![Gitter](https://badges.gitter.im/Join Chat.svg).

Project Goals

  • Provide complete, and completely tested, bindings for the Last.fm REST API for use on modern .NET platforms.
  • Provide functionality beyond API bindings, to spread the joy of Last.fm to developers everywhere.
  • To be the very best, like no-one ever was.

Quickstart

Installing the SDK

If you want to work with the Last.fm API, you should install the NuGet package. Search for Inflatable.Lastfm in the NuGet package browser or run this commmand in the NuGet package console:

PM> Install-Package Inflatable.Lastfm

You can also clone this repo and build from source, referencing IF.Lastfm.Core in your project. Keep in mind this requires a version of Visual Studio that supports portable class libraries and PCL profile 259 - Visual Studio 2012/3 Pro or higher running on Windows 8 or higher.

Using the SDK

Once IF.Lastfm.Core is referenced, it's pretty simple to get started. First, sign up for Last.fm API access if you haven't already

This is how to get album info:

var auth = new LastAuth("apikey", "apisecret");
var albumApi = new AlbumApi(auth); // this is an unauthenticated call to the API
var response = await albumApi.GetAlbumInfoAsync("Grimes", "Visions");
var visions = response.Content; // visions is a LastAlbum

For methods that return several items, you can simply iterate over the response

var pageResponse = await artistApi.GetTopTracksForArtistAsync("Ben Frost", page: 5, itemsPerPage: 100);

foreach (var wallOfSound in pageResponse)
{
	// wallOfSound is a LastTrack
}

Several API methods require user authentication. Once you have your user's Last.fm username and password:

var auth = new LastAuth("apikey", "apisecret");

// wait for authentication
var response = await auth.GetSessionTokenAsync("username", "pass");

if (response.Success && auth.HasAuthenticated) {
	var trackApi = new TrackApi(auth);
	var loved = await trackApi.LoveTrackAsync("CIRCLONT6A [141.98][Syrobonkus mix]", "Aphex Twin");
}

Some documentation is available on the GitHub wiki. You can also check the Windows Phone demo project for some example code.

Any problems, just ask in Gitter.

Dependency Injection

The SDK is built to work with IoC libraries like MvvmLight and Ninject. To inject an API as a dependency to a viewmodel, you just need to register ILastAuth to an instance of LastAuth:

// mvvmlight
var auth = new LastAuth("apikey", "apisecret");
SimpleIoc.Default.Register<ILastAuth>(() => auth);

// ...

var artistApi = ServiceLocator.Current.GetInstance<ArtistApi>();
var response = await artistApi.GetArtistInfoAsync("The Knife");
var theKnife = artist.Content;

Implemented Features

Check the progress report for a list of implemented methods.

Planned Features

Everyone working with Last.fm is likely to need similar kinds of features, so it makes sense for us to work on them together. Here are a few things to look for in the future:

  • Fire-and-forget scrobbling: transparent handling of scrobbles made offline
  • Built-in request cache for API calls
  • Improved identification of poorly tagged tracks using audio fingerprints and the MusicBrainz API

If you have any other neat ideas, post them in our Gitter so we can talk 😄

Platform Compatibility

The current PCL profile is

  • .NET Framework 4.5
  • Windows 8.0
  • Windows Phone 8.1
  • Windows Phone Silverlight 8

If you need support for Mono, Windows Phone 7, or another .NET platform, please ask: the current profile was chosen to reduce dependencies for the most common use cases. The SDK should be trivial to port to any platform which supports Async, HttpClient and Json.Net.

About

Portable Last.fm SDK for modern .NET platforms.

License:Other


Languages

Language:C# 95.2%Language:Smalltalk 4.2%Language:PowerShell 0.6%