Need to work out the rules with the community but basic metadata is done, just need the people.

This commit is contained in:
Joseph Milazzo 2025-03-18 17:42:58 -05:00
parent 585df0b5d3
commit 3557dba465
4 changed files with 79 additions and 7 deletions

View file

@ -19,9 +19,9 @@ public class ExternalChapterDto
public string? Summary { get; set; } public string? Summary { get; set; }
public string? Writer { get; set; } public IList<string>? Writers { get; set; }
public string? Artist { get; set; } public IList<string>? Artists { get; set; }
public DateTime? ReleaseDate { get; set; } public DateTime? ReleaseDate { get; set; }

View file

@ -35,11 +35,11 @@ public class ExternalSeriesDetailDto
public IList<SeriesCharacter>? Characters { get; set; } = []; public IList<SeriesCharacter>? Characters { get; set; } = [];
#region Comic Only #region Comic Only
public string Publisher { get; set; } public string? Publisher { get; set; }
/// <summary> /// <summary>
/// Only from CBR for <see cref="ScrobbleProvider.Cbr"/>. Full metadata about issues /// Only from CBR for <see cref="ScrobbleProvider.Cbr"/>. Full metadata about issues
/// </summary> /// </summary>
public IList<ExternalChapterDto> ChapterDtos { get; set; } public IList<ExternalChapterDto>? ChapterDtos { get; set; }
#endregion #endregion

View file

@ -47,6 +47,7 @@ public interface IChapterRepository
Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync(); Task<IEnumerable<string>> GetCoverImagesForLockedChaptersAsync();
Task<ChapterDto> AddChapterModifiers(int userId, ChapterDto chapter); Task<ChapterDto> AddChapterModifiers(int userId, ChapterDto chapter);
IEnumerable<Chapter> GetChaptersForSeries(int seriesId); IEnumerable<Chapter> GetChaptersForSeries(int seriesId);
Task<IList<Chapter>> GetAllChaptersForSeries(int seriesId);
} }
public class ChapterRepository : IChapterRepository public class ChapterRepository : IChapterRepository
{ {
@ -298,4 +299,13 @@ public class ChapterRepository : IChapterRepository
.Include(c => c.Volume) .Include(c => c.Volume)
.AsEnumerable(); .AsEnumerable();
} }
public async Task<IList<Chapter>> GetAllChaptersForSeries(int seriesId)
{
return await _context.Chapter
.Where(c => c.Volume.SeriesId == seriesId)
.OrderBy(c => c.SortOrder)
.Include(c => c.Volume)
.ToListAsync();
}
} }

View file

@ -836,7 +836,6 @@ public class ExternalMetadataService : IExternalMetadataService
} }
} }
// Download the image and save it
_unitOfWork.SeriesRepository.Update(series); _unitOfWork.SeriesRepository.Update(series);
await _unitOfWork.CommitAsync(); await _unitOfWork.CommitAsync();
@ -1038,8 +1037,71 @@ public class ExternalMetadataService : IExternalMetadataService
{ {
if (externalMetadata.PlusMediaFormat != PlusMediaFormat.Comic) return false; if (externalMetadata.PlusMediaFormat != PlusMediaFormat.Comic) return false;
var chapters = await _unitOfWork.ChapterRepository.GetChaptersAsync(1); if (externalMetadata.ChapterDtos == null || externalMetadata.ChapterDtos.Count == 0) return false;
return false;
// Get all volumes and chapters
var madeModification = false;
var allChapters = await _unitOfWork.ChapterRepository.GetAllChaptersForSeries(series.Id);
var matchedChapters = allChapters
.Join(
externalMetadata.ChapterDtos,
chapter => chapter.Range,
dto => dto.IssueNumber,
(chapter, dto) => (chapter, dto) // Create a tuple of matched pairs
)
.ToList();
foreach (var (chapter, potentialMatch) in matchedChapters)
{
_logger.LogDebug("Updating {ChapterNumber} with metadata", chapter.Range);
// Write the metadata
if (!string.IsNullOrEmpty(potentialMatch.Title) && !potentialMatch.Title.Contains(series.Name))
{
chapter.Title = potentialMatch.Title;
_unitOfWork.ChapterRepository.Update(chapter);
madeModification = true;
}
if (!chapter.SummaryLocked && string.IsNullOrEmpty(chapter.Summary) & !string.IsNullOrEmpty(potentialMatch.Summary))
{
chapter.Summary = potentialMatch.Summary;
_unitOfWork.ChapterRepository.Update(chapter);
madeModification = true;
}
// ReleaseDate
// Cover Image
// Update People (Writer/Artist/Publisher)
if (!chapter.PublisherLocked)
{
// Update publisher
}
//var artists = potentialMatch.Artists.Select(p => new PersonDto())
// await SeriesService.HandlePeopleUpdateAsync(series.Metadata, artists, PersonRole.CoverArtist, _unitOfWork);
//
// foreach (var person in series.Metadata.People.Where(p => p.Role == PersonRole.CoverArtist))
// {
// var meta = upstreamArtists.FirstOrDefault(c => c.Name == person.Person.Name);
// person.OrderWeight = 0;
// if (meta != null)
// {
// person.KavitaPlusConnection = true;
// }
// }
}
_unitOfWork.SeriesRepository.Update(series);
await _unitOfWork.CommitAsync();
return madeModification;
} }
private async Task<bool> UpdateCoverImage(Series series, MetadataSettingsDto settings, ExternalSeriesDetailDto externalMetadata) private async Task<bool> UpdateCoverImage(Series series, MetadataSettingsDto settings, ExternalSeriesDetailDto externalMetadata)