GithubHelp home page GithubHelp logo

xwilarg / boorusharp Goto Github PK

View Code? Open in Web Editor NEW
74.0 5.0 6.0 949 KB

A C# library to browse Booru websites (Gelbooru, Konachan, E621...) easily

Home Page: https://boorusharp.zirk.eu

License: MIT License

C# 99.94% Shell 0.06%
booru gelbooru image danbooru e621 e926 konachan rule34 safebooru sakugabooru

boorusharp's Introduction

BooruSharp BooruSharp.Others
NuGet NuGet
Nuget Nuget
CI Code Quality Coverage
Build (GitHub CI) Codacy Badge Codacy Badge

BooruSharp

BooruSharp is a C# library to browse Booru websites easily
You can download it from NuGet:

Install-Package BooruSharp
Install-Package BooruSharp.Others

BooruSharp currently handle the following websites:

  • booru.allthefallen.moe
  • danbooru.donmai.us
  • derpibooru.org
  • e621.net
  • e926.net
  • gelbooru.com
  • konachan.com
  • lolibooru.moe
  • ponybooru.org
  • realbooru.com
  • rule34.xxx
  • safebooru.org
  • sakugabooru.com
  • beta.sankakucomplex.com
  • twibooru.org
  • xbooru.com
  • yande.re

BooruSharp.Others allow to handle more websites that aren't booru:

  • pixiv.net

Documentation

You can either use the documentation or check the examples below
If you have any question, feel free to contact me

Features availability

Booru Multiple Random Images Post by ID Post by MD5 Tag by ID Comment API Last Comments API Wiki API Related Tag API Post Count API Favorite API Autocomplete API
Atfbooru ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ❌️
Danbooru Donmai ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Derpibooru ✔️ ✔️ ✔️ ✔️
E621 ✔️ ✔️ ✔️ ✔️
E926 ✔️ ✔️ ✔️ ✔️
Gelbooru ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Konachan ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Lolibooru ✔️ ✔️ ✔️ ✔️ ✔️
Ponybooru ✔️ ✔️ ✔️ ✔️
Realbooru ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Rule 34 ✔️ ✔️ ✔️ ✔️ ✔️
Safebooru ✔️ ✔️ ✔️ ✔️ ✔️
Sakugabooru ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ❌️
Sankaku Complex ✔️ ✔️ ✔️ ✔️
Twibooru ✔️ ✔️ ✔️ ✔️
Xbooru ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Yandere ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Pixiv ✔️ ✔️ ✔️

Additional notes on Pixiv

Pixiv also have 2 methods to download an image (ImageToByteArrayAsync) or a preview (PreviewToByteArrayAsync), it'll give you a byte array given a SearchResult

Please make note that you also need to provide at least one tag for the following methods:

  • GetLastPostsAsync
  • GetPostCountAsync
  • GetRandomPostAsync

Examples

Random image

var booru = new BooruSharp.Booru.Gelbooru();
var result = await booru.GetRandomPostAsync("hibiki_(kantai_collection)", "school_swimsuit");

Console.WriteLine("Image preview URL: " + result.PreviewUrl.AbsoluteUri + Environment.NewLine +
                  "Image URL: " + result.FileUrl.AbsoluteUri + Environment.NewLine +
                  "Image is safe: " + (result.Rating == BooruSharp.Search.Post.Rating.Safe) + Environment.NewLine +
                  "Tags on the image: " + String.Join(", ", result.Tags));

Random image (Pixiv)

var booru = new BooruSharp.Others.Pixiv();
await booru.LoginAsync("[refreshToken]"); // See https://github.com/Xwilarg/BooruSharp/#pixiv
var result = await booru.GetRandomPostAsync("シンボリルドルフ(ウマ娘)");
File.WriteAllBytes($"output{Path.GetExtension(result.FileUrl.AbsolutePath)}", await b.ImageToByteArrayAsync(result)); // Save the image in a file

Many random images at once

var booru = new BooruSharp.Booru.SankakuComplex();
var results = await booru.GetRandomPostsAsync(10, "ifrit_(arknights)", "silence_(arknights)");

Console.WriteLine(string.Join(Environment.NewLine, results.Select(x => "Random Image: " + x.FileUrl)));

Get tag

var booru = new BooruSharp.Booru.Safebooru();
var result = await booru.GetTagAsync("cirno");

Console.WriteLine("Tag type: " + result.Type + Environment.NewLine +
                  "ID: " + result.ID);

Get Wiki entry

var booru = new BooruSharp.Booru.Konachan();
var result = await booru.GetWikiAsync("loli");

Console.WriteLine("Description: " + result.Body + Environment.NewLine +
                  "ID: " + result.ID + Environment.NewLine +
                  "Created at: " + result.Creation.ToString("dd/MM/yy HH:mm:ss") + Environment.NewLine +
                  "Last update at: " + result.LastUpdate.ToString("dd/MM/yy HH:mm:ss"));

Get related tags

var booru = new BooruSharp.Booru.Yandere();
var results = await booru.GetRelatedAsync("see_through");

Console.WriteLine(String.Join(Environment.NewLine,
    results.Select(delegate (BooruSharp.Search.Related.SearchResult res) { return ("Name: " + res.Name +" (" + res.Count + ")"); })));

Get comments

var booru = new BooruSharp.Booru.Lolibooru();
var results = await booru.GetCommentAsync(134097);

