Updated scanner logic, and added initial scanner tests.
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
using JSMR.Application.Common.Caching;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
public partial class EnglishVoiceWorksScanner(IHtmlLoader loader, ISpamCircleCache spamCircleCache)
|
||||
: VoiceWorksScanner(loader, spamCircleCache)
|
||||
public partial class EnglishVoiceWorksScanner(IHtmlLoader loader) : VoiceWorksScanner(loader)
|
||||
{
|
||||
[GeneratedRegex(@"Release: (.*?)[/](\d{2})[/](\d{4})", RegexOptions.IgnoreCase, "en-US")]
|
||||
[GeneratedRegex(@"Release date: (.*?)[/](\d{1,2})[/](\d{4})", RegexOptions.IgnoreCase, "en-US")]
|
||||
private static partial Regex SalesDateRegex();
|
||||
|
||||
[GeneratedRegex(@"^(Early|Middle|Late)\s(.*?)\s(\d{4})", RegexOptions.IgnoreCase, "en-US")]
|
||||
@@ -24,140 +23,47 @@ public partial class EnglishVoiceWorksScanner(IHtmlLoader loader, ISpamCircleCac
|
||||
new AlingualLanguage()
|
||||
];
|
||||
|
||||
protected override DateTime? GetEstimatedReleaseDate(string expectedDate)
|
||||
protected override DateOnly? GetEstimatedReleaseDate(string expectedDate)
|
||||
{
|
||||
if (expectedDate.Contains("販売中") || expectedDate.Contains("発売予定未定"))
|
||||
if (expectedDate.Contains("Release Date: TBC", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
Regex textRegex = EstimatedDateRegex();
|
||||
MatchCollection textMatches = textRegex.Matches(expectedDate);
|
||||
Match match = EstimatedDateRegex().Match(expectedDate);
|
||||
|
||||
if (textMatches.Count == 0 || textMatches[0].Groups.Count < 4)
|
||||
if (match.Success == false)
|
||||
return null;
|
||||
|
||||
GroupCollection groups = textMatches[0].Groups;
|
||||
GroupCollection groups = match.Groups;
|
||||
|
||||
int releaseYear = Convert.ToInt32(groups[3].Value);
|
||||
|
||||
int releaseMonth = 1;
|
||||
int releaseDay = 1;
|
||||
|
||||
string releaseTime = groups[1].Value;
|
||||
string releaseMonthText = groups[2].Value;
|
||||
|
||||
switch (releaseTime)
|
||||
int day = groups[1].Value.ToLowerInvariant() switch
|
||||
{
|
||||
case "Early":
|
||||
releaseDay = 1;
|
||||
break;
|
||||
case "Middle":
|
||||
releaseDay = 11;
|
||||
break;
|
||||
case "Late":
|
||||
releaseDay = 21;
|
||||
break;
|
||||
}
|
||||
"early" => 1,
|
||||
"middle" => 11,
|
||||
"late" => 21,
|
||||
_ => 1
|
||||
};
|
||||
|
||||
switch (releaseMonthText)
|
||||
{
|
||||
case "Jan.":
|
||||
releaseMonth = 1;
|
||||
break;
|
||||
case "Feb.":
|
||||
releaseMonth = 2;
|
||||
break;
|
||||
case "Mar.":
|
||||
releaseMonth = 3;
|
||||
break;
|
||||
case "Apr.":
|
||||
releaseMonth = 4;
|
||||
break;
|
||||
case "May.":
|
||||
releaseMonth = 5;
|
||||
break;
|
||||
case "Jun.":
|
||||
releaseMonth = 6;
|
||||
break;
|
||||
case "Jul.":
|
||||
releaseMonth = 7;
|
||||
break;
|
||||
case "Aug.":
|
||||
releaseMonth = 8;
|
||||
break;
|
||||
case "Sep.":
|
||||
releaseMonth = 9;
|
||||
break;
|
||||
case "Oct.":
|
||||
releaseMonth = 10;
|
||||
break;
|
||||
case "Nov.":
|
||||
releaseMonth = 11;
|
||||
break;
|
||||
case "Dec.":
|
||||
releaseMonth = 12;
|
||||
break;
|
||||
}
|
||||
string monthAbbreviation = groups[2].Value.Replace(".", "");
|
||||
int month = DateTime.ParseExact(monthAbbreviation, "MMM", CultureInfo.InvariantCulture).Month;
|
||||
|
||||
return new DateTime(releaseYear, releaseMonth, releaseDay);
|
||||
int year = Convert.ToInt32(groups[3].Value);
|
||||
|
||||
return new DateOnly(year, month, day);
|
||||
}
|
||||
|
||||
protected override DateTime? GetSalesDate(string salesDate)
|
||||
protected override DateOnly? GetSalesDate(string salesDate)
|
||||
{
|
||||
Regex textRegex = SalesDateRegex();
|
||||
MatchCollection textMatches = textRegex.Matches(salesDate);
|
||||
Match match = SalesDateRegex().Match(salesDate);
|
||||
|
||||
if (textMatches.Count == 0 || textMatches[0].Groups.Count < 4)
|
||||
if (match.Success == false)
|
||||
return null;
|
||||
|
||||
string month = textMatches[0].Groups[1].Value;
|
||||
int releaseMonth = -1;
|
||||
string monthAbbreviation = match.Groups[1].Value;
|
||||
int day = int.Parse(match.Groups[2].Value);
|
||||
int year = int.Parse(match.Groups[3].Value);
|
||||
|
||||
switch (month)
|
||||
{
|
||||
case "Jan":
|
||||
releaseMonth = 1;
|
||||
break;
|
||||
case "Feb":
|
||||
releaseMonth = 2;
|
||||
break;
|
||||
case "Mar":
|
||||
releaseMonth = 3;
|
||||
break;
|
||||
case "Apr":
|
||||
releaseMonth = 4;
|
||||
break;
|
||||
case "May":
|
||||
releaseMonth = 5;
|
||||
break;
|
||||
case "Jun":
|
||||
releaseMonth = 6;
|
||||
break;
|
||||
case "Jul":
|
||||
releaseMonth = 7;
|
||||
break;
|
||||
case "Aug":
|
||||
releaseMonth = 8;
|
||||
break;
|
||||
case "Sep":
|
||||
releaseMonth = 9;
|
||||
break;
|
||||
case "Oct":
|
||||
releaseMonth = 10;
|
||||
break;
|
||||
case "Nov":
|
||||
releaseMonth = 11;
|
||||
break;
|
||||
case "Dec":
|
||||
releaseMonth = 12;
|
||||
break;
|
||||
}
|
||||
int month = DateTime.ParseExact(monthAbbreviation, "MMM", CultureInfo.InvariantCulture).Month;
|
||||
|
||||
if (releaseMonth == -1)
|
||||
return null;
|
||||
|
||||
int releaseYear = Convert.ToInt32(textMatches[0].Groups[3].Value);
|
||||
int releaseDay = Convert.ToInt32(textMatches[0].Groups[2].Value);
|
||||
|
||||
return new DateTime(releaseYear, releaseMonth, releaseDay);
|
||||
return new(year, month, day);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user