gelbooru source
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Gallery.Util;
|
||||
using Gallery.Util.Interface;
|
||||
using Gallery.Util.Model;
|
||||
using Xamarin.Forms;
|
||||
@ -13,9 +15,40 @@ namespace Gallery.Gelbooru
|
||||
public string FlyoutIconKey => "Gelbooru";
|
||||
public string HomePage => "https://gelbooru.com";
|
||||
|
||||
public Task<GalleryItem[]> GetRecentItemsAsync(int page)
|
||||
public async Task<GalleryItem[]> GetRecentItemsAsync(int page)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var offset = (page - 1) * 42;
|
||||
var url = $"https://gelbooru.com/index.php?page=post&s=list&tags=all&pid={offset}";
|
||||
var (result, error) = await NetHelper.RequestObject(url, @return: content => ResolveGalleryItems(content));
|
||||
|
||||
if (result == null || !string.IsNullOrEmpty(error))
|
||||
{
|
||||
Log.Error("gelbooru.content.load", $"failed to load content array, error: {error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private GalleryItem[] ResolveGalleryItems(string content)
|
||||
{
|
||||
var regex = new Regex(
|
||||
@"<article(.|\n)+?<a id=""p(\d+?)"" href=""([^""]+?)"">(.|\n)+?<img src=""([^""]+?)"" title=""([^""]+?)""",
|
||||
RegexOptions.Multiline);
|
||||
var matches = regex.Matches(content);
|
||||
var items = new GalleryItem[matches.Count];
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
var g = matches[i].Groups;
|
||||
items[i] = new GalleryItem(int.Parse(g[2].Value))
|
||||
{
|
||||
RawUrl = g[3].Value,
|
||||
PreviewUrl = g[5].Value,
|
||||
Tags = g[6].Value.Split(' '),
|
||||
IsRawPage = true
|
||||
};
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void SetCookie()
|
||||
|
Reference in New Issue
Block a user