Skip to content

Commit

Permalink
apply eh settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Dec 21, 2021
1 parent c2c8fa5 commit bb6b487
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
20 changes: 12 additions & 8 deletions EHentaiGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public EHentaiGallery()
client.Settings.SharedPreferences = Setting<EhentaiSetting>.Current;

Request.RequestFactory = url => new EHentaiRequest(url);

//暂时表站
client.Settings.GallerySite = Settings.GallerySites.SITE_E;

//强制钦定一下列表样式
client.Cookies.Add(new System.Net.Cookie("sl", "dm_1", "/", "e-hentai.org"));
client.Cookies.Add(new System.Net.Cookie("sl", "dm_1", "/", "exhentai.org"));
}

public override GalleryItem GetImage(string id)
public override Task<GalleryItem> GetImage(string id)
{
if (!IdConverter.TryConvertBackEhentai(id, out var gid, out var token))
{
Expand All @@ -54,10 +58,10 @@ public override GalleryItem GetImage(string id)
var url = client.EhUrl.GetGalleryDetailUrl(gid, token);
var detail = client.GetGalleryDetailAsync(url).Result;

return EHentaiImageGalleryInfo.Create(client.EhUrl, detail);
return Task.FromResult(EHentaiImageGalleryInfo.Create(client.EhUrl, detail));
}

public override GalleryImageDetail GetImageDetial(GalleryItem item)
public override async Task<GalleryImageDetail> GetImageDetial(GalleryItem item)
{
if ((item as EHentaiImageGalleryInfo)?.CachedGalleryDetail is GalleryImageDetail d)
return d;
Expand All @@ -68,10 +72,10 @@ public override GalleryImageDetail GetImageDetial(GalleryItem item)
var url = client.EhUrl.GetGalleryDetailUrl(gid, token);
var detail = Task.Run(async () => await client.GetGalleryDetailAsync(url)).Result;

return new EHentaiImageGalleryImageDetail(detail);
return await Task.FromResult(new EHentaiImageGalleryImageDetail(detail));
}

public override IEnumerable<GalleryItem> GetMainPostedImages() => SearchImages(default);
public override IAsyncEnumerable<GalleryItem> GetMainPostedImages() => SearchImagesAsync(default);

public DetailImagePageBase GenerateDetailImagePageObject()
{
Expand All @@ -83,7 +87,7 @@ public async Task AccountLoginAsync(AccountInfo info)
try
{
var respUserName = await client.SignInAsync(info.Name, info.Password);
if (respUserName?.Equals(info.Name, System.StringComparison.InvariantCultureIgnoreCase) ?? false)
if (respUserName?.Equals(info.Name, StringComparison.InvariantCultureIgnoreCase) ?? false)
{
Log<EHentaiGallery>.Info("login successfully.");
}
Expand All @@ -100,7 +104,7 @@ public Task AccountLogoutAsync()
return Task.CompletedTask;
}

public IEnumerable<GalleryItem> SearchImages(IEnumerable<string> keywords)
public async IAsyncEnumerable<GalleryItem> SearchImagesAsync(IEnumerable<string> keywords)
{
var page = 0;
var urlBuilder = new ListUrlBuilder(client.EhUrl);
Expand All @@ -115,7 +119,7 @@ public IEnumerable<GalleryItem> SearchImages(IEnumerable<string> keywords)

var url = urlBuilder.Build();

var result = client.GetGalleryListAsync(url).Result;
var result = await client.GetGalleryListAsync(url);
foreach (var info in result.galleryInfoList)
yield return EHentaiImageGalleryInfo.Create(client.EhUrl, info);

Expand Down
47 changes: 44 additions & 3 deletions EhentaiSetting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Castle.DynamicProxy.Generators;
using EHentaiAPI;
using EHentaiAPI.Utils;
using System;
using System.Collections.Generic;
Expand All @@ -14,15 +14,54 @@ namespace WbooruPlugin.EHentai
[Export(typeof(SettingBase))]
public class EhentaiSetting : SettingBase, ISharedPreferences
{
[Group("View Options")]
const string ViewOptionsGroup = "画廊浏览";

[Group(ViewOptionsGroup)]
[NameAlias("画廊预览图片列表数量")]
public uint DetailPagePreviewImagesCount { get; set; } = 20;

[Group("View Options")]
[Group(ViewOptionsGroup)]
[Description("这样会让你的账号流量流量花费更快(用完就会出现509错误)")]
[NameAlias("浏览大图时优先加载原图")]
public bool OriginImageRequire { get; set; } = false;

[Group(ViewOptionsGroup)]
[Description("以像素为单位")]
[NameAlias("列表滚动速度")]
public int ScrollOffsetSpeed { get; set; } = 30;

[Group(ViewOptionsGroup)]
[Description("当你浏览大图时,后台自动向后预加载页面的数量")]
[NameAlias("浏览页面预加载后面页数")]
public int ViewPageFrontPreload
{
get
{
return EhSettingMap.TryGetValue(Settings.KEY_SPIDER_FRONT_PRELOAD_COUNT, out var d) ? int.Parse(d.ToString()) : Settings.DEFAULT_SPIDER_FRONT_PRELOAD_COUNT;
}
set
{
EhSettingMap[Settings.KEY_SPIDER_FRONT_PRELOAD_COUNT] = value;
}
}

[Group(ViewOptionsGroup)]
[Description("当你浏览大图时,后台自动向前预加载页面的数量")]
[NameAlias("浏览页面预加载前面页数")]
public int ViewPageBackPreload
{
get
{
return EhSettingMap.TryGetValue(Settings.KEY_SPIDER_BACK_PRELOAD_COUNT, out var d) ? int.Parse(d.ToString()) : Settings.DEFAULT_SPIDER_BACK_PRELOAD_COUNT;
}
set
{
EhSettingMap[Settings.KEY_SPIDER_BACK_PRELOAD_COUNT] = value;
}
}

#region ISharedPreferences

[Ignore]
public Dictionary<string, object> EhSettingMap { get; set; } = new();

Expand All @@ -38,5 +77,7 @@ public ISharedPreferences setValue<T>(string key, T value = default)
EhSettingMap[key] = value;
return this;
}

#endregion
}
}
14 changes: 10 additions & 4 deletions UI/Pages/EHentaiGalleryDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
Expand All @@ -25,6 +26,7 @@
using Wbooru.Kernel;
using Wbooru.Models;
using Wbooru.Models.Gallery;
using Wbooru.Network;
using Wbooru.Settings;
using Wbooru.UI.Controls;
using Wbooru.UI.Dialogs;
Expand Down Expand Up @@ -142,16 +144,20 @@ public override async void ApplyItem(Gallery g, GalleryItem i)
return;
}

