/DiscogsClient

Discogs API C# Client

Primary LanguageC#MIT LicenseMIT

DiscogsClient

Build status NuGet Badge MIT License

C# Client library for Discogs API v2.0

Check demo application Music.Cover.Finder

Features

  • Include API to authorize user (generating OAuth1.0 token and token secret)
  • Full support to DataBase API including image download
  • Support of identity API
  • Transparent support of rate limit
  • Asynchroneous and cancellable API using Tasks
  • Transparent management of pagination using none blocking API (Reactive IObservable) or IEnumerable

Sample usage

Create discogs client

Oauth authentication

  //Create authentication object using private and public keys: you should fournish real keys here
  var oAuthCompleteInformation = new OAuthCompleteInformation("consumerKey", 
                                  "consumerSecret", "token", "tokenSecret");
  //Create discogs client using the authentication
  var discogsClient = new DiscogsClient(oAuthCompleteInformation);

Token based authentication

  //Create authentication based on Discogs token
  var tokenInformation = new TokenAuthenticationInformation("my-token");
  //Create discogs client using the authentication
  var discogsClient = new DiscogsClient(tokenInformation);

Search The DataBase

Using IObservable:

var discogsSearch = new DiscogsSearch()
{
  artist = "Ornette Coleman",
  release_title = "The Shape Of Jazz To Come"
};
    
//Retrieve observable result from search
var observable = _DiscogsClient.Search(discogsSearch);

Using IEnumerable:

//Alternatively retreive same result as enumerable 
var enumerable = _DiscogsClient.SearchAsEnumerable(discogsSearch);

Get Release, Master, Artist or Label Information

var release = await _DiscogsClient.GetReleaseAsync(1704673);
var master = await _DiscogsClient.GetMasterAsync(47813);
var artist = await _DiscogsClient.GetArtistAsync(224506);
var label = await _DiscogsClient.GetLabelAsync(125);

Download Image

//Retrieve Release information
var res = await _DiscogsClient.GetMasterAsync(47813);
  
//Download the first image of the release
await _DiscogsClient.SaveImageAsync(res.images[0], Path.GetTempPath(), "Ornette-TSOAJTC");

OAuth: Authorize new user

//Create authentificator information: you should fournish real keys here
var oAuthConsumerInformation = new OAuthConsumerInformation("consumerKey", "consumerSecret");
  
//Create Authentifier client
var discogsAuthentifierClient = new DiscogsAuthentifierClient(oAuthConsumerInformation);

//Retreive Token and Token secret 
var oauth = discogsClient.Authorize(s => Task.FromResult(GetToken(s))).Result;

Authorize takes a Func< string, Task< string>> as parameter, receiving the authentication url and returning the corresponding access key. Trivial implementation:

private static string GetToken(string url)
{
  Console.WriteLine("Please authorize the application and enter the final key in the console");
  Process.Start(url);
  return Console.ReadLine();
}

See DiscogsClientTest and DiscogsAuthenticationConsole for full samples of available APIs.