implement yande.re source

This commit is contained in:
2021-08-06 17:18:18 +08:00
parent 600d81a3f1
commit 9d316cba77
18 changed files with 486 additions and 2 deletions

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Gallery.Util\Gallery.Util.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,24 @@
using System;
using System.Threading.Tasks;
using Gallery.Util.Interface;
using Gallery.Util.Model;
namespace Gallery.Danbooru
{
public class GallerySource : IGallerySource
{
public string Name => "Danbooru";
public string HomePage => "https://danbooru.donmai.us";
public Task<GalleryItem[]> GetRecentItemsAsync(int page)
{
throw new NotImplementedException();
}
public void SetCookie()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Gallery.Util\Gallery.Util.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,24 @@
using System;
using System.Threading.Tasks;
using Gallery.Util.Interface;
using Gallery.Util.Model;
namespace Gallery.Gelbooru
{
public class GallerySource : IGallerySource
{
public string Name => "Gelbooru";
public string HomePage => "https://gelbooru.com";
public Task<GalleryItem[]> GetRecentItemsAsync(int page)
{
throw new NotImplementedException();
}
public void SetCookie()
{
throw new NotImplementedException();
}
}
}

View File

@ -4,6 +4,12 @@
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Gallery.Util\Gallery.Util.csproj" />
</ItemGroup>

View File

@ -0,0 +1,65 @@
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Gallery.Util;
using Gallery.Util.Interface;
using Gallery.Util.Model;
namespace Gallery.Yandere
{
public class GallerySource : IGallerySource
{
public string Name => "Yande.re";
public string HomePage => "https://yande.re";
public async Task<GalleryItem[]> GetRecentItemsAsync(int page)
{
var url = $"https://yande.re/post?page={page}";
var (result, error) = await NetHelper.RequestObject<YandereItem[]>(url, contentHandler: ContentHandler);
if (result == null || !string.IsNullOrEmpty(error))
{
Log.Error("yandere.content.load", $"failed to load content array, error: {error}");
return null;
}
var items = new GalleryItem[result.Length];
for (var i = 0; i < items.Length; i++)
{
var y = result[i];
var item = new GalleryItem(y.id)
{
Tags = y.tags?.Split(' '),
CreatedTime = y.created_at.ToLocalTime(),
UpdatedTime = y.updated_at.ToLocalTime(),
UserId = y.creator_id.ToString(),
UserName = y.author,
Source = y.source,
PreviewUrl = y.preview_url,
RawUrl = y.file_url,
Width = y.width,
Height = y.height
};
items[i] = item;
}
return items;
}
private string ContentHandler(string content)
{
var regex = new Regex(@"Post\.register\((\{.+\})\)\s*$", RegexOptions.Multiline);
var matches = regex.Matches(content);
var array = new string[matches.Count];
for (var i = 0; i < array.Length; i++)
{
array[i] = matches[i].Groups[1].Value;
}
return $"[{string.Join(',', array)}]";
}
public void SetCookie()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,29 @@
using System;
namespace Gallery.Yandere
{
public class YandereItem
{
#pragma warning disable IDE1006 // Naming Styles
public long id { get; set; }
public string tags { get; set; }
public long created_at { get; set; }
public long updated_at { get; set; }
public long creator_id { get; set; }
public string author { get; set; }
public string source { get; set; }
public int score { get; set; }
public int file_size { get; set; }
public string file_ext { get; set; }
public string file_url { get; set; }
public string preview_url { get; set; }
public int actual_preview_width { get; set; }
public int actual_preview_height { get; set; }
public string rating { get; set; }
public int width { get; set; }
public int height { get; set; }
#pragma warning restore IDE1006 // Naming Styles
}
}