BooruSharp | BooruSharp.Others |
---|---|
CI | Code Quality | Coverage |
---|---|---|
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:
BooruSharp.Others allow to handle more websites that aren't booru:
You can either use the documentation or check the examples below \ If you have any question, feel free to contact me
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 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | ❌ |
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:
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));
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
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)));
var booru = new BooruSharp.Booru.Safebooru();
var result = await booru.GetTagAsync("cirno");
Console.WriteLine("Tag type: " + result.Type + Environment.NewLine +
"ID: " + result.ID);
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 + ")"); })));
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); })));
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);
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)));
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 is done by creating a new instance of BooruAuth is specifying it to your Booru instance
userId is your username \ passwordHash is your api key, to get it go to your account page and then in "Manage API Access"
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
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
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
Feel free to open a pull request.
Feel free to open an issue or come ask on Discord.