BooruSharp 3.5.5

.NET Standard 2.0
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package BooruSharp --version 3.5.5
NuGet\Install-Package BooruSharp -Version 3.5.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BooruSharp" Version="3.5.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BooruSharp --version 3.5.5
#r "nuget: BooruSharp, 3.5.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install BooruSharp as a Cake Addin
#addin nuget:?package=BooruSharp&version=3.5.5

// Install BooruSharp as a Cake Tool
#tool nuget:?package=BooruSharp&version=3.5.5

BooruSharp

BooruSharp is a C# library to browse Booru websites easily<br/> 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
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"));
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 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.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BooruSharp:

Package Downloads
BooruSharp.Others

Extension of BooruSharp to handle non-booru websites and handle them like the others

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0-beta 54 1/10/2023
3.5.5 439 9/28/2022
3.5.4 960 8/18/2022
3.5.3 210 8/17/2022
3.5.3-beta 65 8/14/2022
3.5.2-beta 68 8/12/2022
3.5.1-beta 66 8/12/2022
3.5.0-beta 66 8/12/2022
3.4.0 409 8/11/2022
3.3.0 344 6/19/2022
3.2.0 261 5/31/2022
3.1.0 812 3/20/2022
3.0.4 622 1/19/2022
3.0.3 1,408 5/21/2021
3.0.2 1,126 2/5/2021
3.0.1 756 11/17/2020
3.0.0 487 11/12/2020
2.11.0 1,075 9/7/2020
2.10.0 843 8/18/2020
2.9.0 748 8/17/2020
2.8.1 423 8/17/2020
2.8.0 702 8/2/2020
2.7.0 547 7/9/2020
2.6.1 406 7/8/2020
2.6.0 411 7/8/2020
2.5.0 372 7/7/2020
2.4.0 352 7/6/2020
2.3.1 430 6/23/2020
2.3.0 416 6/22/2020
2.2.0 363 6/22/2020
2.1.0 470 6/4/2020
2.0.3 941 3/24/2020
2.0.2 403 3/24/2020
2.0.1 398 3/23/2020
2.0.0 413 3/21/2020
1.4.8 541 2/21/2020
1.4.7 450 1/31/2020
1.4.6 529 9/24/2019
1.4.4 894 8/1/2019
1.4.3 570 7/13/2019
1.4.2 700 5/30/2019
1.4.1 768 4/8/2019
1.4.0 630 2/27/2019
1.3.6 815 1/10/2019
1.3.5 674 1/5/2019
1.3.3 826 10/17/2018
1.3.1 772 8/21/2018
1.3.0 803 8/14/2018
1.2.0 770 7/31/2018
1.1.1 731 7/30/2018
1.1.0 755 7/27/2018
1.0.1 788 7/22/2018