Automatic Collection Creation (#1768)

* Made the unread badges slightly smaller and rounded on top right.

* A bit more tweaks on the not read badges. Looking really nice now.

* In order to start the work on managing collections from ScanLoop, I needed to refactor collection apis into the service layer and add unit tests.

Removed ToUpper Normalization for new tags.

* Hooked up ability to auto generate collections from SeriesGroup metadata tag.
This commit is contained in:
Joe Milazzo 2023-01-30 19:57:46 -08:00 committed by GitHub
parent 91a2a6854f
commit 1da27f085c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 2222 additions and 121 deletions

View file

@ -45,6 +45,7 @@ public class ProcessSeries : IProcessSeries
private readonly IFileService _fileService;
private readonly IMetadataService _metadataService;
private readonly IWordCountAnalyzerService _wordCountAnalyzerService;
private readonly ICollectionTagService _collectionTagService;
private IList<Genre> _genres;
private IList<Person> _people;
@ -52,7 +53,8 @@ public class ProcessSeries : IProcessSeries
public ProcessSeries(IUnitOfWork unitOfWork, ILogger<ProcessSeries> logger, IEventHub eventHub,
IDirectoryService directoryService, ICacheHelper cacheHelper, IReadingItemService readingItemService,
IFileService fileService, IMetadataService metadataService, IWordCountAnalyzerService wordCountAnalyzerService)
IFileService fileService, IMetadataService metadataService, IWordCountAnalyzerService wordCountAnalyzerService,
ICollectionTagService collectionTagService)
{
_unitOfWork = unitOfWork;
_logger = logger;
@ -63,6 +65,7 @@ public class ProcessSeries : IProcessSeries
_fileService = fileService;
_metadataService = metadataService;
_wordCountAnalyzerService = wordCountAnalyzerService;
_collectionTagService = collectionTagService;
}
/// <summary>
@ -151,7 +154,7 @@ public class ProcessSeries : IProcessSeries
series.NormalizedLocalizedName = Parser.Parser.Normalize(series.LocalizedName);
}
UpdateSeriesMetadata(series, library.Type);
await UpdateSeriesMetadata(series, library);
// Update series FolderPath here
await UpdateSeriesFolderPath(parsedInfos, library, series);
@ -223,10 +226,10 @@ public class ProcessSeries : IProcessSeries
BackgroundJob.Enqueue(() => _wordCountAnalyzerService.ScanSeries(libraryId, seriesId, forceUpdate));
}
private static void UpdateSeriesMetadata(Series series, LibraryType libraryType)
private async Task UpdateSeriesMetadata(Series series, Library library)
{
series.Metadata ??= DbFactory.SeriesMetadata(new List<CollectionTag>());
var isBook = libraryType == LibraryType.Book;
var isBook = library.Type == LibraryType.Book;
var firstChapter = SeriesService.GetFirstChapterForMetadata(series, isBook);
var firstFile = firstChapter?.Files.FirstOrDefault();
@ -278,6 +281,14 @@ public class ProcessSeries : IProcessSeries
series.Metadata.Language = firstChapter.Language;
}
if (!string.IsNullOrEmpty(firstChapter.SeriesGroup) && library.ManageCollections)
{
_logger.LogDebug("Collection tag found for {SeriesName}", series.Name);
var tag = await _collectionTagService.GetTagOrCreate(0, firstChapter.SeriesGroup);
_collectionTagService.AddTagToSeriesMetadata(tag, series.Metadata);
}
// Handle People
foreach (var chapter in chapters)
{
@ -629,6 +640,11 @@ public class ProcessSeries : IProcessSeries
chapter.Language = comicInfo.LanguageISO;
}
if (!string.IsNullOrEmpty(comicInfo.SeriesGroup))
{
chapter.SeriesGroup = comicInfo.SeriesGroup;
}
if (comicInfo.Count > 0)
{
chapter.TotalCount = comicInfo.Count;