After reviewing, this needs some major work to finish it off.
This commit is contained in:
parent
bad5c9dcd6
commit
29167f281e
4 changed files with 40 additions and 14 deletions
|
@ -34,10 +34,10 @@ public class MagazineParserTests
|
|||
Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseMagazineChapter(filename));
|
||||
}
|
||||
|
||||
// [Theory]
|
||||
// [InlineData("AIR International Vol. 14 No. 3 (ISSN 1011-3250)", "1011-3250")]
|
||||
// public void ParseGTINTest(string filename, string expected)
|
||||
// {
|
||||
// Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseGTIN(filename));
|
||||
// }
|
||||
[Theory]
|
||||
[InlineData("AIR International Vol. 14 No. 3 (ISSN 1011-3250)", "1011-3250")]
|
||||
public void ParseGTINTest(string filename, string expected)
|
||||
{
|
||||
Assert.Equal(expected, API.Services.Tasks.Scanner.Parser.Parser.ParseGTIN(filename));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ public interface ISeriesService
|
|||
Task<bool> UpdateRelatedSeries(UpdateRelatedSeriesDto dto);
|
||||
Task<RelatedSeriesDto> GetRelatedSeries(int userId, int seriesId);
|
||||
Task<string> FormatChapterTitle(int userId, ChapterDto chapter, LibraryType libraryType, bool withHash = true);
|
||||
Task<string> FormatChapterTitle(int userId, Chapter chapter, LibraryType libraryType, bool withHash = true);
|
||||
Task<string> FormatChapterTitle(int userId, bool isSpecial, LibraryType libraryType, string chapterRange, string? chapterTitle,
|
||||
bool withHash);
|
||||
Task<string> FormatChapterName(int userId, LibraryType libraryType, bool withHash = false);
|
||||
|
@ -633,7 +632,7 @@ public class SeriesService : ISeriesService
|
|||
|
||||
public async Task<string> FormatChapterTitle(int userId, bool isSpecial, LibraryType libraryType, string chapterRange, string? chapterTitle, bool withHash)
|
||||
{
|
||||
if (string.IsNullOrEmpty(chapterTitle) && (isSpecial || libraryType == LibraryType.Book)) throw new ArgumentException("Chapter Title cannot be null");
|
||||
if (string.IsNullOrEmpty(chapterTitle) && (isSpecial || (libraryType == LibraryType.Book || libraryType == LibraryType.Magazine))) throw new ArgumentException("Chapter Title cannot be null");
|
||||
|
||||
if (isSpecial)
|
||||
{
|
||||
|
@ -643,10 +642,10 @@ public class SeriesService : ISeriesService
|
|||
var hashSpot = withHash ? "#" : string.Empty;
|
||||
var baseChapter = libraryType switch
|
||||
{
|
||||
LibraryType.Book => await _localizationService.Translate(userId, "book-num", chapterTitle!),
|
||||
LibraryType.Book => await _localizationService.Translate(userId, "book-num", chapterTitle ?? string.Empty),
|
||||
LibraryType.LightNovel => await _localizationService.Translate(userId, "book-num", chapterRange),
|
||||
LibraryType.Comic => await _localizationService.Translate(userId, "issue-num", hashSpot, chapterRange),
|
||||
LibraryType.Magazine => await _localizationService.Translate(userId, "issue-num", hashSpot, chapterTitle),
|
||||
LibraryType.Magazine => await _localizationService.Translate(userId, "issue-num", hashSpot, chapterTitle ?? string.Empty),
|
||||
LibraryType.ComicVine => await _localizationService.Translate(userId, "issue-num", hashSpot, chapterRange),
|
||||
LibraryType.Manga => await _localizationService.Translate(userId, "chapter-num", chapterRange),
|
||||
LibraryType.Image => await _localizationService.Translate(userId, "chapter-num", chapterRange),
|
||||
|
@ -667,10 +666,6 @@ public class SeriesService : ISeriesService
|
|||
return await FormatChapterTitle(userId, chapter.IsSpecial, libraryType, chapter.Range, chapter.Title, withHash);
|
||||
}
|
||||
|
||||
public async Task<string> FormatChapterTitle(int userId, Chapter chapter, LibraryType libraryType, bool withHash = true)
|
||||
{
|
||||
return await FormatChapterTitle(userId, chapter.IsSpecial, libraryType, chapter.Range, chapter.Title, withHash);
|
||||
}
|
||||
|
||||
// TODO: Refactor this out and use FormatChapterTitle instead across library
|
||||
public async Task<string> FormatChapterName(int userId, LibraryType libraryType, bool withHash = false)
|
||||
|
|
|
@ -42,6 +42,7 @@ public class MagazineParser(IDirectoryService directoryService) : DefaultParser(
|
|||
{
|
||||
ret.Series = Parser.CleanTitle(folders[^1]);
|
||||
}
|
||||
|
||||
var hasGeoCode = !string.IsNullOrEmpty(Parser.ParseGeoCode(ret.Series));
|
||||
foreach (var folder in folders[..^1])
|
||||
{
|
||||
|
|
|
@ -958,6 +958,36 @@ public static partial class Parser
|
|||
}
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// Tries to parse a GTIN/ISBN out of a string
|
||||
// /// </summary>
|
||||
// /// <param name="value"></param>
|
||||
// /// <returns></returns>
|
||||
// public static string? ParseGTIN(string? value)
|
||||
// {
|
||||
// if (string.IsNullOrEmpty(value)) return value;
|
||||
// const string pattern = @"\b(?:\(|\[|\{)([A-Z]{2})(?:\)|\]|\})\b|^([A-Z]{2})$";
|
||||
//
|
||||
// // Match the pattern in the input string
|
||||
// var match = Regex.Match(value, pattern, RegexOptions.IgnoreCase);
|
||||
//
|
||||
// if (match.Success)
|
||||
// {
|
||||
// // Extract the GeoCode from the first capturing group if it exists,
|
||||
// // otherwise, extract the GeoCode from the second capturing group
|
||||
// var extractedCode = match.Groups[1].Success ? match.Groups[1].Value : match.Groups[2].Value;
|
||||
//
|
||||
// // Validate the extracted GeoCode against the list of valid GeoCodes
|
||||
// if (GeoCodes.Contains(extractedCode))
|
||||
// {
|
||||
// return extractedCode;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
private static string FormatValue(string value, bool hasPart)
|
||||
{
|
||||
if (!value.Contains('-'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue