Skip to content

Commit

Permalink
update 10.0.2
Browse files Browse the repository at this point in the history
fix danbooru etc.
  • Loading branch information
xplusky committed Apr 11, 2023
1 parent 6f95aeb commit 111707d
Show file tree
Hide file tree
Showing 57 changed files with 552 additions and 195 deletions.
35 changes: 34 additions & 1 deletion MoeLoaderP.Core/Ex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace MoeLoaderP.Core;
/// </summary>
public static class Ex
{
private static string _logListOriginalString;
private static string _logItemString;

public static int GetXIntValue(this XElement el, string xpath)
{
return (el.XPathSelectElement(xpath)?.Value ?? "0").ToInt();
Expand Down Expand Up @@ -55,8 +58,30 @@ public enum MessagePos

public static ObservableCollection<string> LogCollection { get; set; } = new();

public static string LogListOriginalString
{
get => _logListOriginalString;
set
{
_logListOriginalString = value;
if(value!=null) LogListOriginalStringAction?.Invoke(value);
}
}

public static string LogItemString
{
get => _logItemString;
set
{
_logItemString = value; LogItemStringAction?.Invoke(value);
}
}

public static Action<string> LogAction { get; set; }

public static event Action<string> LogListOriginalStringAction;
public static event Action<string> LogItemStringAction;

public static dynamic GetValue(this HtmlNode rootNode, CustomXpath xpath)
{
if (xpath == null) return null;
Expand Down Expand Up @@ -139,7 +164,15 @@ public static string ToPairsString(this Pairs pairs)
if (pairs == null) return query;
foreach (var para in pairs.Where(para => !para.Value.IsEmpty()))
{
query += $"{(i > 0 ? "&" : "?")}{para.Key}={para.Value}";
if (para.Value == null)
{
query += $"{(i > 0 ? "&" : "?")}{para.Key}";
}
else
{
query += $"{(i > 0 ? "&" : "?")}{para.Key}={para.Value}";
}

i++;
}

Expand Down
6 changes: 3 additions & 3 deletions MoeLoaderP.Core/MoeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public bool IsFav

public string Description { get; set; }
public List<string> Tags { get; set; } = new();
public bool IsExplicit { get; set; }
public bool IsNsfw { get; set; }
public string DetailUrl { get; set; }
public string OriginString { get; set; }

Expand Down Expand Up @@ -280,8 +280,8 @@ public void LocalFilter()
{
switch (set.IsXMode)
{
case false or false when IsExplicit:
case true when para.IsShowExplicitOnly && IsExplicit == false:
case false or false when IsNsfw:
case true when para.IsShowExplicitOnly && IsNsfw == false:
isNotFilter = false;
break;
}
Expand Down
12 changes: 6 additions & 6 deletions MoeLoaderP.Core/MoeLoaderP.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="9.1.2" />
<PackageReference Include="Magick.NET.Core" Version="9.1.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.0.1" />
<PackageReference Include="Magick.NET.Core" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
106 changes: 90 additions & 16 deletions MoeLoaderP.Core/NetOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public NetOperator(Settings settings,MoeSite site, double timeout = 40)
Settings = settings;
Site = site;
Timeout = timeout;


HttpClientHandler = new HttpClientHandler
{
Proxy = GetProxy(),
Expand All @@ -53,21 +51,38 @@ public NetOperator(Settings settings,MoeSite site, double timeout = 40)
ProgressMessageHandler = new ProgressMessageHandler(HttpClientHandler);
Client = new HttpClient(ProgressMessageHandler);
var agent = Agents[new Random().Next(0, Agents.Length - 1)];
Client.DefaultRequestHeaders.UserAgent.ParseAdd(agent);
var header = Client.DefaultRequestHeaders;
//header.UserAgent.ParseAdd(agent);
//header.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
//header.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
if (site is DanbooruSite)
{
header.TryAddWithoutValidation("User-Agent", "gdl/1.24.5");
}
else
{
header.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
}
//header.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
//header.TryAddWithoutValidation("Sec-Fetch-Dest", "document");
//header.TryAddWithoutValidation("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
//header.TryAddWithoutValidation("Connection", "keep-alive");
//header.TryAddWithoutValidation("Sec-Fetch-Dest", "document");
//header.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
//header.TryAddWithoutValidation("Sec-Fetch-Dest", "document");
//header.TryAddWithoutValidation("Sec-Fetch-Dest", "document");
//header.TryAddWithoutValidation("Sec-Fetch-User", "?1");
//header.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");


Client.Timeout = TimeSpan.FromSeconds(Timeout);
}


public static string[] Agents =
{
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
//"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36",
};

public IWebProxy GetProxy()
Expand Down Expand Up @@ -148,6 +163,7 @@ public async Task<HttpResponseMessage> GetAsync(string api, bool showSearchMessa
{
try
{

return await Client.GetAsync(api, token);
}
catch (Exception)
Expand Down Expand Up @@ -178,15 +194,34 @@ public async Task<string> GetStringAsync(string api, Pairs parapairs = null, boo
}
}

public async Task<dynamic> GetJsonAsync(string api, Pairs parapairs = null, bool showSearchMessage = true, CancellationToken token = default)
public async Task<dynamic> GetJsonAsync(string api, Pairs parapairs = null, bool showSearchMessage = true, bool saveListOriginalString = false, bool tryWebView = false,
CancellationToken token = default)
{
var query = parapairs.ToPairsString();
try
{
var response = await GetAsync($"{api}{query}", showSearchMessage, 3,token: token);

var response = await GetAsync($"{api}{query}", showSearchMessage,token: token);
var res = response.Headers;
var s = await response.Content.ReadAsStringAsync(token);
return JsonConvert.DeserializeObject(s);
if (saveListOriginalString)
{
Ex.LogListOriginalString = s;
}

dynamic deo = JsonConvert.DeserializeObject(s);
//try
//{
// deo = JsonConvert.DeserializeObject(s);
//}
//catch (Exception e)
//{
// if (e.Message.Contains("Unexpected character", StringComparison.OrdinalIgnoreCase))
// {
// // if (WebView == null) InitWebView();

// }
//}
return deo;
}
catch (Exception e)
{
Expand All @@ -196,6 +231,45 @@ public async Task<dynamic> GetJsonAsync(string api, Pairs parapairs = null, bool
}
}

//public void InitWebView()
//{
// WebView = new WebView2();
// try
// {
// WebView.CoreWebView2InitializationCompleted += WebViewOnCoreWebView2InitializationCompleted;

// var option = new CoreWebView2EnvironmentOptions();
// switch (GetProxyMode(Settings, Site.SiteSettings))
// {
// case Settings.ProxyModeEnum.None:
// option.AdditionalBrowserArguments = "--no-proxy-server";
// break;
// case Settings.ProxyModeEnum.Custom:
// option.AdditionalBrowserArguments = $"--proxy-server=http://{Settings.ProxySetting}";
// break;
// case Settings.ProxyModeEnum.Ie:
// break;
// }
// Environment = await CoreWebView2Environment.CreateAsync(null, App.AppDataDir, option);

// AuthButton.Click += AuthButtonOnClick;
// GoToLoginPageButton.Click += GoToLoginPageButtonOnClick;
// var _ = MainBrowser.EnsureCoreWebView2Async(Environment);
// }
// catch (Exception ex)
// {
// var result = MessageBox.Show(this, "未找到WebView2组件,需要下载吗?(需要Webview2组件才能显示网页登录界面)", App.DisplayName, MessageBoxButton.YesNo, MessageBoxImage.Question);
// if (result == MessageBoxResult.Yes)
// {
// "https://go.microsoft.com/fwlink/p/?LinkId=2124703".GoUrl();

// }
// Ex.Log(ex);
// Close();
// }
//}


public async Task<HtmlDocument> GetHtmlAsync(string api, Pairs parapairs = null, bool showSearchMessage = true, CancellationToken token = default)
{
var query = parapairs.ToPairsString();
Expand Down Expand Up @@ -235,7 +309,7 @@ public async Task<XmlDocument> GetXmlAsync(string api, Pairs pairs = null, bool
return xml;
}

public async Task<XDocument> GetXDocAsync(string api, Pairs pairs = null, bool showSearchMessage = true,
public async Task<XDocument> GetXDocAsync(string api, Pairs pairs = null, bool showSearchMessage = true,bool tryWebView = false,
CancellationToken token = default)
{
var query = pairs.ToPairsString();
Expand Down
3 changes: 2 additions & 1 deletion MoeLoaderP.Core/SearchSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public SearchSession(SearchPara para)

public string Name { get; set; }



public Settings Settings { get; set; }

Expand Down Expand Up @@ -185,7 +186,7 @@ public async Task<SearchedPage> TryGetRealPage(SearchPara para)
rp.CurrentPageItemsOutputCount = rp.Count(item=> item.IsLocalFilter == false);
var mes =
$"第{rp.CurrentPageNum}页获取到图片{rp.CurrentPageItemsOriginCount}张,条件过滤{rp.CurrentPageItemsOriginCount - rp.CurrentPageItemsOutputCount}张";

Ex.LogListOriginalString = rp.OriginString?.ToString();
Ex.ShowMessage(mes, pos: Ex.MessagePos.Searching);
return rp;
}
Expand Down
16 changes: 16 additions & 0 deletions MoeLoaderP.Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public SearchSession CurrentSession

#region Window size / Display

private double _logWindowWidth = 500d;

public double LogWindowWidth
{
get => _logWindowWidth;
set => SetField(ref _logWindowWidth, value, nameof(LogWindowWidth));
}

private double _logWindowHeight = 350d;

public double LogWindowHeight
{
get => _logWindowHeight;
set => SetField(ref _logWindowHeight, value, nameof(LogWindowHeight));
}

private bool _isLowPerformanceMode;

public bool IsLowPerformanceMode
Expand Down
44 changes: 27 additions & 17 deletions MoeLoaderP.Core/SiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SiteManager(Settings settings)
Settings = settings;
Sites = new MoeSites(settings);
Settings.PropertyChanged += SettingsOnPropertyChanged;
SetDefaultSiteList();
RefreshSiteList();
}

public Settings Settings { get; set; }
Expand Down Expand Up @@ -48,13 +48,14 @@ public void SetDefaultSiteList()
Sites.Add(new GelbooruSite());
Sites.Add(new SankakuChanSite());
if (x) Sites.Add(new SankakuIdolSite());
Sites.Add(new DanbooruSite());
Sites.Add(new DeviantartSite());
Sites.Add(new DonmaiSite());

Sites.Add(new BilibiliSite());
Sites.Add(new YuriimgSite());
Sites.Add(new BehoimiSite());
Sites.Add(new SafebooruSite());
if (x) Sites.Add(new LolibooruSite());
Sites.Add(new LolibooruSite());
if (x) Sites.Add(new AtfbooruSite());
if (x) Sites.Add(new Rule34Site());

Expand Down Expand Up @@ -101,30 +102,39 @@ public bool R18Check()
if (!Settings.HaveEnteredXMode)
{
ClickTimes++;
if (ClickTimes <= 3) return false;
if (ClickTimes is > 3 and < 10)
switch (ClickTimes)
{
Ex.ShowMessage($"还剩 {10 - ClickTimes} 次粉碎!");
return false;
case <= 3:
return false;
case > 3 and < 10:
Ex.ShowMessage($"还剩 {10 - ClickTimes} 次击破!");
return false;
case >= 10:
Settings.HaveEnteredXMode = true;
break;
}

if (ClickTimes >= 10) Settings.HaveEnteredXMode = true;
}

Ex.ShowMessage(Settings.IsXMode ? "已关闭 R18 模式" : "已开启 R18 模式");
Ex.ShowMessage(Settings.IsXMode ? "已关闭 NSFW 模式" : "已开启 NSFW 模式");
Settings.IsXMode = !Settings.IsXMode;
Sites.Clear();
SetDefaultSiteList();
RefreshSiteList();
return true;
}

private void SettingsOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Settings.IsCustomSiteMode))
{
Sites.Clear();
if (Settings.IsCustomSiteMode) SetCustomSitesFormJson(Settings.CustomSitesDir);
else SetDefaultSiteList();
}
//if (e.PropertyName == nameof(Settings.IsCustomSiteMode))
//{
// Sites.Clear();
// if (Settings.IsCustomSiteMode) SetCustomSitesFormJson(Settings.CustomSitesDir);
// else SetDefaultSiteList();
//}
}

public void RefreshSiteList()
{
SetDefaultSiteList();
SetCustomSitesFormJson(Settings.CustomSitesDir);
}
}
2 changes: 1 addition & 1 deletion MoeLoaderP.Core/Sites/AtfbooruSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
public class AtfbooruSite : BooruSite
{
public override string HomeUrl => "https://booru.allthefallen.moe/";
public override string HomeUrl => "https://booru.allthefallen.moe";
public override string DisplayName => "Atfbooru";
public override string ShortName => "atfbooru";

Expand Down
2 changes: 1 addition & 1 deletion MoeLoaderP.Core/Sites/BilibiliSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BilibiliSite()

public override string ShortName => "bilibili";

public override bool VerifyCookieAndSave(CookieCollection ccol)
public override bool VerifyCookie(CookieCollection ccol)
{
return ccol.Any(cookie => cookie.Name.Equals("DedeUserID", StringComparison.OrdinalIgnoreCase));
}
Expand Down
Loading

0 comments on commit 111707d

Please sign in to comment.