mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NadekoBot.Modules.Nsfw.Common
|
|
{
|
|
public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
|
|
{
|
|
private readonly string _baseUrl;
|
|
|
|
public KonachanImageDownloader(HttpClient http)
|
|
: base(Booru.Konachan, http)
|
|
{
|
|
_baseUrl = "https://konachan.com";
|
|
}
|
|
|
|
public override async Task<List<DapiImageObject>> DownloadImagesAsync(string[] tags, int page, bool isExplicit = false, CancellationToken cancel = default)
|
|
{
|
|
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
|
|
var uri = $"{_baseUrl}/post.json?s=post&q=index&limit=200&tags={tagString}&page={page}";
|
|
var imageObjects = await _http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel)
|
|
.ConfigureAwait(false);
|
|
if (imageObjects is null)
|
|
return new();
|
|
return imageObjects
|
|
.Where(x => x.FileUrl is not null)
|
|
.ToList();
|
|
}
|
|
}
|
|
} |