mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Fixed .gelbooru
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -13,10 +14,11 @@ namespace NadekoBot.Modules.Nsfw.Common
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
|
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page,
|
||||||
|
bool isExplicit = false, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
||||||
var uri = $"http://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" +
|
var uri = $"https://gelbooru.com/index.php?page=dapi&s=post&json=1&q=index&limit=100" +
|
||||||
$"&tags={tagString}&pid={page}";
|
$"&tags={tagString}&pid={page}";
|
||||||
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
|
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||||
using var res = await _http.SendAsync(req, cancel).ConfigureAwait(false);
|
using var res = await _http.SendAsync(req, cancel).ConfigureAwait(false);
|
||||||
@@ -25,11 +27,17 @@ namespace NadekoBot.Modules.Nsfw.Common
|
|||||||
if (string.IsNullOrWhiteSpace(resString))
|
if (string.IsNullOrWhiteSpace(resString))
|
||||||
return new();
|
return new();
|
||||||
|
|
||||||
var images = JsonSerializer.Deserialize<List<DapiImageObject>>(resString, _serializerOptions);
|
var images = JsonSerializer.Deserialize<GelbooruResponse>(resString, _serializerOptions);
|
||||||
if (images is null)
|
if (images is null or { Post: null })
|
||||||
return new();
|
return new();
|
||||||
|
|
||||||
return images.Where(x => x.FileUrl is not null).ToList();
|
return images.Post.Where(x => x.FileUrl is not null).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GelbooruResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("post")]
|
||||||
|
public List<DapiImageObject> Post { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user