Skip to content

Commit

Permalink
bukl update
Browse files Browse the repository at this point in the history
release v1
  • Loading branch information
Shiroechi committed Nov 13, 2020
1 parent 6f3b67d commit d29bc02
Show file tree
Hide file tree
Showing 16 changed files with 899 additions and 116 deletions.
164 changes: 160 additions & 4 deletions Booru/Booru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public abstract class Booru
/// </summary>
/// <param name="domain">URL of booru based sites.</param>
/// <param name="httpClient">Client for sending and receive http response.</param>
public Booru(string domain, HttpClient httpClient) : this(domain, null, new JSF32())
public Booru(string domain, HttpClient httpClient = null) : this(domain, httpClient, new JSF32())
{

}
Expand Down Expand Up @@ -144,7 +144,7 @@ public HttpClient HttpClient

if (!this._HttpClient.DefaultRequestHeaders.Contains("User-Agent"))
{
this._HttpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 Unknown");
this._HttpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
}
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ protected async Task<string> GetJsonAsync(string url)
}
else
{
throw new HttpResponseException("Unexpected error occured");
throw new HttpResponseException("Unexpected error occured.");
}
}
}
Expand Down Expand Up @@ -292,13 +292,169 @@ protected Rating ConvertRating(string rating)
/// <returns></returns>
public bool Authenticate(string username, string password)
{
throw new NotImplementedException();
throw new NotImplementedException($"Method { nameof(Authenticate) } is not implemented yet.");
this._Username = username;
this._Password = this._PasswordSalt.Replace("{}", password);

return false;
}

#region Artist

/// <summary>
/// Get a list of artists.
/// </summary>
/// <param name="name">The name (or a fragment of the name) of the artist.</param>
/// <param name="page">The page number.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Artist[]> ArtistListAsync(string name, uint page = 0)
{
throw new NotImplementedException($"Method { nameof(ArtistListAsync) } is not implemented yet.");
}

#endregion Artist

#region Pool

/// <summary>
/// Search a pool.
/// </summary>
/// <param name="title">The title of pool.</param>
/// <param name="page">Tha page number.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Pool[]> PoolList(string title, uint page = 0)
{
throw new NotImplementedException($"Method { nameof(PoolList) } is not implemented yet.");
}

/// <summary>
/// Get list of post inside the pool.
/// </summary>
/// <param name="poolId">The <see cref="Pool"/> id.</param>
/// <param name="page">The page number.</param>
/// <returns></returns>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Post[]> PoolPostList(uint poolId, uint page = 0)
{
throw new NotImplementedException($"Method { nameof(PoolPostList) } is not implemented yet.");
}

#endregion Pool

#region Post

/// <summary>
/// Get a list of <see cref="Post"/>.
/// </summary>
/// <param name="limit">How many <see cref="Post"/> to retrieve.</param>
/// <param name="page">The page number.</param>
/// <param name="tags">The tags to search for.</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
/// <exception cref="SearchNotFoundException"></exception>
public virtual async Task<Post[]> PostListAsync(uint limit, string[] tags, uint page = 0)
{
throw new NotImplementedException($"Method { nameof(PostListAsync) } is not implemented yet.");
}

/// <summary>
/// Search a single random post from booru with the given tags.
/// </summary>
/// <param name="tags"><see cref="Tag"/> to search.</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
/// <exception cref="SearchNotFoundException"></exception>
public virtual async Task<Post> GetRandomPostAsync(string[] tags = null)
{
throw new NotImplementedException($"Method { nameof(GetRandomPostAsync) } is not implemented yet.");
}

/// <summary>
/// Search some post from booru with the given tags.
/// </summary>
/// <param name="tags"><see cref="Tag"/> to search.</param>
/// <param name="limit">How many post to retrieve.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Post[]> GetRandomPostAsync(uint limit, string[] tags = null)
{
throw new NotImplementedException($"Method { nameof(GetRandomPostAsync) } is not implemented yet.");
}

#endregion Post

#region Tag

/// <summary>
/// Get a list of tag that contains
/// </summary>
/// <param name="name">The tag names to query.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Tag[]> TagListAsync(string name)
{
throw new NotImplementedException($"Method { nameof(TagListAsync) } is not implemented yet.");
}

