Compare commits

..

9 Commits

  1. 4
      Booru.Net.Tests/Booru.Net.Tests.csproj
  2. 52
      Booru.Net.Tests/Program.cs
  3. 12
      Booru.Net/Booru.Net.csproj
  4. 33
      Booru.Net/Clients/DanbooruClient.cs
  5. 39
      Booru.Net/Clients/E621Client.cs
  6. 33
      Booru.Net/Clients/GelbooruClient.cs
  7. 33
      Booru.Net/Clients/KonaChanClient.cs
  8. 37
      Booru.Net/Clients/RealbooruClient.cs
  9. 33
      Booru.Net/Clients/Rule34Client.cs
  10. 33
      Booru.Net/Clients/SafeBooruClient.cs
  11. 33
      Booru.Net/Clients/YandereClient.cs
  12. 21
      Booru.Net/Converters/TagGroupConverter.cs
  13. 13
      Booru.Net/Interfaces/IIndexBooruClient.cs
  14. 13
      Booru.Net/Interfaces/IPHPBooruClient.cs
  15. 13
      Booru.Net/Interfaces/IPostBooruClient.cs
  16. 13
      Booru.Net/Interfaces/IPostsBooruClient.cs
  17. 13
      Booru.Net/Interfaces/IPostsWrappedBooruClient.cs
  18. 11
      Booru.Net/Models/Boards/DanBooruImage.cs
  19. 18
      Booru.Net/Models/Boards/E621Image.cs
  20. 25
      Booru.Net/Models/Boards/E621ImageFlags.cs
  21. 28
      Booru.Net/Models/Boards/E621ImageSource.cs
  22. 4
      Booru.Net/Models/Boards/E621Score.cs
  23. 6
      Booru.Net/Models/Boards/GelbooruImage.cs
  24. 4
      Booru.Net/Models/BooruImage.cs
  25. 26
      README.md

@ -3,8 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyVersion>2020.3.24.0</AssemblyVersion>
<FileVersion>2020.3.24.0</FileVersion>
<AssemblyVersion>2020.4.28.0</AssemblyVersion>
<FileVersion>2020.4.28.0</FileVersion>
</PropertyGroup>
<ItemGroup>

