Skip to content

Commit

Permalink
Merge pull request #29 from Shiroechi/dev
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
Shiroechi authored Dec 17, 2020
2 parents c89b2ff + 7f19ff7 commit 12c947c
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 175 deletions.
245 changes: 123 additions & 122 deletions Booru/Booru.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Booru/Client/DanbooruDonmai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BooruDex.Booru.Client
public class DanbooruDonmai : Template.Danbooru
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="DanbooruDonmai"/> client object.
/// </summary>
Expand All @@ -14,7 +14,7 @@ public DanbooruDonmai(HttpClient httpClient = null) : base("https://danbooru.don
{

}

#endregion Constructor & Destructor
}
}
31 changes: 13 additions & 18 deletions Booru/Template/Danbooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using BooruDex.Models;

using Litdex.Security.RNG;
using Litdex.Security.RNG.PRNG;

namespace BooruDex.Booru.Template
{
Expand All @@ -25,15 +24,15 @@ public abstract class Danbooru : Booru
/// <param name="domain">URL of booru based sites.</param>
/// <param name="httpClient">Client for sending and receive http response.</param>
/// <param name="rng">Random generator for random post.</param>
public Danbooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng == null ? new SplitMix64() : rng)
public Danbooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng)
{
this.IsSafe = false;
this.HasArtistApi =
this.HasPoolApi =
this.HasTagApi =
this.HasTagRelatedApi =
this.HasWikiApi = true;
this._PostLimit = 200;
this._DefaultPostLimit = 200;
this._TagsLimit = 2;
this._PageLimit = 1000;
this._ApiVersion = "";
Expand Down Expand Up @@ -220,22 +219,18 @@ public virtual async Task<Post> PostShowAsync(uint postId)
{
var url = this.CreateBaseApiCall($"posts/{ postId }");

JsonElement obj;

using (var temp = await this.GetJsonResponseAsync<JsonDocument>(url))
using (var doc = await this.GetJsonResponseAsync<JsonDocument>(url))
{
obj = temp.RootElement.Clone();
}
// if Post is not found, it return JSON response
// containing error message

// if Post is not found, it return JSON response
// containing error message
if (doc.RootElement.TryGetProperty("success", out _))
{
throw new SearchNotFoundException($"Post with id { postId } is not found.");
}

if (obj.TryGetProperty("success", out _))
{
throw new SearchNotFoundException($"Post with id { postId } is not found.");
return this.ReadPost(doc.RootElement);
}

return this.ReadPost(obj);
}

/// <inheritdoc/>
Expand All @@ -245,17 +240,17 @@ public override async Task<Post> GetRandomPostAsync(string[] tags = null)
}

