How to get images of Discogs releases?

2.6k Views Asked by At

I want to get images of Discogs releases. Can I do it without Discogs API? They don't have links to the images in their db dumps.

2

There are 2 best solutions below

4
On

To do this without the API, you would have to load a web page and extract the image from the html source code. You can find the relevant page by loading https://www.discogs.com/release/xxxx where xxxx is the release number. Since html is just a text file, you can now extract the jpeg URL.

I don't know what your programming language is, but I'm sure it can handle String functions, like indexOf and subString. You could extract the html's OG:Image content for picture.

So taking an example: https://www.discogs.com/release/8140515

Compare page at : https://www.discogs.com/release/8140515 with extracted URL image below.

0
On

This is how to do it with Java & Jsoup library.

  • get HTML page of the release
  • parse HTML & get <meta property="og:image" content=".." /> to get content value
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class DiscogRelease {

    private final String url;

    public DiscogRelease(String url) {
        this.url = url;
    }

    public String getImageUrl() {
        try {
            Document doc = Jsoup.connect(this.url).get();
            Elements metas = doc.head().select("meta[property=\"og:image\"]");
            if (!metas.isEmpty()) {
                Element element = metas.get(0);
                return element.attr("content");
            }
        } catch (IOException ex) {
            Logger.getLogger(DiscogRelease.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

}