/// <summary>
/// Get a list of related tags.
/// </summary>
/// <param name="name">The tag names to query.</param>
/// <param name="type">Restrict results to tag type (can be general, artist, copyright, or character).</param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<TagRelated[]> TagRelatedAsync(string name, TagType type = TagType.General)
{
throw new NotImplementedException($"Method { nameof(TagRelatedAsync) } is not implemented yet.");
}

#endregion Tag

#region Wiki

/// <summary>
/// Search a wiki content.
/// </summary>
/// <param name="title">Wiki title.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="AuthenticationException"></exception>
/// <exception cref="HttpRequestException"></exception>
/// <exception cref="HttpResponseException"></exception>
public virtual async Task<Wiki[]> WikiListAsync(string title)
{
throw new NotImplementedException($"Method { nameof(WikiListAsync) } is not implemented yet.");
}

#endregion Wiki

#endregion Public Method
}
}
16 changes: 0 additions & 16 deletions Booru/Client/Danbooru.cs

This file was deleted.

21 changes: 21 additions & 0 deletions Booru/Client/DanbooruDonmai.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Net.Http;

namespace BooruDex.Booru.Client
{
public class DanbooruDonmai : Template.Danbooru
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="DanbooruDonmai"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public DanbooruDonmai(HttpClient httpClient = null) : base("https://danbooru.donmai.us/", httpClient)
{

}

#endregion Constructor & Destructor

}
}
23 changes: 23 additions & 0 deletions Booru/Client/Gelbooru.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;

namespace BooruDex.Booru.Client
{
public class Gelbooru : Template.Gelbooru
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Gelbooru"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Gelbooru(HttpClient httpClient = null) : base("http://gelbooru.com/", httpClient)
{

}

#endregion Constructor & Destructor
}
}
6 changes: 5 additions & 1 deletion Booru/Client/Konachan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ namespace BooruDex.Booru.Client
{
public class Konachan : Moebooru
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Konachan"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Konachan(HttpClient httpClient = null) : base("http://konachan.com/", httpClient)
{

this._PasswordSalt = "So-I-Heard-You-Like-Mupkids-?--{}--";
}

#endregion Constructor & Destructor
}
}
25 changes: 24 additions & 1 deletion Booru/Client/Lolibooru.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
using System.Net.Http;

using BooruDex.Booru.Template;
using BooruDex.Models;

using Newtonsoft.Json.Linq;

namespace BooruDex.Booru.Client
{
public class Lolibooru : Moebooru
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Lolibooru"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Lolibooru(HttpClient httpClient = null) : base("http://lolibooru.moe/", httpClient)
{
// lolibooru tag limit can more than 6
this._TagsLimit = 0; // not tag limit
this._PasswordSalt = "--{}--";
}

#endregion Constructor & Destructor

#region Protected Override Method

protected override Tag ReadTag(JToken json)
{
var item = json;
return new Tag(
item["id"].Value<uint>(),
item["name"].Value<string>(),
(TagType)item["tag_type"].Value<int>(),
item["post_count"].Value<uint>()
);
}

#endregion Protected Override Method
}
}
22 changes: 22 additions & 0 deletions Booru/Client/Realbooru.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Net.Http;

using BooruDex.Booru.Template;

namespace BooruDex.Booru.Client
{
public class Realbooru : Gelbooru02
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Realbooru"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Realbooru(HttpClient httpClient = null) : base("http://realbooru.com/", httpClient)
{

}

#endregion Constructor & Destructor
}
}
22 changes: 22 additions & 0 deletions Booru/Client/Rule34.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Net.Http;

using BooruDex.Booru.Template;

namespace BooruDex.Booru.Client
{
public class Rule34 : Gelbooru02
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Rule34"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Rule34(HttpClient httpClient = null) : base("https://rule34.xxx/", httpClient)
{

}

#endregion Constructor & Destructor
}
}
22 changes: 22 additions & 0 deletions Booru/Client/Safebooru.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Net.Http;

using BooruDex.Booru.Template;

namespace BooruDex.Booru.Client
{
public class Safebooru : Gelbooru02
{
#region Constructor & Destructor

/// <summary>
/// Create <see cref="Safebooru"/> client object.
/// </summary>
/// <param name="httpClient">Http client for sending request and recieving response.</param>
public Safebooru(HttpClient httpClient = null) : base("https://safebooru.org/", httpClient)
{

}

#endregion Constructor & Destructor
}
}
Loading

0 comments on commit d29bc02

Please sign in to comment.