Detail = gallery.GetImageDetial(info) as EHentaiImageGalleryImageDetail;
Detail = (await gallery.GetImageDetial(info)) as EHentaiImageGalleryImageDetail;
Log.Debug($"Thumb = {Detail.Detail.Thumb}");

this.spider = new EhPageImageSpider<System.Drawing.Image>(client, Detail.Detail, async (url, reporter) =>
this.spider = new EhPageImageSpider<System.Drawing.Image>(client, Detail.Detail, async (preview, info, reporter) =>
{
var url = Setting<EhentaiSetting>.Current.OriginImageRequire && !string.IsNullOrWhiteSpace(info.OriginImageUrl) ? info.OriginImageUrl : info.ImageUrl;

var image = await ImageResourceManager.RequestImageAsync(url, url, false, curDLStatus =>
{
reporter.CurrentDownloadingLength = curDLStatus.downloaded_bytes;
if (curDLStatus.content_bytes != reporter.CurrentDownloadingLength)
reporter.CurrentDownloadingLength = curDLStatus.content_bytes;
if (curDLStatus.content_bytes != reporter.TotalDownloadLength)
reporter.TotalDownloadLength = curDLStatus.content_bytes;
},req=> {
req.CookieContainer = client.Cookies;
});
return image;
});
Expand Down
2 changes: 1 addition & 1 deletion UI/Pages/EHentaiGalleryImageListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
ItemsSource="{Binding PreviewImages}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<virtualizingstaggeredpanel:VirtualizingStaggeredPanel GridItemWidth="{Binding GridItemWidth}" />
<virtualizingstaggeredpanel:VirtualizingStaggeredPanel GridItemWidth="{Binding GridItemWidth}" ScrollOffset="{Binding ScrollOffsetSpeed}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
Expand Down
3 changes: 3 additions & 0 deletions UI/Pages/EHentaiGalleryImageListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -77,6 +78,8 @@ public int PageEnd
private readonly EhClient client;
public GalleryDetail Detail { get; init; }

public int ScrollOffsetSpeed => Setting<EhentaiSetting>.Current.ScrollOffsetSpeed;

private readonly EhPageImageSpider<System.Drawing.Image> spider;

public uint GridItemWidth => Setting<GlobalSetting>.Current.PictureGridItemWidth;
Expand Down
2 changes: 2 additions & 0 deletions UI/Pages/EHentaiImageViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Wbooru;
using Wbooru.Kernel;
using Wbooru.UI.Controls;
using Wbooru.Utils;
Expand Down

0 comments on commit bb6b487

Please sign in to comment.