From 984c44554120bb0d62efccf05806e0a61bb790d7 Mon Sep 17 00:00:00 2001 From: mixa3607 <30209772+mixa3607@users.noreply.github.com> Date: Wed, 15 May 2024 23:14:31 +0500 Subject: [PATCH] ArkProjects.EHentai.Api extract ClientName from Settings page --- .../files/ParsingTests/HathSettings_1.json | 1 + .../Models/Requests/HathSettingsResponse.cs | 29 +++++++------------ .../Models/Requests/StaticRangeGroup.cs | 7 +++++ .../Models/Requests/StaticRangeGroupType.cs | 11 +++++++ 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroup.cs create mode 100644 ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroupType.cs diff --git a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api.Tests/files/ParsingTests/HathSettings_1.json b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api.Tests/files/ParsingTests/HathSettings_1.json index afb8e8f..160fa7d 100644 --- a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api.Tests/files/ParsingTests/HathSettings_1.json +++ b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api.Tests/files/ParsingTests/HathSettings_1.json @@ -3,6 +3,7 @@ { "ExpectedResult": { "ClientId": 45244, + "ClientName": "services.lan", "ClientKey": "PFxb12auaaaaaaaaaaaa", "StaticRanges": 289, "StaticRangeGroups": { diff --git a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/HathSettingsResponse.cs b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/HathSettingsResponse.cs index 9ee22b4..39389ff 100644 --- a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/HathSettingsResponse.cs +++ b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/HathSettingsResponse.cs @@ -4,25 +4,10 @@ namespace ArkProjects.EHentai.Api.Models.Requests; -public enum StaticRangeGroupType -{ - Unknown, - Priority1, - Priority2, - Priority3, - Priority4, - HighCapacity -} - -public class StaticRangeGroup -{ - public StaticRangeGroupType Type { get; set; } = StaticRangeGroupType.Unknown; - public int Count { get; set; } = -1; -} - public class HathSettingsResponse { public long ClientId { get; set; } = -1; + public string? ClientName { get; set; } public string? ClientKey { get; set; } public int StaticRanges { get; set; } = -1; @@ -47,11 +32,18 @@ public static HathSettingsResponse Parse(HtmlDocument doc) } { - var table = tables.First(x => x.SelectSingleNode(".//tr/td/div[text()='Reset Static Ranges']") != null); + + var table = doc.DocumentNode.SelectSingleNode("//*/table[@class='infot']"); var rows = table.SelectNodes(".//tr"); foreach (var row in rows) { - if (row.InnerText.Contains("Reset Static Ranges")) + if (row.SelectNodes(".//td[@class='infota']").FirstOrDefault()?.InnerText.Contains("Client Name") == true) + { + var text = row.SelectNodes(".//td[@class='infotv']/p/span").First().InnerText; + response.ClientName = text?.Trim(); + } + + if (row.SelectNodes(".//td[@class='infota']").FirstOrDefault()?.InnerText.Contains("Reset Static Ranges") == true) { var text = row.SelectNodes(".//td[@class='infotv']/p[1]").First().InnerText; { @@ -78,7 +70,6 @@ public static HathSettingsResponse Parse(HtmlDocument doc) match = match.NextMatch(); } } - } } } diff --git a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroup.cs b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroup.cs new file mode 100644 index 0000000..1812743 --- /dev/null +++ b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroup.cs @@ -0,0 +1,7 @@ +namespace ArkProjects.EHentai.Api.Models.Requests; + +public class StaticRangeGroup +{ + public StaticRangeGroupType Type { get; set; } = StaticRangeGroupType.Unknown; + public int Count { get; set; } = -1; +} \ No newline at end of file diff --git a/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroupType.cs b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroupType.cs new file mode 100644 index 0000000..2b8ea8e --- /dev/null +++ b/ArkProjects.EHentai.Api/ArkProjects.EHentai.Api/Models/Requests/StaticRangeGroupType.cs @@ -0,0 +1,11 @@ +namespace ArkProjects.EHentai.Api.Models.Requests; + +public enum StaticRangeGroupType +{ + Unknown, + Priority1, + Priority2, + Priority3, + Priority4, + HighCapacity +} \ No newline at end of file