All Projects → ivkos → wallhaven4j

ivkos / wallhaven4j

Licence: MIT license
Wallhaven API for Java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to wallhaven4j

arborist
Arborist is a PEG parser that supports left-associative left recursion
Stars: ✭ 17 (+0%)
Mutual labels:  parsing
iris
An easy-to-use, customizable, cross-platform, and open-source wallpaper manager.
Stars: ✭ 13 (-23.53%)
Mutual labels:  wallpaper
YAPDFKit
Yet another PDF Kit for parsing and modifying PDF's. For OS X and iOS.
Stars: ✭ 27 (+58.82%)
Mutual labels:  parsing
FullFIX
A library for parsing FIX (Financial Information eXchange) protocol messages.
Stars: ✭ 60 (+252.94%)
Mutual labels:  parsing
Wallbay
Wallpaper App developed in Flutter using Pexels API
Stars: ✭ 107 (+529.41%)
Mutual labels:  wallpaper
kotlogram2
An convinient wrapper for kotlogram
Stars: ✭ 17 (+0%)
Mutual labels:  jitpack
parser-lang
A parser combinator library with declarative superpowers
Stars: ✭ 25 (+47.06%)
Mutual labels:  parsing
Sunscreen
🌅 A macOS app that sets your wallpaper based on sunrise and sunset.
Stars: ✭ 52 (+205.88%)
Mutual labels:  wallpaper
sb-dynlex
Configurable lexer for PHP featuring a fluid API.
Stars: ✭ 27 (+58.82%)
Mutual labels:  parsing
puppeteer-autoscroll-down
Handle infinite scroll on websites by puppeteer
Stars: ✭ 40 (+135.29%)
Mutual labels:  parsing
biaffine-ner
Named Entity Recognition as Dependency Parsing
Stars: ✭ 293 (+1623.53%)
Mutual labels:  parsing
logstash-config
logstash-config provides a parser and abstract syntax tree (AST) for the Logstash config format, written in Go
Stars: ✭ 26 (+52.94%)
Mutual labels:  parsing
Chleon-Player
A minimalistic media player which adjusts the color based on the wallpaper or cover.
Stars: ✭ 29 (+70.59%)
Mutual labels:  wallpaper
php-fast-xml-parser
Fast SAX XML parser for PHP.
Stars: ✭ 25 (+47.06%)
Mutual labels:  parsing
domainatrex
😈 A library for parsing TLDs from urls in Elixir
Stars: ✭ 29 (+70.59%)
Mutual labels:  parsing
pypact
A Python package for parsing FISPACT-II output
Stars: ✭ 19 (+11.76%)
Mutual labels:  parsing
attoparser
A tiny but fast java event-style markup parser.
Stars: ✭ 46 (+170.59%)
Mutual labels:  parsing
packetevents
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. We support many protocol versions. (1.8+)
Stars: ✭ 235 (+1282.35%)
Mutual labels:  jitpack
Linux Dynamic Wallpapers
Dynamic Wallpapers for Linux
Stars: ✭ 305 (+1694.12%)
Mutual labels:  wallpaper
DownloadRedditImages
Easily download all the images from any subreddit (also select sort_type if you want hot/top/new/controversial, and also sort_time day/week/month/year/all). Randomly select downloaded images and set as wallpaper, updating every 30 mins (or whenever you want duh)!
Stars: ✭ 66 (+288.24%)
Mutual labels:  wallpaper

wallhaven4j

Release Build Status codecov

wallhaven4j is a Java library that allows you to search for wallpapers on Wallhaven and access its resources - wallpapers, collections, tags, and users.

Requirements

  • JRE 7 or higher at runtime
  • JDK 8 or higher to compile the library from source

Installation

Gradle

Step 1. Add the JitPack repository to your root build.gradle at the end of repositories:

allprojects {
    repositories {
      ...
      maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency:

dependencies {
    compile 'com.ivkos:wallhaven4j:1.3.0'
}

Maven

Step 1. Add the JitPack repository to your pom.xml file:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency:

<dependency>
    <groupId>com.ivkos</groupId>
    <artifactId>wallhaven4j</artifactId>
    <version>1.3.0</version>
</dependency>

Documentation

Javadocs can be found here.

Quick Start

Important note: This library works by parsing the HTML of Wallhaven. Site design can change unexpectedly and potentially break the library, so until a fix is pushed you are advised to handle ParseExceptions gracefully at any Wallhaven operation. See Exception Handling below for more information.

Creating a Wallhaven session

// anonymous session
Wallhaven wh = new Wallhaven();

// log in with your wallhaven account
Wallhaven wh = new Wallhaven("USERNAME", "PASSWORD");

// log in with account and save session cookies to reuse later
Wallhaven wh = new Wallhaven("USERNAME", "PASSWORD", new File("/path/to/cookies.json"));

Searching

To search for wallpapers you need to first build a SearchQuery like so, and then use the search(...) methods of the Wallhaven object:

SearchQuery query = new SearchQueryBuilder()
            .keywords("cars", "bmw")
            .categories(Category.GENERAL)
            .purity(Purity.SFW)
            .sorting(Sorting.VIEWS)
            .order(Order.DESC)
            .resolutions(new Resolution(1920, 1080), new Resolution(1280, 720))
            .ratios(new Ratio(16, 9))
            .pages(3)
            .build();
    
List<Wallpaper> carWallpapers = wh.search(query);

If a filter is omitted, its default value will be used. Default values are defined in SearchQueryDefaults.

SearchQuery query = new SearchQueryBuilder()
            .keywords("minimal")
            .categories(Category.GENERAL)
            .ratios(new Ratio(9, 16))
            .pages(3)
            .build();
            
List<Wallpaper> minimalWallpapers = wh.search(query);

If your application needs to fetch individual pages on demand, for example when doing lazy loading, you can do this like so:

SearchQuery query = new SearchQueryBuilder()
            .keywords("face")
            .categories(Category.PEOPLE)
            .sorting(Sorting.FAVORITES)
            .build();

// fetch individual pages
List<Wallpaper> page1 = wh.search(query, 1);
List<Wallpaper> page3 = wh.search(query, 3);

Getting Resources by ID

Getting resources by their IDs is easy with the methods of the Wallhaven object:

Tag nature = wh.getTag(37);
User gandalf = wh.getUser("Gandalf");
Wallpaper doggo = wh.getWallpaper(254637);
WallpaperCollection wc = wh.getWallpaperCollection("Gandalf", 2);

Exception Handling

wallhaven4j parses Wallhaven's HTML. As a consequence, parsing may break if Wallhaven changes its design. It is recommended to be prepared to handle gracefully such cases. wallhaven4j has the following exception hierarchy:

  • WallhavenException
    • ConnectionException - problem with the HTTP connection to Wallhaven
    • LoginException - logging in to Wallhaven was unsuccessful due to incorrect credentials
    • ParseException - problem parsing Wallhaven's HTML
    • ResourceNotAccessibleException - the requested resource cannot be accessed due to privacy or purity restrictions
    • ResourceNotFoundException - the requested resource cannot be found
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].