mfischbo / java-discogs-client

A java client for the public API of discogs.com
Apache License 2.0
1 stars 2 forks source link

How to find Album Covers and Artists Images #3

Closed goxr3plus closed 6 years ago

goxr3plus commented 6 years ago

Hi hello :) , i would like to use your library with XR3Player (JavaFX Media Player ) for downloading Album Covers and Artists Images :)

Can i have an example on how to do it :) ?

mfischbo commented 6 years ago

Hey! Sorry, for the late reply. Haven't checked in on github for a while. Basically you can retrieve images by fetching a release and load the image from the URL. Should look something like this:

DiscogsClient client = new DiscogsClient();

// Image retrieval requires a authenticated client. Different strategies can be found in the security
// package
UsernamePasswordAuthenticationStrategy authStrategy = new UsernamePasswordAuthenticationStrategy("username", "password");
DatabaseOperations dbOperations = client.getDatabaseOperations(authStrategy);

try {
    SearchResult result = dbOperations.search("Art Blakey", new PageRequest());
    ReleaseSearchResult releaseResult = result.getReleaseResults().get(0);

    Release release = dbOperations.getRelease(releaseResult.getId());
    InputStream imageStream = dbOperations.getImage(release.getImages().get(0).getUri());

} catch (ClientException clientException) {
    // handle exception
}

In order to retrieve images from the API please also have a look here https://www.discogs.com/developers/#page:images

So basically you just need to retrieve a Release (e.g. through a search operation) and then load the image from the provided list of images.

goxr3plus commented 6 years ago

Wish you will continue the support of this library :) :)