Added Chobit integration. Updated tests.
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
|
||||
public class ChobitResult
|
||||
{
|
||||
[JsonPropertyName("count")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[JsonPropertyName("works")]
|
||||
public ChobitWork[] Works { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
|
||||
public class ChobitResultCollection : Dictionary<string, ChobitResult> { }
|
||||
@@ -1,16 +1,39 @@
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
|
||||
public class ChobitWork
|
||||
{
|
||||
[JsonPropertyName("work_id")]
|
||||
public string? WorkId { get; set; }
|
||||
|
||||
[JsonPropertyName("dlsite_work_id")]
|
||||
public string? DLSiteWorkId { get; set; }
|
||||
|
||||
[JsonPropertyName("work_name")]
|
||||
public string? WorkName { get; set; }
|
||||
|
||||
[JsonPropertyName("work_name_kana")]
|
||||
public string? WorkNameKana { get; set; }
|
||||
public string? URL { get; set; }
|
||||
public string? EmbedURL { get; set; }
|
||||
|
||||
[JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
[JsonPropertyName("embed_url")]
|
||||
public string? EmbedUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("thumb")]
|
||||
public string? Thumb { get; set; }
|
||||
|
||||
[JsonPropertyName("mini_thumb")]
|
||||
public string? MiniThumb { get; set; }
|
||||
|
||||
[JsonPropertyName("file_type")]
|
||||
public string? FileType { get; set; }
|
||||
|
||||
[JsonPropertyName("embed_width")]
|
||||
public decimal EmbedWidth { get; set; }
|
||||
|
||||
[JsonPropertyName("embed_height")]
|
||||
public decimal EmbedHeight { get; set; }
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace JSMR.Application.Integrations.Chobit.Models;
|
||||
|
||||
public class ChobitWorkResult : Dictionary<string, ChobitResult> { }
|
||||
@@ -4,5 +4,6 @@ namespace JSMR.Application.Integrations.Ports;
|
||||
|
||||
public interface IChobitClient
|
||||
{
|
||||
Task<ChobitWorkResult> GetSampleInfoAsync(string[] productIds, CancellationToken cancellationToken = default);
|
||||
Task<ChobitResult> GetSampleInfoAsync(string productId, CancellationToken cancellationToken = default);
|
||||
Task<ChobitResultCollection> GetSampleInfoAsync(string[] productIds, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using JSMR.Application.Integrations.DLSite.Models;
|
||||
using JSMR.Application.Integrations.Chobit.Models;
|
||||
using JSMR.Application.Integrations.DLSite.Models;
|
||||
using JSMR.Domain.Enums;
|
||||
using JSMR.Domain.ValueObjects;
|
||||
|
||||
@@ -16,7 +17,7 @@ public sealed record VoiceWorkIngest
|
||||
public int WishlistCount { get; init; }
|
||||
public int Downloads { get; init; }
|
||||
public bool HasTrial { get; init; }
|
||||
public bool HasDLPlay { get; init; }
|
||||
public bool HasChobit { get; init; }
|
||||
public byte? StarRating { get; init; }
|
||||
public int? Votes { get; init; }
|
||||
public AgeRating AgeRating { get; init; }
|
||||
@@ -29,7 +30,7 @@ public sealed record VoiceWorkIngest
|
||||
public VoiceWorkSeries? Series { get; init; }
|
||||
public VoiceWorkTranslation? Translation { get; init; }
|
||||
|
||||
public static VoiceWorkIngest From(DLSiteWork work, VoiceWorkDetails? details)
|
||||
public static VoiceWorkIngest From(DLSiteWork work, VoiceWorkDetails? details, ChobitResult? chobit)
|
||||
{
|
||||
return new VoiceWorkIngest()
|
||||
{
|
||||
@@ -43,7 +44,7 @@ public sealed record VoiceWorkIngest
|
||||
WishlistCount = details?.WishlistCount ?? 0,
|
||||
Downloads = Math.Max(work.Downloads, details?.DownloadCount ?? 0),
|
||||
HasTrial = work.HasTrial || (details?.HasTrial ?? false),
|
||||
HasDLPlay = details?.HasDLPlay ?? false,
|
||||
HasChobit = chobit?.Count > 0,
|
||||
StarRating = work.StarRating,
|
||||
Votes = work.Votes,
|
||||
AgeRating = details?.AgeRating ?? work.AgeRating,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JSMR.Application.Common.Caching;
|
||||
using JSMR.Application.Integrations.Chobit.Models;
|
||||
using JSMR.Application.Integrations.DLSite.Models;
|
||||
using JSMR.Application.Integrations.Ports;
|
||||
using JSMR.Application.Scanning.Contracts;
|
||||
@@ -10,6 +11,7 @@ public sealed class ScanVoiceWorksHandler(
|
||||
IVoiceWorkScannerRepository scannerRepository,
|
||||
IVoiceWorkUpdaterRepository updaterRepository,
|
||||
IDLSiteClient dlsiteClient,
|
||||
IChobitClient chobitClient,
|
||||
ISpamCircleCache spamCircleCache,
|
||||
IVoiceWorkSearchUpdater searchUpdater)
|
||||
{
|
||||
@@ -44,11 +46,13 @@ public sealed class ScanVoiceWorksHandler(
|
||||
|
||||
string[] productIds = [.. scanResult.Works.Where(x => !string.IsNullOrWhiteSpace(x.ProductId)).Select(x => x.ProductId!)];
|
||||
VoiceWorkDetailCollection voiceWorkDetails = await dlsiteClient.GetVoiceWorkDetailsAsync(productIds, cancellationToken);
|
||||
ChobitResultCollection chobitResults = await chobitClient.GetSampleInfoAsync(productIds, cancellationToken);
|
||||
|
||||
VoiceWorkIngest[] ingests = [.. scanResult.Works.Select(work =>
|
||||
{
|
||||
voiceWorkDetails.TryGetValue(work.ProductId!, out VoiceWorkDetails? value);
|
||||
return VoiceWorkIngest.From(work, value);
|
||||
chobitResults.TryGetValue(work.ProductId, out ChobitResult? chobit);
|
||||
return VoiceWorkIngest.From(work, value, chobit);
|
||||
})];
|
||||
|
||||
VoiceWorkUpsertResult[] upsertResults = await updater.UpsertAsync(ingests, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user