项目作者: Kodehawa

项目描述 :
Simple asynchronous Java API wrapper around the most popular danbooru-compatible (Konachan, Yande.re, Danbooru, Gelbooru, etc) APIs.
高级语言: Java
项目地址: git://github.com/Kodehawa/imageboard-api.git
创建时间: 2017-09-07T20:34:38Z
项目社区:https://github.com/Kodehawa/imageboard-api

开源协议:Apache License 2.0

下载


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
  • e621
  • Konachan
  • Yande.re
  • Danbooru
  • Safebooru
  • Gelbooru
  • 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

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. implementation 'io.github.kodehawa:imageboard-api:2.6.1.1'
  6. }

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.

Examples

Random Images

  1. import net.kodehawa.lib.imageboards.entities.BoardImage;
  2. import net.kodehawa.lib.imageboards.DefaultImageBoards;
  3. public class RandomImages {
  4. public static void main(String[] args) {
  5. // Asynchronous GET
  6. // 60 random images
  7. DefaultImageBoards.KONACHAN.get().async(images -> {
  8. for (BoardImage image : images) System.out.println(image.getURL());
  9. });
  10. // Asynchronous GET
  11. // 30 random images
  12. ImageBoards.KONACHAN.get(30).async(images -> {
  13. for (BoardImage image : images) System.out.println(image.getURL());
  14. });
  15. // Blocking GET
  16. // 5 random image
  17. BoardImage image = DefaultImageBoards.KONACHAN.get(5).blocking().get(0);
  18. System.out.println(image.getURL());
  19. System.out.println(image.getRating());
  20. System.out.println(image.getTags());
  21. System.out.println(image.getHeight());
  22. System.out.println(image.getWidth());
  23. }
  24. }
  1. import net.kodehawa.lib.imageboards.entities.BoardImage;
  2. import net.kodehawa.lib.imageboards.DefaultImageBoards;
  3. public class TagImages {
  4. public static void main(String[] args) {
  5. // Asynchronous GET
  6. // 20 images tagged with animal_ears
  7. DefaultImageBoards.KONACHAN.search(20, "animal_ears").async(images -> {
  8. for (BoardImage image : images) System.out.println(image.getURL());
  9. });
  10. // Blocking GET
  11. // 60 images tagged with animal_ears
  12. BoardImage image = DefaultImageBoards.KONACHAN.search("animal_ears").blocking().get(0);
  13. System.out.println(image.getURL());
  14. System.out.println(image.getRating());
  15. System.out.println(image.getTags());
  16. System.out.println(image.getHeight());
  17. System.out.println(image.getWidth());
  18. }
  19. }

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.