From 519cf60fc8942df94668bdf9a751a56ac64986ce Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 11 May 2025 10:04:52 -0500 Subject: [PATCH] Send better data to Kavita+ related to AltNames and Year. Fixed a localization issue which prevented issue count showing on Series Match Result. --- API/Services/Plus/ExternalMetadataService.cs | 30 +++++++++++++++---- API/Services/Tasks/Scanner/Parser/Parser.cs | 6 ++++ .../match-series-result-item.component.html | 2 +- UI/Web/src/assets/langs/en.json | 1 + 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/API/Services/Plus/ExternalMetadataService.cs b/API/Services/Plus/ExternalMetadataService.cs index a1e3750dd..cd6fbce25 100644 --- a/API/Services/Plus/ExternalMetadataService.cs +++ b/API/Services/Plus/ExternalMetadataService.cs @@ -200,6 +200,9 @@ public class ExternalMetadataService : IExternalMetadataService /// /// Returns the match results for a Series from UI Flow /// + /// + /// Will extract alternative names like Localized name, year will send as ReleaseYear but fallback to Comic Vine syntax if applicable + /// /// /// public async Task> MatchSeries(MatchSeriesDto dto) @@ -212,19 +215,22 @@ public class ExternalMetadataService : IExternalMetadataService var potentialAnilistId = ScrobblingService.ExtractId(dto.Query, ScrobblingService.AniListWeblinkWebsite); var potentialMalId = ScrobblingService.ExtractId(dto.Query, ScrobblingService.MalWeblinkWebsite); - List altNames = [series.LocalizedName, series.OriginalName]; - if (potentialAnilistId == null && potentialMalId == null && !string.IsNullOrEmpty(dto.Query)) + var format = series.Library.Type.ConvertToPlusMediaFormat(series.Format); + var otherNames = ExtractAlternativeNames(dto, series); + + var year = series.Metadata.ReleaseYear; + if (year == 0 && format == PlusMediaFormat.Comic) { - altNames.Add(dto.Query); + year = int.Parse(Parser.ParseYear(series.Name)); } var matchRequest = new MatchSeriesRequestDto() { - Format = series.Library.Type.ConvertToPlusMediaFormat(series.Format), + Format = format, Query = dto.Query, SeriesName = series.Name, - AlternativeNames = altNames.Where(s => !string.IsNullOrEmpty(s)).ToList(), - Year = series.Metadata.ReleaseYear, + AlternativeNames = otherNames, + Year = year, AniListId = potentialAnilistId ?? ScrobblingService.GetAniListId(series), MalId = potentialMalId ?? ScrobblingService.GetMalId(series) }; @@ -254,6 +260,18 @@ public class ExternalMetadataService : IExternalMetadataService return ArraySegment.Empty; } + private static List ExtractAlternativeNames(MatchSeriesDto dto, Series series) + { + List altNames = [series.LocalizedName, series.OriginalName]; + // if (potentialAnilistId == null && potentialMalId == null && !string.IsNullOrEmpty(dto.Query)) + // { + // altNames.Add(dto.Query); + // } + + var otherNames = altNames.Where(s => !string.IsNullOrEmpty(s)).Distinct().ToList(); + return otherNames; + } + /// /// Retrieves Metadata about a Recommended External Series diff --git a/API/Services/Tasks/Scanner/Parser/Parser.cs b/API/Services/Tasks/Scanner/Parser/Parser.cs index 12987b18b..c8eb010b3 100644 --- a/API/Services/Tasks/Scanner/Parser/Parser.cs +++ b/API/Services/Tasks/Scanner/Parser/Parser.cs @@ -1159,6 +1159,12 @@ public static partial class Parser return !string.IsNullOrEmpty(name) && SeriesAndYearRegex.IsMatch(name); } + /// + /// Parse a Year from a Comic Series: Series Name (YEAR) + /// + /// Harley Quinn (2024) returns 2024 + /// + /// public static string ParseYear(string? name) { if (string.IsNullOrEmpty(name)) return string.Empty; diff --git a/UI/Web/src/app/_single-module/match-series-result-item/match-series-result-item.component.html b/UI/Web/src/app/_single-module/match-series-result-item/match-series-result-item.component.html index 2d94dd848..322a16bd8 100644 --- a/UI/Web/src/app/_single-module/match-series-result-item/match-series-result-item.component.html +++ b/UI/Web/src/app/_single-module/match-series-result-item/match-series-result-item.component.html @@ -33,10 +33,10 @@ } @else {
@if ((item.series.volumes || 0) > 0 || (item.series.chapters || 0) > 0) { - {{t('volume-count', {num: item.series.volumes})}} @if (item.series.plusMediaFormat === PlusMediaFormat.Comic) { {{t('issue-count', {num: item.series.chapters})}} } @else { + {{t('volume-count', {num: item.series.volumes})}} {{t('chapter-count', {num: item.series.chapters})}} } } @else { diff --git a/UI/Web/src/assets/langs/en.json b/UI/Web/src/assets/langs/en.json index 19d4443b6..13e61fdef 100644 --- a/UI/Web/src/assets/langs/en.json +++ b/UI/Web/src/assets/langs/en.json @@ -2911,6 +2911,7 @@ "author-count": "{{num}} Authors", "item-count": "{{num}} Items", "chapter-count": "{{num}} Chapters", + "issue-count": "{{num}} Issues", "no-data": "No Data", "book-num": "Book",