/// <inheritdoc/>
public override async Task<Post[]> GetRandomPostAsync(uint limit, string[] tags = null)
public override async Task<Post[]> GetRandomPostAsync(byte limit, string[] tags = null)
{
this.CheckTagsLimit(tags);

if (limit <= 0)
{
limit = 1;
}
else if (limit > this._PostLimit)
else if (limit > this._DefaultPostLimit)
{
limit = this._PostLimit;
limit = this._DefaultPostLimit;
}

var url = this.CreateBaseApiCall("posts") +
Expand Down
7 changes: 3 additions & 4 deletions Booru/Template/Gelbooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using BooruDex.Models;

using Litdex.Security.RNG;
using Litdex.Security.RNG.PRNG;

namespace BooruDex.Booru.Template
{
Expand All @@ -23,11 +22,11 @@ public abstract class Gelbooru : Booru
/// <param name="domain">URL of booru based sites.</param>
/// <param name="httpClient">Client for sending and receive http response.</param>
/// <param name="rng">Random generator for random post.</param>
public Gelbooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng == null ? new SplitMix64() : rng)
public Gelbooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng)
{
this.IsSafe = false;
this.HasTagApi = true;
this._PostLimit = 100; // may increased up to 1000
this._DefaultPostLimit = 100; // may increased up to 1000
this._TagsLimit = 0; // no tag limit
this._PageLimit = 20000;
this._ApiVersion = "";
Expand All @@ -42,7 +41,7 @@ public abstract class Gelbooru : Booru
protected override string CreateBaseApiCall(string query, bool json = true)
{
var sb = new StringBuilder($"{ this._BaseUrl.AbsoluteUri }index.php?page=dapi&s={ query }&q=index");

if (json)
{
sb.Append("&json=1");
Expand Down
5 changes: 2 additions & 3 deletions Booru/Template/Gelbooru02.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BooruDex.Models;

using Litdex.Security.RNG;
using Litdex.Security.RNG.PRNG;

namespace BooruDex.Booru.Template
{
Expand All @@ -22,9 +21,9 @@ public abstract class Gelbooru02 : Booru
/// <param name="domain">URL of booru based sites.</param>
/// <param name="httpClient">Client for sending and receive http response.</param>
/// <param name="rng">Random generator for random post.</param>
public Gelbooru02(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng == null ? new SplitMix64() : rng)
public Gelbooru02(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng)
{
this._PostLimit = 100;
this._DefaultPostLimit = 100;
this._TagsLimit = 0; // no tag limit
this.IsSafe = false;
this._ApiVersion = "";
Expand Down
5 changes: 2 additions & 3 deletions Booru/Template/Moebooru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BooruDex.Models;

using Litdex.Security.RNG;
using Litdex.Security.RNG.PRNG;

namespace BooruDex.Booru.Template
{
Expand All @@ -22,15 +21,15 @@ public abstract class Moebooru : Booru
/// <param name="domain">URL of booru based sites.</param>
/// <param name="httpClient">Client for sending and receive http response.</param>
/// <param name="rng">Random generator for random post.</param>
public Moebooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng == null ? new SplitMix64() : rng)
public Moebooru(string domain, HttpClient httpClient = null, IRNG rng = null) : base(domain, httpClient, rng)
{
this.IsSafe = false;
this.HasArtistApi =
this.HasPoolApi =
this.HasTagApi =
this.HasTagRelatedApi =
this.HasWikiApi = true;
this._PostLimit = 100; // may increased up to 1000
this._DefaultPostLimit = 100; // may increased up to 1000
this._TagsLimit = 6;
this._PageLimit = 0;
this._ApiVersion = "1.13.0+update.3";
Expand Down
13 changes: 9 additions & 4 deletions BooruDex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
<PackageTags>Imageboard Image Booru Danbooru Gelbooru Gelbooru02 Moebooru Yandere Konachan Safebooru Lolibooru Rule34 Behoimi Realbooru</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<Description>Library to access the booru website using public API. This library only support GET method, it means only listing and searching only.</Description>
<PackageReleaseNotes>- Code refactor
- New method for danbooru template, ArtistDetailAsync.</PackageReleaseNotes>
<Version>2.1.0</Version>
<PackageReleaseNotes>- Remove re-throw
- Refactor code
- Fix issue NULL HttpClient
- Enhancement some method behavior
</PackageReleaseNotes>
<Version>2.1.1</Version>
<AssemblyName>BooruDex</AssemblyName>
<RootNamespace>BooruDex</RootNamespace>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Shiroechi</Copyright>
<PackageId>BooruDex</PackageId>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -28,6 +31,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>D:\Project\C#\API\BooruDex\BooruDex.xml</DocumentationFile>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 20 additions & 11 deletions BooruDex.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Models/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ readonly public struct Post
/// <param name="previewWidth">The width of the preview image, in pixels.</param>
/// <param name="source">The original source of the file.</param>
public Post(
uint id,
uint id,
string postUrl,
string fileUrl,
string previewUrl,
Rating rating,
string tags,
uint size,
int height,
int width,
int? previewHeight,
string previewUrl,
Rating rating,
string tags,
uint size,
int height,
int width,
int? previewHeight,
int? previewWidth,
string source)
{
Expand Down

0 comments on commit 12c947c

Please sign in to comment.