@ -21,43 +21,61 @@ namespace Booru.Net.Tests
{
try
{
IEnumerable<BooruImage> posts = null;
Console.WriteLine(client);
switch(client)
List<string> tags = new List<string>{ "corona", "-cum" };
switch (client)
{
case 0:
posts = await new DanbooruClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new DanbooruClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z=>tags.Contains(z) != null)));
}
break;
case 1:
var p = await new E621Client().GetImagesAsync().ConfigureAwait(false);
Console.WriteLine(p.Posts.All(x => x != null));
{
var posts = await new E621Client().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.All(x => x.Tags.Any(z => z.Value.Any(y => tags.Contains(y)))));
}
break;
case 2:
posts = await new GelbooruClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new GelbooruClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
case 3:
posts = await new KonaChanClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new KonaChanClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
case 4:
posts = await new RealbooruClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new RealbooruClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
case 5:
posts = await new Rule34Client().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new Rule34Client().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
case 6:
posts = await new SafebooruClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new SafebooruClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
case 7:
posts = await new YandereClient().GetImagesAsync().ConfigureAwait(false);
{
var posts = await new YandereClient().GetImagesAsync(tags).ConfigureAwait(false);
Console.WriteLine(posts.Any(x => x.Tags.Any(z => tags.Contains(z) != null)));
}
break;
}
if (posts != null)
{
Console.WriteLine(posts.All(x => x != null));
}
}
catch(Exception ex)
{

@ -24,14 +24,11 @@ Yande.re</Description>
<PackageTags>booru imageboard api wrapper</PackageTags>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>2.0.0.0</Version>
<Version>2.0.5</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<PackageReleaseNotes>⚠ This version is not compatible with 1.0.0.X code ⚠
Wrapper Restructuring &amp; Seperate out each client from the container client
Fix bugs presented from some booru's updating</PackageReleaseNotes>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<FileVersion>2.0.5.0</FileVersion>
<PackageReleaseNotes>Tags now work</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
@ -49,7 +46,6 @@ Fix bugs presented from some booru's updating</PackageReleaseNotes>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestEase" Version="1.4.10" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class DanbooruClient : IPostsBooruClient<DanbooruImage>, IDisposable
public class DanbooruClient : IDisposable
{
IPostsBooruClient<DanbooruImage> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public DanbooruClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://danbooru.donmai.us/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPostsBooruClient<DanbooruImage>>();
}
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"posts.json?tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<DanbooruImage>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,45 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class E621Client : IPostsWrappedBooruClient<WrappedPosts<E621Image>>, IDisposable
public class E621Client : IDisposable
{
IPostsWrappedBooruClient<WrappedPosts<E621Image>> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public E621Client()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://e621.net/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPostsWrappedBooruClient<WrappedPosts<E621Image>>>();
}
public Task<WrappedPosts<E621Image>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
public Task<IReadOnlyList<E621Image>> GetImagesAsync(IEnumerable<string> tags)
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<E621Image>> GetImagesAsync(params string[] tags)
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<E621Image>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"posts.json?tags={tags}").ConfigureAwait(false);
public Task<WrappedPosts<E621Image>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
var posts = JsonConvert.DeserializeObject<WrappedPosts<E621Image>>(content, settings);
return posts.Posts;
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class GelbooruClient : IPHPBooruClient<GelbooruImage>, IDisposable
public class GelbooruClient : IDisposable
{
IPHPBooruClient<GelbooruImage> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public GelbooruClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://gelbooru.com/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPHPBooruClient<GelbooruImage>>();
}
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<GelbooruImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<GelbooruImage>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class KonaChanClient : IPostBooruClient<KonaChanImage>, IDisposable
public class KonaChanClient : IDisposable
{
IPostBooruClient<KonaChanImage> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public KonaChanClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://konachan.com/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPostBooruClient<KonaChanImage>>();
}
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<KonaChanImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"post.json?tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<KonaChanImage>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class RealbooruClient : IPHPBooruClient<RealbooruImage>, IDisposable
public class RealbooruClient : IDisposable
{
IPHPBooruClient<RealbooruImage> _api;
HttpClient _api;
JsonSerializerSettings settings;
public RealbooruClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://realbooru.com/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPHPBooruClient<RealbooruImage>>();
}
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> await _api.GetImagesAsync(tags).ConfigureAwait(false);
public Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(params string[] tags)
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
public async Task<IReadOnlyList<RealbooruImage>> GetImagesAsync(params string[] tags)
=> await _api.GetImagesAsync(tags).ConfigureAwait(false);
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<RealbooruImage>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class Rule34Client : IPHPBooruClient<Rule34Image>, IDisposable
public class Rule34Client : IDisposable
{
IPHPBooruClient<Rule34Image> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public Rule34Client()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://rule34.xxx/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPHPBooruClient<Rule34Image>>();
}
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<Rule34Image>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<Rule34Image>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<Rule34Image>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class SafebooruClient : IPHPBooruClient<SafebooruImage>, IDisposable
public class SafebooruClient : IDisposable
{
IPHPBooruClient<SafebooruImage> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public SafebooruClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://safebooru.org/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPHPBooruClient<SafebooruImage>>();
}
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<SafebooruImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"index.php?page=dapi&s=post&q=index&json=1&tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<SafebooruImage>>(content, settings);
}
public void Dispose()
{

@ -1,5 +1,4 @@
using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
@ -7,35 +6,43 @@ using System.Threading.Tasks;
namespace Booru.Net
{
public class YandereClient : IPostBooruClient<YandereImage>, IDisposable
public class YandereClient : IDisposable
{
IPostBooruClient<YandereImage> _api;
private readonly HttpClient _api;
private readonly JsonSerializerSettings settings;
public YandereClient()
{
var httpClient = new HttpClient
_api = new HttpClient
{
BaseAddress = new Uri("https://yande.re/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
_api.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPostBooruClient<YandereImage>>();
}
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public Task<IReadOnlyList<YandereImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
=> GetImagesAsync(string.Join("%20", tags));
public async Task<IReadOnlyList<YandereImage>> GetImagesAsync(string tags)
{
var get = await _api.GetAsync($"post.json?tags={tags}").ConfigureAwait(false);
if (!get.IsSuccessStatusCode)
throw new HttpRequestException($"Response failed with reason: \"({get.StatusCode}) {get.ReasonPhrase}\"");
var content = await get.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<IReadOnlyList<YandereImage>>(content, settings);
}
public void Dispose()
{

@ -2,6 +2,7 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Booru.Net.Converters
{
@ -16,25 +17,11 @@ namespace Booru.Net.Converters
{
var token = JToken.Load(reader);
List<Dictionary<string, List<string>>> container = new List<Dictionary<string, List<string>>>();
Dictionary<string, List<string>> container = new Dictionary<string, List<string>>();
foreach(var el in token.Children<JObject>())
foreach(JProperty el in token.Values<JProperty>())
{
Dictionary<string, List<string>> att = new Dictionary<string, List<string>>();
foreach (JProperty prop in el.Properties())
{
List<string> children = new List<string>();
foreach(var child in prop.Value.Children())
{
children.Add(child.Value<string>());
}
att.Add(prop.Name, children);
break;
}
container.Add(att);
container.Add(el.Name, el.Value.Values<string>().ToList());
}
return container;

@ -1,13 +0,0 @@
using RestEase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Booru.Net
{
public interface IIndexBooruClient<T> : IDisposable
{
[Get("index.json")]
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
}
}

@ -1,13 +0,0 @@
using RestEase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Booru.Net
{
public interface IPHPBooruClient<T> : IDisposable
{
[Get("index.php?page=dapi&s=post&q=index&json=1")]
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
}
}

@ -1,13 +0,0 @@
using RestEase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Booru.Net
{
public interface IPostBooruClient<T> : IDisposable
{
[Get("post.json")]
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
}
}

@ -1,13 +0,0 @@
using RestEase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Booru.Net
{
public interface IPostsBooruClient<T> : IDisposable
{
[Get("posts.json")]
public Task<IReadOnlyList<T>> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
}
}

@ -1,13 +0,0 @@
using RestEase;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Booru.Net
{
public interface IPostsWrappedBooruClient<T> : IDisposable
{
[Get("posts.json")]
public Task<T> GetImagesAsync([Query("tags")] IEnumerable<string> tags);
}
}

@ -4,7 +4,16 @@ using System.Collections.Generic;
namespace Booru.Net
{
public class DanbooruImage : BooruImage
{
{
[JsonProperty("score")]
public int? Score { get; set; }
[JsonProperty("file_url")]
private string FileUrl { get; set; }
public override string ImageUrl
=> FileUrl;
[JsonProperty("tag_string")]
private string TagString { get; set; }

@ -12,11 +12,25 @@ namespace Booru.Net
[JsonProperty("directory")]
public string Directory { get; set; }
[JsonProperty("file")]
public E621ImageSource File { get; set; }
[JsonProperty("preview")]
public E621ImageSource PreviewImage { get; set; }
[JsonProperty("sample")]
public E621ImageSource SampleImage { get; set; }
[JsonProperty("flags")]
public E621ImageFlags Flags { get; set; }
[JsonProperty("tags")]
[JsonConverter(typeof(TagGroupConverter))]
private List<Dictionary<string, List<string>>> PTags { get; set; }
private Dictionary<string, List<string>> PTags { get; set; }
public IReadOnlyDictionary<string, List<string>> Tags { get { return PTags; } }
public IReadOnlyList<Dictionary<string, List<string>>> Tags { get { return PTags.AsReadOnly(); } }
public override string ImageUrl => File.Url;
public override string PostUrl { get { return "https://e621.net/post/show/" + ID; } }
}

@ -0,0 +1,25 @@
using Newtonsoft.Json;
namespace Booru.Net
{
public class E621ImageFlags
{
[JsonProperty("pending")]
public bool Pending { get; private set; }
[JsonProperty("flagged")]
public bool Flagged { get; private set; }
[JsonProperty("note_locked")]
public bool NoteLocked { get; private set; }
[JsonProperty("status_locked")]
public bool StatusLocked { get; private set; }
[JsonProperty("rating_locked")]
public bool RatingLocked { get; private set; }
[JsonProperty("deleted")]
public bool Deleted { get; private set; }
}
}

@ -0,0 +1,28 @@
using Newtonsoft.Json;
namespace Booru.Net
{
public class E621ImageSource
{
[JsonProperty("width")]
public int Width { get; private set; }
[JsonProperty("height")]
public int Height { get; private set; }
[JsonProperty("ext")]
public string Extension { get; private set; }
[JsonProperty("size")]
public ulong Size { get; private set; }
[JsonProperty("has")]
public bool Has { get; private set; }
[JsonProperty("md5")]
public string MD5 { get; private set; }
[JsonProperty("url")]
public string Url { get; private set; }
}
}

@ -8,9 +8,9 @@ namespace Booru.Net
public int Up { get; set; }
[JsonProperty("down")]
private int Down { get; set; }
public int Down { get; set; }
[JsonProperty("total")]
private int Total { get; set; }
public int Total { get; set; }
}
}

@ -11,6 +11,12 @@ namespace Booru.Net
[JsonProperty("directory")]
public string Directory { get; set; }
[JsonProperty("file_url")]
private string FileUrl { get; set; }
public override string ImageUrl
=> FileUrl;
[JsonProperty("tags")]
private string Ptags { get; set; }

@ -10,9 +10,9 @@ namespace Booru.Net
[JsonProperty("rating")]
private string Prating { get; set; }
public virtual string ImageUrl { get; set; }
public virtual string ImageUrl { get; private set; }
public virtual string PostUrl { get; set; }
public virtual string PostUrl { get; private set; }
public Rating Rating
{

@ -14,24 +14,28 @@ Currently supported Boards are:
# How to get started
```cs
var BooruClient = new BooruClient();
var GelbooruClient = new GelbooruClient();
var posts = await BooruClient.GetGelbooruImagesAsync("aisha_clanclan", "melfina");
var posts = await GelbooruClient.GetImagesAsync("aisha_clanclan", "melfina");
if(posts != null)
{
...
}
```
List of Methods in Wrapper:
- `GetGelbooruImagesAsync(IEnumerable<string> tags)`
- `GetDanbooruImagesAsync(IEnumerable<string> tags)`
- `GetRule34ImagesAsync(IEnumerable<string> tags)`
- `GetE621ImagesAsync(IEnumerable<string> tags)`
- `GetKonaChanImagesAsync(IEnumerable<string> tags)`
- `GetYandereImagesAsync(IEnumerable<string> tags)`
- `GetRealBooruImagesAsync(IEnumerable<string> tags)`
List<string> tags = new List<string>
{
"aisha_clanclan",
"melfina"
};
posts = await GelbooruClient.GetImagesAsync(tags);
if(posts != null)
{
...
}
```
# Contributing
If you wish to add more booru's to the wrapper/make the code better/optimise the code, please fork your own version and pull-request it. If you are planning on adding another booru to the wrapper, please do it in a similar style to the currently existing methods.

Loading…
Cancel
Save