Skip to content

Repository files navigation

ImageBoard (Booru) API

Maven Central

ImageBoard API is a simple asynchronous Java API wrapper around the most popular danbooru-compatible booru APIs. Pretty much, it is a Booru library for Java. The interface also supports other types of custom boards given a little tweaking. Releases are published in Maven Central.

This helps you craft requests and search/fetch images on the danbooru-compatible imageboards (boorus) that exist out there.

Supported Booru Image Boards

  • Rule34 (requires authentication)
  • e621
  • Konachan
  • Yande.re
  • Danbooru
  • Safebooru
  • Gelbooru (requires authentication)
  • e926

Creating your own ImageBoard instance is possible, but would require a little tweaking. Please refer to the ImageBoards.java and CustomBoard.java to set up boards that are not included with this library. The boorus listed above are available by default with no further configuration required by the user.

Adding ImageBoardAPI to your project

imageboard-api is available in Maven Central (Sonatype). Check the Sonatype respository for more information

Gradle

repositories {
mavenCentral()
}
dependencies {
implementation 'io.github.kodehawa:imageboard-api:3.0.0'
}

Set Up

There is a ImageBoards class located under utils, that one contains static, pre-created ImageBoardAPI objects for you, but you can roll your own.

Implementation

You can find implementation details and a lot of examples in the tests for this project and in Mantaro

The User-Agent must be initialized to make requests. You can initialize it with ImageBoard.setUserAgent(). The default one was blocked by most imageboards, setting your own is the best to avoid UA blocking.

If a board requires authentication, you can provide a BoardAuthorizationProvider when constructing ImageBoard.
The provider is called in two stages:

  1. URL stage (applyToUrl) to inject query/path auth
  2. Request stage (applyToRequest) to inject headers

For simple cases, use the built-in helpers like HeaderAuthorization or UrlParameterAuthorization.

Note: This only really applies to custom boards, the default ones either don't require authentication or have a simplified construction method that just enables you to pass the required credentials without needing to worry about the auth provider.

Examples

Random Images

importnet.kodehawa.lib.imageboards.entities.BoardImage;
importnet.kodehawa.lib.imageboards.DefaultImageBoards;
publicclassRandomImages {
publicstaticvoidmain(String[] args) {
// Asynchronous GET// 60 random imagesDefaultImageBoards.KONACHAN.get().async(images -> {
for (BoardImageimage : images) System.out.println(image.getURL());
});
// Asynchronous GET// 30 random imagesImageBoards.KONACHAN.get(30).async(images -> {
for (BoardImageimage : images) System.out.println(image.getURL());
});
// Blocking GET// 5 random imageBoardImageimage = DefaultImageBoards.KONACHAN.get(5).blocking().get(0);
System.out.println(image.getURL());
System.out.println(image.getRating());
System.out.println(image.getTags());
System.out.println(image.getHeight());
System.out.println(image.getWidth());
// Authenticated image board callsBoardImageimage = DefaultImageBoards.createGelbooru("authToken","userId").get(5).blocking().get(0);
}
}

Image Tag Search

importnet.kodehawa.lib.imageboards.entities.BoardImage;
importnet.kodehawa.lib.imageboards.DefaultImageBoards;
publicclassTagImages {
publicstaticvoidmain(String[] args) {
// Asynchronous GET// 20 images tagged with animal_earsDefaultImageBoards.KONACHAN.search(20, "animal_ears").async(images -> {
for (BoardImageimage : images) System.out.println(image.getURL());
});
// Blocking GET// 60 images tagged with animal_earsBoardImageimage = DefaultImageBoards.KONACHAN.search("animal_ears").blocking().get(0);
System.out.println(image.getURL());
System.out.println(image.getRating());
System.out.println(image.getTags());
System.out.println(image.getHeight());
System.out.println(image.getWidth());
}
}

Filter bad results

You might want to filter BoardImage#isPending, as the tags/rating of those is almost guaranteed to never be correct.

For filtering other results, you can filter tags from BoardImage#getTags and use a .contains call on the list.

About

Simple asynchronous Java API wrapper around the most popular danbooru-compatible (Konachan, Yande.re, Danbooru, Gelbooru, etc) booru APIs.

Topics

Resources

Stars

55 stars

Watchers

4 watching

Forks

Releases

Used by

Contributors

Languages