Console.WriteLine(String.Join(Environment.NewLine,
    results.Select(delegate (BooruSharp.Search.Comment.SearchResult res) { return ("Author: " + res.AuthorName + ", the " + res.Creation.ToString("dd/MM/yy HH:mm:ss") + " - " + res.Body); })));

Add to favorite

var booru = new BooruSharp.Booru.Safebooru();
booru.SetBooruAuth(new BooruSharp.Booru.BooruAuth("yourUserId", "yourPasswordHash")); // See https://github.com/Xwilarg/BooruSharp/#booru
await booru.AddFavoriteAsync(1759793);

Get search autocomplete results

var booru = new BooruSharp.Booru.Safebooru();
var results = await booru.AutocompleteAsync("kasuga_");
Console.WriteLine(String.Join(Environment.NewLine, results.Select(x => "Autocomplete result:" + x.Name)));

Get all character tags containing a string

var yandere = new BooruSharp.Booru.Yandere();
var results = await yandere.GetTagsAsync("tsukiko");
Console.WriteLine(String.Join(Environment.NewLine,
	results.Where(delegate (BooruSharp.Search.Tag.SearchResult res) { return (res.Type == BooruSharp.Search.Tag.TagType.Character); })
           .Select(delegate (BooruSharp.Search.Tag.SearchResult res) { return (res.Name); })));

Authentification

Authentification is done by creating a new instance of BooruAuth is specifying it to your Booru instance

E621 / E926

userId is your username
passwordHash is your api key, to get it go to your account page and then in "Manage API Access"

Derpibooru / Poniboory / Twibooru

userId need to be an empty string
passwordHash is your api key, go on the website at the top left hover your profile icon, go in "Account", you'll see your API key there

Others booru

For booru authentification, you'll need your user id and your password hash
To get it, I advise you to go on an image, open the developer panel (F12) and go in "Network"
Then press the button to add the image to your favorite and look at the "Cookies" section of the last request Authentification

Pixiv

For Pixiv authentification, please use LoginAsync with a refresh token
To get your refresh token, you can follow this tutorial: https://gist.github.com/ZipFile/c9ebedb224406f4f11845ab700124362

Want to contribute

Feel free to open a pull request.

Need more help

Feel free to open an issue or come ask on Discord.

boorusharp's People

Contributors

dependabot[bot] avatar keelhauled avatar luciomacarine avatar n-ski avatar xwilarg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

boorusharp's Issues

GetRandomPostAsync returns the same post every time

When upgrading from 3.4.0 NuGet package to 3.5.4 I've faced a problem where GetRandomPostAsync returns the same post depending on time you're calling the method.
Code to reproduce:

using BooruSharp.Booru;

var booru = new Konachan();

for (var i = 0; i < 100; i++)
{
    var post = await booru.GetRandomPostAsync();
    Console.WriteLine($"Post ID: {post.ID}");
}

Stacktrace:

Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Post ID: 347773
Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 503 (Service Unavailable).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at BooruSharp.Booru.ABooru.GetJsonAsync(String url)
   at BooruSharp.Booru.ABooru.GetSearchResultFromUrlAsync(String url)
   at BooruSharp.Booru.ABooru.GetRandomPostAsync(String[] tagsArg)
   at Program.<Main>$(String[] args) in /Volumes/Media/Projects/ConsoleApp2/ConsoleApp2/Program.cs:line 7
   at Program.<Main>(String[] args)

Process finished with exit code 134.

Building the app using .NET SDK 6.0.202

Sankakucomplex authorization does not work

Trying to get a post with more than 5 tags...

            var booru = new BooruSharp.Booru.SankakuComplex();
            booru.Auth = new BooruSharp.Booru.BooruAuth("login", "pwHash");

            var post = await booru.GetRandomPostAsync(tags).ConfigureAwait(false);

And getting this error:

2

Login and password are taken from here:

1

Pixiv authentification no longer works

Pixiv authentification seems to have change something because all authentification attempt using BooruSharp.Other now returns an error

I'm opening this issue if someone want to help looking into that

This is related to #31

Pixiv Bookmarks?

I'm trying to port an excessively bad tool I threw together in Python to a legit netcore service, and I'm looking for Pixiv tools to replace PixivUtil2.

The big feature I'm looking for is the ability to get the latest x (pages) of bookmarked images. Is that a possibility?

I looked around in the code, and I saw no mention of it, so I figured I'd ask.

.Net Core

It would be useful to provide .Net Core builds in the NuGet package. I use this in an application i want to migrate and this is one of the only packages that do not support .Net Core

System.MissingMethodException: Method not found

I try use pixiv api: i can succesful login, but when i try call GetRandomPostAsync() i get System.MissingMethodException: Method not found

Stacktrace:
Unhandled exception. System.MissingMethodException: Method not found: 'Void BooruSharp.Search.Post.SearchResult..ctor(System.Uri, System.Uri, System.Uri, BooruSharp.Search.Post.Rating, System.Collections.Generic.IList1<System.String>, Int32, System.Nullable1, Int32, Int32, System.Nullable1, System.Nullable1, System.Nullable1<System.DateTime>, System.String, System.Nullable1, System.String)'.
at BooruSharp.Others.Pixiv.ParseSearchResult(JToken post)
at BooruSharp.Others.Pixiv.GetRandomPostAsync(String[] tagsArg)

E621 authorization

E621 seems not to authorize. I tried with (user_name, api_key) and (user_id, api_key).
But for example cub -rating:safe, which need authorization to show anything still results in empty results.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.