Moved some classes around to the domain layer.
This commit is contained in:
@@ -11,7 +11,7 @@ public class VoiceWorkDetails
|
||||
public int WishlistCount { get; init; }
|
||||
public int DownloadCount { get; init; }
|
||||
public DateTime? RegistrationDate { get; init; }
|
||||
public SupportedLanguage[] SupportedLanguages { get; init; } = [];
|
||||
public IReadOnlyList<SupportedLanguage> SupportedLanguages { get; init; } = [];
|
||||
public AIGeneration AI { get; init; }
|
||||
public bool HasTrial { get; init; }
|
||||
public bool HasDLPlay { get; init; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace JSMR.Application.Integrations.DLSite.Models;
|
||||
|
||||
public class VoiceWorkSeries
|
||||
{
|
||||
public required string Identifier { get; init; }
|
||||
public required string Name { get; init; }
|
||||
}
|
||||
//public class VoiceWorkSeries
|
||||
//{
|
||||
// public required string Identifier { get; init; }
|
||||
// public required string Name { get; init; }
|
||||
//}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace JSMR.Application.Integrations.DLSite.Models;
|
||||
|
||||
public class VoiceWorkTranslation
|
||||
{
|
||||
public required string OriginalProductId { get; init; }
|
||||
public bool IsOfficialTranslation { get; init; }
|
||||
public bool IsRecommendedTranslation { get; init; }
|
||||
public required Language Language { get; init; }
|
||||
}
|
||||
//public class VoiceWorkTranslation
|
||||
//{
|
||||
// public required string OriginalProductId { get; init; }
|
||||
// public bool IsOfficialTranslation { get; init; }
|
||||
// public bool IsRecommendedTranslation { get; init; }
|
||||
// public required Language Language { get; init; }
|
||||
//}
|
||||
@@ -21,7 +21,7 @@ public sealed record VoiceWorkIngest
|
||||
public int? Votes { get; init; }
|
||||
public AgeRating AgeRating { get; init; }
|
||||
public bool HasImage { get; init; }
|
||||
public ICollection<SupportedLanguage> SupportedLanguages { get; init; } = [];
|
||||
public IReadOnlyList<SupportedLanguage> SupportedLanguages { get; init; } = [];
|
||||
public DateOnly? ExpectedDate { get; init; }
|
||||
public DateOnly? SalesDate { get; init; }
|
||||
public DateTime? RegistrationDate { get; init; }
|
||||
|
||||
9
JSMR.Domain/Enums/TranslationKind.cs
Normal file
9
JSMR.Domain/Enums/TranslationKind.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace JSMR.Domain.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum TranslationKind
|
||||
{
|
||||
None = 0,
|
||||
Official = 1,
|
||||
Recommended = 2
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using JSMR.Domain.Enums;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace JSMR.Domain.ValueObjects;
|
||||
|
||||
@@ -26,14 +27,14 @@ public sealed record SupportedLanguage(string Code, Language Language)
|
||||
private static readonly Dictionary<Language, SupportedLanguage> _byLang =
|
||||
All.ToDictionary(x => x.Language);
|
||||
|
||||
public static bool TryFromCode(string code, out SupportedLanguage? supportedLanguage) =>
|
||||
public static bool TryFromCode(string code, [MaybeNullWhen(false)] out SupportedLanguage supportedLanguage) =>
|
||||
_byCode.TryGetValue(code, out supportedLanguage);
|
||||
|
||||
public static bool TryFromLanguage(Language lang, out SupportedLanguage? supportedLanguage) =>
|
||||
_byLang.TryGetValue(lang, out supportedLanguage);
|
||||
public static bool TryFromLanguage(Language language, [MaybeNullWhen(false)] out SupportedLanguage supportedLanguage) =>
|
||||
_byLang.TryGetValue(language, out supportedLanguage);
|
||||
|
||||
public static SupportedLanguage FromLanguage(Language language) =>
|
||||
_byLang.TryGetValue(language, out var sl)
|
||||
? sl
|
||||
_byLang.TryGetValue(language, out SupportedLanguage? supportedLanguage)
|
||||
? supportedLanguage
|
||||
: throw new ArgumentOutOfRangeException(nameof(language), $"Unsupported: {language}");
|
||||
}
|
||||
3
JSMR.Domain/ValueObjects/VoiceWorkSeries.cs
Normal file
3
JSMR.Domain/ValueObjects/VoiceWorkSeries.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace JSMR.Domain.ValueObjects;
|
||||
|
||||
public sealed record VoiceWorkSeries(string Identifier, string Name);
|
||||
8
JSMR.Domain/ValueObjects/VoiceWorkTranslation.cs
Normal file
8
JSMR.Domain/ValueObjects/VoiceWorkTranslation.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using JSMR.Domain.Enums;
|
||||
|
||||
namespace JSMR.Domain.ValueObjects;
|
||||
|
||||
public sealed record VoiceWorkTranslation(
|
||||
string OriginalProductId,
|
||||
Language Language,
|
||||
TranslationKind Kind = TranslationKind.None);
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace JSMR.Infrastructure.Common.Locales;
|
||||
|
||||
public class EnglishLocale : ILocale
|
||||
{
|
||||
public string Abbreviation => "en";
|
||||
public string Code => "en_US";
|
||||
}
|
||||
//public class EnglishLocale : ILocale
|
||||
//{
|
||||
// public string Abbreviation => "en";
|
||||
// public string Code => "en_US";
|
||||
//}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace JSMR.Infrastructure.Common.Locales;
|
||||
|
||||
public interface ILocale
|
||||
{
|
||||
string Abbreviation { get; }
|
||||
string Code { get; }
|
||||
}
|
||||
//public interface ILocale
|
||||
//{
|
||||
// string Abbreviation { get; }
|
||||
// string Code { get; }
|
||||
//}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace JSMR.Infrastructure.Common.Locales;
|
||||
|
||||
public class JapaneseLocale : ILocale
|
||||
{
|
||||
public string Abbreviation => "jp";
|
||||
public string Code => "ja_JP";
|
||||
}
|
||||
//public class JapaneseLocale : ILocale
|
||||
//{
|
||||
// public string Abbreviation => "jp";
|
||||
// public string Code => "ja_JP";
|
||||
//}
|
||||
@@ -16,25 +16,6 @@ public static class DLSiteToDomainMapper
|
||||
private const string OptAIFull = "AIG";
|
||||
private const string OptAIPartial = "AIP";
|
||||
|
||||
private static readonly (string Code, Language Lang)[] SupportedLanguageFlags =
|
||||
[
|
||||
(SupportedLanguage.Japanese.Code, Language.Japanese),
|
||||
(SupportedLanguage.English.Code, Language.English),
|
||||
(SupportedLanguage.ChineseTraditional.Code, Language.ChineseTraditional),
|
||||
(SupportedLanguage.ChineseSimplified.Code, Language.ChineseSimplified)
|
||||
];
|
||||
|
||||
private static readonly (string Code, SupportedLanguage Lang)[] SupportedLanguageFlags2 =
|
||||
[
|
||||
(SupportedLanguage.Japanese.Code, SupportedLanguage.Japanese),
|
||||
(SupportedLanguage.English.Code, SupportedLanguage.English),
|
||||
(SupportedLanguage.ChineseTraditional.Code, SupportedLanguage.ChineseTraditional),
|
||||
(SupportedLanguage.ChineseSimplified.Code, SupportedLanguage.ChineseSimplified)
|
||||
];
|
||||
|
||||
private static readonly Dictionary<string, Language> TranslationLanguageMap =
|
||||
SupportedLanguageFlags.ToDictionary(x => x.Code, x => x.Lang, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private static readonly Dictionary<int, AgeRating> AgeRatingMap = new()
|
||||
{
|
||||
{ 1, AgeRating.AllAges },
|
||||
@@ -89,11 +70,10 @@ public static class DLSiteToDomainMapper
|
||||
if (string.IsNullOrWhiteSpace(productInfo.TitleId) || string.IsNullOrWhiteSpace(productInfo.TitleName))
|
||||
return null;
|
||||
|
||||
return new VoiceWorkSeries
|
||||
{
|
||||
Identifier = productInfo.TitleId,
|
||||
Name = productInfo.TitleName
|
||||
};
|
||||
return new VoiceWorkSeries(
|
||||
Identifier: productInfo.TitleId,
|
||||
Name: productInfo.TitleName
|
||||
);
|
||||
}
|
||||
|
||||
private static VoiceWorkTranslation? MapTranslation(ProductInfo info, HashSet<string> options)
|
||||
@@ -108,30 +88,37 @@ public static class DLSiteToDomainMapper
|
||||
if (!options.Contains(languageCode))
|
||||
return null;
|
||||
|
||||
if (!TranslationLanguageMap.TryGetValue(languageCode, out Language language))
|
||||
if (!SupportedLanguage.TryFromCode(languageCode, out SupportedLanguage? supportedLanguage))
|
||||
return null;
|
||||
|
||||
string originalId = translationInfo.OriginalWorkNumber;
|
||||
bool isOfficial = options.Contains(OptOfficialTranslation);
|
||||
bool isRecommended = options.Contains(OptRecommendedTranslation);
|
||||
|
||||
return new VoiceWorkTranslation
|
||||
{
|
||||
OriginalProductId = originalId,
|
||||
Language = language,
|
||||
IsOfficialTranslation = isOfficial,
|
||||
IsRecommendedTranslation = isRecommended
|
||||
};
|
||||
TranslationKind translationKind = TranslationKind.None;
|
||||
|
||||
if (options.Contains(OptOfficialTranslation))
|
||||
translationKind |= TranslationKind.Official;
|
||||
|
||||
if (options.Contains(OptRecommendedTranslation))
|
||||
translationKind |= TranslationKind.Recommended;
|
||||
|
||||
//bool isOfficial = options.Contains(OptOfficialTranslation);
|
||||
//bool isRecommended = options.Contains(OptRecommendedTranslation);
|
||||
|
||||
return new VoiceWorkTranslation(
|
||||
OriginalProductId: originalId,
|
||||
Language: supportedLanguage.Language,
|
||||
Kind: translationKind
|
||||
);
|
||||
}
|
||||
|
||||
private static SupportedLanguage[] MapSupportedLanguages(HashSet<string> options)
|
||||
{
|
||||
List<SupportedLanguage> languages = [];
|
||||
|
||||
foreach (var (code, language) in SupportedLanguageFlags2)
|
||||
foreach (SupportedLanguage supportedLanguage in SupportedLanguage.All)
|
||||
{
|
||||
if (options.Contains(code) && !languages.Contains(language))
|
||||
languages.Add(language);
|
||||
if (options.Contains(supportedLanguage.Code) && !languages.Contains(supportedLanguage))
|
||||
languages.Add(supportedLanguage);
|
||||
}
|
||||
|
||||
return [.. languages];
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using JSMR.Domain.ValueObjects;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Application.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
|
||||
namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
public class DLSiteSearchFilterBuilder
|
||||
public sealed class DLSiteSearchFilterBuilder
|
||||
{
|
||||
private readonly List<string> _optionsAnd = [];
|
||||
private readonly List<string> _optionsNot = [];
|
||||
private readonly List<string> _excludedMakers = [];
|
||||
|
||||
private ILocale _locale = new JapaneseLocale();
|
||||
private Locale _locale = Locale.Japanese;
|
||||
|
||||
private void AddToOptionsAnd(string value)
|
||||
{
|
||||
@@ -27,7 +27,7 @@ public class DLSiteSearchFilterBuilder
|
||||
_optionsNot.Add(value);
|
||||
}
|
||||
|
||||
public DLSiteSearchFilterBuilder UseLocale(ILocale locale)
|
||||
public DLSiteSearchFilterBuilder UseLocale(Locale locale)
|
||||
{
|
||||
_locale = locale;
|
||||
|
||||
@@ -90,12 +90,12 @@ public class DLSiteSearchFilterBuilder
|
||||
|
||||
public string BuildSearchQuery(int pageNumber, int pageSize)
|
||||
{
|
||||
ILocale locale = _locale ?? new JapaneseLocale();
|
||||
var (localeAbbreviation, localeCode) = LocaleMap.Map[_locale];
|
||||
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
writer.Write($"https://www.dlsite.com/maniax/");
|
||||
writer.Write($"fsr/=/language/{locale.Abbreviation}/");
|
||||
writer.Write($"fsr/=/language/{localeAbbreviation}/");
|
||||
|
||||
writer.Write("sex_category[0]/male/");
|
||||
writer.Write("ana_flg/all/");
|
||||
@@ -129,7 +129,7 @@ public class DLSiteSearchFilterBuilder
|
||||
writer.Write($"per_page/{pageSize}/");
|
||||
writer.Write($"page/{pageNumber}/");
|
||||
writer.Write("show_type/1/");
|
||||
writer.Write($"?locale={locale.Code}");
|
||||
writer.Write($"?locale={localeCode}");
|
||||
|
||||
return writer.ToString();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using JSMR.Domain.ValueObjects;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
|
||||
namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
@@ -8,12 +7,12 @@ public static class DLSiteSearchFilterBuilderExtensions
|
||||
{
|
||||
public static DLSiteSearchFilterBuilder UseDefaultLocale(this DLSiteSearchFilterBuilder searchFilterBuilder)
|
||||
{
|
||||
return searchFilterBuilder.UseLocale(new JapaneseLocale());
|
||||
return searchFilterBuilder.UseLocale(Locale.Japanese);
|
||||
}
|
||||
|
||||
public static DLSiteSearchFilterBuilder UseEnglishLocale(this DLSiteSearchFilterBuilder searchFilterBuilder)
|
||||
{
|
||||
return searchFilterBuilder.UseLocale(new EnglishLocale());
|
||||
return searchFilterBuilder.UseLocale(Locale.English);
|
||||
}
|
||||
|
||||
public static DLSiteSearchFilterBuilder IncludeJapaneseSupportedLanguage(this DLSiteSearchFilterBuilder searchFilterBuilder)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using JSMR.Application.Common;
|
||||
using JSMR.Application.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -16,7 +14,7 @@ public partial class EnglishVoiceWorksScanner(IHtmlLoader loader) : VoiceWorksSc
|
||||
[GeneratedRegex(@"^(Early|Middle|Late)\s(.*?)\s(\d{4})", RegexOptions.IgnoreCase, "en-US")]
|
||||
private static partial Regex EstimatedDateRegex();
|
||||
|
||||
protected override ILocale Locale => new EnglishLocale();
|
||||
protected override Locale Locale => Locale.English;
|
||||
|
||||
protected override SupportedLanguage[] SupportedLanguages =>
|
||||
[
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using JSMR.Application.Common;
|
||||
using JSMR.Application.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@@ -15,7 +13,7 @@ public partial class JapaneseVoiceWorksScanner(IHtmlLoader loader) : VoiceWorksS
|
||||
[GeneratedRegex("販売日: (.*?)年(.*?)月(.*)日", RegexOptions.IgnoreCase, "en-US")]
|
||||
private static partial Regex SalesDateRegex();
|
||||
|
||||
protected override ILocale Locale => new JapaneseLocale();
|
||||
protected override Locale Locale => Locale.Japanese;
|
||||
|
||||
protected override SupportedLanguage[] SupportedLanguages =>
|
||||
[
|
||||
|
||||
16
JSMR.Infrastructure/Scanning/LocaleMap.cs
Normal file
16
JSMR.Infrastructure/Scanning/LocaleMap.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using JSMR.Application.Enums;
|
||||
|
||||
namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
internal class LocaleMap
|
||||
{
|
||||
public static readonly IReadOnlyDictionary<Locale, (string Abbreviation, string Code)> Map =
|
||||
new Dictionary<Locale, (string, string)>
|
||||
{
|
||||
{ Locale.Japanese, ("jp", "ja_JP") },
|
||||
{ Locale.English, ("en", "en_US") },
|
||||
{ Locale.ChineseSimplified, ("zh-cn", "zh_CN") },
|
||||
{ Locale.ChineseTraditional, ("zh-tw", "zh_TW") },
|
||||
{ Locale.Korean, ("ko", "ko_KR") },
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using HtmlAgilityPack;
|
||||
using JSMR.Application.Enums;
|
||||
using JSMR.Application.Scanning.Contracts;
|
||||
using JSMR.Application.Scanning.Ports;
|
||||
using JSMR.Domain.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
using JSMR.Infrastructure.Common.Locales;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using JSMR.Infrastructure.Scanning.Models;
|
||||
using System.Globalization;
|
||||
@@ -13,7 +13,7 @@ namespace JSMR.Infrastructure.Scanning;
|
||||
|
||||
public abstract class VoiceWorksScanner(IHtmlLoader htmlLoader) : IVoiceWorksScanner
|
||||
{
|
||||
protected abstract ILocale Locale { get; }
|
||||
protected abstract Locale Locale { get; }
|
||||
protected abstract SupportedLanguage[] SupportedLanguages { get; }
|
||||
|
||||
protected abstract DateOnly? GetEstimatedReleaseDate(string expectedDate);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class DLSiteClientTests
|
||||
result["RJ01230163"].HasTrial.ShouldBeTrue();
|
||||
result["RJ01230163"].HasDLPlay.ShouldBeTrue();
|
||||
result["RJ01230163"].HasReviews.ShouldBeTrue();
|
||||
result["RJ01230163"].SupportedLanguages.Length.ShouldBe(1);
|
||||
result["RJ01230163"].SupportedLanguages.Count.ShouldBe(1);
|
||||
result["RJ01230163"].SupportedLanguages.Select(x => x.Language).ShouldContain(Language.English);
|
||||
result["RJ01230163"].DownloadCount.ShouldBe(659);
|
||||
result["RJ01230163"].WishlistCount.ShouldBe(380);
|
||||
@@ -78,7 +78,7 @@ public class DLSiteClientTests
|
||||
voiceWorkDetails.Series.Identifier.ShouldBe("SE0001");
|
||||
voiceWorkDetails.Series.Name.ShouldBe("Series 1");
|
||||
|
||||
voiceWorkDetails.SupportedLanguages.Length.ShouldBe(1);
|
||||
voiceWorkDetails.SupportedLanguages.Count.ShouldBe(1);
|
||||
voiceWorkDetails.SupportedLanguages[0].Language.ShouldBe(Language.Japanese);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user