Release Testing Day 3 (#1946)

* Removed extra trace messages as the people issue might have been resolved.

* When registering, disable button until form is valid. Allow non-email formatted emails, but not blank.

* Fixed opds not having http(s)://

* Added a new API to allow scanning all libraries from end point

* Moved Bookmarks directory to Media tab

* Fixed an edge case for finding next chapter when we had volume 1,2 etc but they had the same chapter number.

* Code cleanup
This commit is contained in:
Joe Milazzo
2023-04-29 07:49:00 -05:00
committed by GitHub
parent 119ea35b62
commit 4e0e3608aa
17 changed files with 253 additions and 141 deletions
+34 -35
View File
@@ -25,7 +25,6 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using VersOne.Epub;
using VersOne.Epub.Options;
using Image = SixLabors.ImageSharp.Image;
namespace API.Services;
@@ -67,7 +66,7 @@ public class BookService : IBookService
private const string BookApiUrl = "book-resources?file=";
public static readonly EpubReaderOptions BookReaderOptions = new()
{
PackageReaderOptions = new PackageReaderOptions()
PackageReaderOptions = new PackageReaderOptions
{
IgnoreMissingToc = true
}
@@ -194,7 +193,7 @@ public class BookService : IBookService
var prepend = filename.Length > 0 ? filename.Replace(Path.GetFileName(filename), string.Empty) : string.Empty;
var importBuilder = new StringBuilder();
//foreach (Match match in Tasks.Scanner.Parser.Parser.CssImportUrlRegex().Matches(stylesheetHtml))
foreach (Match match in Tasks.Scanner.Parser.Parser.CssImportUrlRegex.Matches(stylesheetHtml))
foreach (Match match in Parser.CssImportUrlRegex.Matches(stylesheetHtml))
{
if (!match.Success) continue;
@@ -246,7 +245,7 @@ public class BookService : IBookService
private static void EscapeCssImportReferences(ref string stylesheetHtml, string apiBase, string prepend)
{
//foreach (Match match in Tasks.Scanner.Parser.Parser.CssImportUrlRegex().Matches(stylesheetHtml))
foreach (Match match in Tasks.Scanner.Parser.Parser.CssImportUrlRegex.Matches(stylesheetHtml))
foreach (Match match in Parser.CssImportUrlRegex.Matches(stylesheetHtml))
{
if (!match.Success) continue;
var importFile = match.Groups["Filename"].Value;
@@ -257,7 +256,7 @@ public class BookService : IBookService
private static void EscapeFontFamilyReferences(ref string stylesheetHtml, string apiBase, string prepend)
{
//foreach (Match match in Tasks.Scanner.Parser.Parser.FontSrcUrlRegex().Matches(stylesheetHtml))
foreach (Match match in Tasks.Scanner.Parser.Parser.FontSrcUrlRegex.Matches(stylesheetHtml))
foreach (Match match in Parser.FontSrcUrlRegex.Matches(stylesheetHtml))
{
if (!match.Success) continue;
var importFile = match.Groups["Filename"].Value;
@@ -268,7 +267,7 @@ public class BookService : IBookService
private static void EscapeCssImageReferences(ref string stylesheetHtml, string apiBase, EpubBookRef book)
{
//var matches = Tasks.Scanner.Parser.Parser.CssImageUrlRegex().Matches(stylesheetHtml);
var matches = Tasks.Scanner.Parser.Parser.CssImageUrlRegex.Matches(stylesheetHtml);
var matches = Parser.CssImageUrlRegex.Matches(stylesheetHtml);
foreach (Match match in matches)
{
if (!match.Success) continue;
@@ -424,7 +423,7 @@ public class BookService : IBookService
public ComicInfo? GetComicInfo(string filePath)
{
if (!IsValidFile(filePath) || Tasks.Scanner.Parser.Parser.IsPdf(filePath)) return null;
if (!IsValidFile(filePath) || Parser.IsPdf(filePath)) return null;
try
{
@@ -438,10 +437,10 @@ public class BookService : IBookService
}
var (year, month, day) = GetPublicationDate(publicationDate);
var info = new ComicInfo()
var info = new ComicInfo
{
Summary = epubBook.Schema.Package.Metadata.Description,
Writer = string.Join(",", epubBook.Schema.Package.Metadata.Creators.Select(c => Tasks.Scanner.Parser.Parser.CleanAuthor(c.Creator))),
Writer = string.Join(",", epubBook.Schema.Package.Metadata.Creators.Select(c => Parser.CleanAuthor(c.Creator))),
Publisher = string.Join(",", epubBook.Schema.Package.Metadata.Publishers),
Month = month,
Day = day,
@@ -489,14 +488,14 @@ public class BookService : IBookService
}
}
var hasVolumeInSeries = !Tasks.Scanner.Parser.Parser.ParseVolume(info.Title)
.Equals(Tasks.Scanner.Parser.Parser.DefaultVolume);
var hasVolumeInSeries = !Parser.ParseVolume(info.Title)
.Equals(Parser.DefaultVolume);
if (string.IsNullOrEmpty(info.Volume) && hasVolumeInSeries && (!info.Series.Equals(info.Title) || string.IsNullOrEmpty(info.Series)))
{
// This is likely a light novel for which we can set series from parsed title
info.Series = Tasks.Scanner.Parser.Parser.ParseSeries(info.Title);
info.Volume = Tasks.Scanner.Parser.Parser.ParseVolume(info.Title);
info.Series = Parser.ParseSeries(info.Title);
info.Volume = Parser.ParseVolume(info.Title);
}
return info;
@@ -552,7 +551,7 @@ public class BookService : IBookService
return false;
}
if (Tasks.Scanner.Parser.Parser.IsBook(filePath)) return true;
if (Parser.IsBook(filePath)) return true;
_logger.LogWarning("[BookService] Book {EpubFile} is not a valid EPUB/PDF", filePath);
return false;
@@ -564,7 +563,7 @@ public class BookService : IBookService
try
{
if (Tasks.Scanner.Parser.Parser.IsPdf(filePath))
if (Parser.IsPdf(filePath))
{
using var docReader = DocLib.Instance.GetDocReader(filePath, new PageDimensions(1080, 1920));
return docReader.GetPageCount();
@@ -585,8 +584,8 @@ public class BookService : IBookService
{
// content = StartingScriptTag().Replace(content, "<script$1></script>");
// content = StartingTitleTag().Replace(content, "<title$1></title>");
content = Regex.Replace(content, @"<script(.*)(/>)", "<script$1></script>", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
content = Regex.Replace(content, @"<title(.*)(/>)", "<title$1></title>", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
content = Regex.Replace(content, @"<script(.*)(/>)", "<script$1></script>", RegexOptions.None, Parser.RegexTimeout);
content = Regex.Replace(content, @"<title(.*)(/>)", "<title$1></title>", RegexOptions.None, Parser.RegexTimeout);
return content;
}
@@ -622,7 +621,7 @@ public class BookService : IBookService
/// <returns></returns>
public ParserInfo? ParseInfo(string filePath)
{
if (!Tasks.Scanner.Parser.Parser.IsEpub(filePath)) return null;
if (!Parser.IsEpub(filePath)) return null;
try
{
@@ -682,9 +681,9 @@ public class BookService : IBookService
{
specialName = epubBook.Title;
}
var info = new ParserInfo()
var info = new ParserInfo
{
Chapters = Tasks.Scanner.Parser.Parser.DefaultChapter,
Chapters = Parser.DefaultChapter,
Edition = string.Empty,
Format = MangaFormat.Epub,
Filename = Path.GetFileName(filePath),
@@ -704,9 +703,9 @@ public class BookService : IBookService
// Swallow exception
}
return new ParserInfo()
return new ParserInfo
{
Chapters = Tasks.Scanner.Parser.Parser.DefaultChapter,
Chapters = Parser.DefaultChapter,
Edition = string.Empty,
Format = MangaFormat.Epub,
Filename = Path.GetFileName(filePath),
@@ -714,7 +713,7 @@ public class BookService : IBookService
FullFilePath = filePath,
IsSpecial = false,
Series = epubBook.Title.Trim(),
Volumes = Tasks.Scanner.Parser.Parser.DefaultVolume,
Volumes = Parser.DefaultVolume,
};
}
catch (Exception ex)
@@ -834,7 +833,7 @@ public class BookService : IBookService
var key = CoalesceKey(book, mappings, nestedChapter.Link.ContentFileName);
if (mappings.ContainsKey(key))
{
nestedChapters.Add(new BookChapterItem()
nestedChapters.Add(new BookChapterItem
{
Title = nestedChapter.Title,
Page = mappings[key],
@@ -871,7 +870,7 @@ public class BookService : IBookService
{
part = anchor.Attributes["href"].Value.Split("#")[1];
}
chaptersList.Add(new BookChapterItem()
chaptersList.Add(new BookChapterItem
{
Title = anchor.InnerText,
Page = mappings[key],
@@ -951,7 +950,7 @@ public class BookService : IBookService
{
if (navigationItem.Link == null)
{
var item = new BookChapterItem()
var item = new BookChapterItem
{
Title = navigationItem.Title,
Children = nestedChapters
@@ -968,7 +967,7 @@ public class BookService : IBookService
var groupKey = CleanContentKeys(navigationItem.Link.ContentFileName);
if (mappings.ContainsKey(groupKey))
{
chaptersList.Add(new BookChapterItem()
chaptersList.Add(new BookChapterItem
{
Title = navigationItem.Title,
Page = mappings[groupKey],
@@ -991,7 +990,7 @@ public class BookService : IBookService
{
if (!IsValidFile(fileFilePath)) return string.Empty;
if (Tasks.Scanner.Parser.Parser.IsPdf(fileFilePath))
if (Parser.IsPdf(fileFilePath))
{
return GetPdfCoverImage(fileFilePath, fileName, outputDirectory, saveAsWebP);
}
@@ -1002,7 +1001,7 @@ public class BookService : IBookService
{
// Try to get the cover image from OPF file, if not set, try to parse it from all the files, then result to the first one.
var coverImageContent = epubBook.Content.Cover
?? epubBook.Content.Images.Values.FirstOrDefault(file => Tasks.Scanner.Parser.Parser.IsCoverImage(file.FileName))
?? epubBook.Content.Images.Values.FirstOrDefault(file => Parser.IsCoverImage(file.FileName))
?? epubBook.Content.Images.Values.FirstOrDefault();
if (coverImageContent == null) return string.Empty;
@@ -1075,12 +1074,12 @@ public class BookService : IBookService
// body = WhiteSpace2().Replace(body, string.Empty);
// body = WhiteSpace3().Replace(body, " ");
// body = WhiteSpace4().Replace(body, "$1");
body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty, RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"/\*[\d\D]*?\*/", string.Empty, RegexOptions.None, Parser.RegexTimeout);
body = Regex.Replace(body, @"[a-zA-Z]+#", "#", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty, RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"\s+", " ", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"[a-zA-Z]+#", "#", RegexOptions.None, Parser.RegexTimeout);
body = Regex.Replace(body, @"[\n\r]+\s*", string.Empty, RegexOptions.None, Parser.RegexTimeout);
body = Regex.Replace(body, @"\s+", " ", RegexOptions.None, Parser.RegexTimeout);
body = Regex.Replace(body, @"\s?([:,;{}])\s?", "$1", RegexOptions.None, Parser.RegexTimeout);
try
{
body = body.Replace(";}", "}");
@@ -1091,7 +1090,7 @@ public class BookService : IBookService
}
//body = UnitPadding().Replace(body, "$1");
body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1", RegexOptions.None, Tasks.Scanner.Parser.Parser.RegexTimeout);
body = Regex.Replace(body, @"([\s:]0)(px|pt|%|em)", "$1", RegexOptions.None, Parser.RegexTimeout);
return body;