项目作者: David-Desmaisons

项目描述 :
Discogs API C# Client
高级语言: C#
项目地址: git://github.com/David-Desmaisons/DiscogsClient.git
创建时间: 2016-05-16T16:12:47Z
项目社区:https://github.com/David-Desmaisons/DiscogsClient

开源协议:MIT License

下载


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

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

Token based authentication

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

Search The DataBase

Using IObservable:

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

Using IEnumerable:

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

Get Release, Master, Artist or Label Information

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

Download Image

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

OAuth: Authorize new user

  1. //Create authentificator information: you should fournish real keys here
  2. var oAuthConsumerInformation = new OAuthConsumerInformation("consumerKey", "consumerSecret");
  3. //Create Authentifier client
  4. var discogsAuthentifierClient = new DiscogsAuthentifierClient(oAuthConsumerInformation);
  5. //Retreive Token and Token secret
  6. 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:

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

See DiscogsClientTest and DiscogsAuthenticationConsole for full samples of available APIs.