EPUB Support (#178)
* Added book filetype detection and reorganized tests due to size of file * Added ability to get basic Parse Info from Book and Pages. * We can now scan books and get them in a library with cover images. * Take the first image in the epub if the cover isn't set. * Implemented the ability to unzip the ebup to cache. Implemented a test api to load html files. * Just some test code to figure out how to approach this. * Fixed some merge conflicts * Removed some dead code from merge * Snapshot: I can now load everything properly into the UI by rewriting the urls before I send them back. I don't notice any lag from this method. It can be optimized further. * Implemented a way to load the content in the browser not via an iframe. * Added a note * Anchor mappings is complete. New anchors are updated so references now resolve to javascript:void() for UI to take care of internally loading and the appropriate page is mapped to it. Anchors that are external have target="_blank" added so they don't force you out of the app and styles are of course inlined. * Oops i need this * Table of contents api implemented (rough) and some small enhancements to codebase for books. * GetBookPageResources now only loads files from within the book. Nested chapter list support and images now use html parsing instead of string parsing. * Fonts now are remapped to load from endpoint. * book-resources now uses a key, ensuring the file is in proper format for lookup. Changed chapter list based on structure with one HEADER and nested chapters. * Properly handle svg resource requests and when there are part anchors that are clickable, make sure we handle them in the UI by adding a kavita-page handler. * Add Chapter group page even if one isn't set by using first page (without part) from nestedChildren. * Added extra debug code for issue #163. * Added new user preferences for books and updated the css so we scope it to our reading section. * Cleaned up style code * Implemented ability to save book preferences and some cleanup on existing apis. * Added an api for checking if a user has read something in a library type before. * Forgot to make sure the has reading progress is against a user lol. * Remove cacheservice code for books, sine we use an in-memory method * Handle svg images as well * Enhanced cover image extraction to check for a "cover" image if the cover image wasn't set in OPF before falling back to the first image. * Fixed an issue with special books not properly generating metadata due to not having filename set. * Cleanup, removed warmup task code from statup/program and changed taskscheduler to schedule tasks on startup only (or if tasks are changed from UI). * Code cleanup * Code cleanup * So much code. Lots of refactors to try to test scanner service. Moved a lot of the queries into Extensions to allow to easier test, even though it's hacky. Support @font-face src:url swaps with ' and ". Source summary information from epubs. * Well...baseURL needs to come from BE and not from UI lol. * Adjusted migrations so default values match Entity * Removed comment * I think I finally fixed #163! The issue was that when i checked if it had a parserInfo, i wasn't considering that the chapter range might have a - in it (0-6) and so when the code to check if range could parse out a number failed, it treated it like a special and checked range against info's filename. * Some bugfixes * Lots of testing, extracting code to make it easier to test. This code is buggy, but fixed a bug where 1) If we changed the normalization code, we would remove the whole db during a scan and 2) We weren't actually removing series properly. Other than that, code is being extracted to remove duplication and centralize logic. * More code cleanup and test cleanup to ensure scan loop is working as expected and matches expectaions from tests. * Cleaned up the code and made it so if I change normalization, which I do in this branch, it wont break existing DBs. * Some comic parser changes for partial chapter support. * Added some code for directory service and scanner service along with python code to generate test files (not used yet). Fixed up all the tests. * Code smells
This commit is contained in:
parent
2b99c8abfa
commit
a01613f80f
103 changed files with 5017 additions and 2480 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using API.Data;
|
||||
using API.Entities.Interfaces;
|
||||
using API.Helpers;
|
||||
using API.Interfaces;
|
||||
using API.Interfaces.Services;
|
||||
|
|
@ -26,8 +27,8 @@ namespace API.Extensions
|
|||
services.AddScoped<IMetadataService, MetadataService>();
|
||||
services.AddScoped<IBackupService, BackupService>();
|
||||
services.AddScoped<ICleanupService, CleanupService>();
|
||||
|
||||
|
||||
services.AddScoped<IBookService, BookService>();
|
||||
|
||||
|
||||
services.AddDbContext<DataContext>(options =>
|
||||
{
|
||||
|
|
|
|||
35
API/Extensions/ChapterListExtensions.cs
Normal file
35
API/Extensions/ChapterListExtensions.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
using API.Parser;
|
||||
|
||||
namespace API.Extensions
|
||||
{
|
||||
public static class ChapterListExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns first chapter in the list with at least one file
|
||||
/// </summary>
|
||||
/// <param name="chapters"></param>
|
||||
/// <returns></returns>
|
||||
public static Chapter GetFirstChapterWithFiles(this IList<Chapter> chapters)
|
||||
{
|
||||
return chapters.FirstOrDefault(c => c.Files.Any());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single chapter (or null if doesn't exist) where Range matches the info.Chapters property. If the info
|
||||
/// is <see cref="ParserInfo.IsSpecial"/> then, the filename is used to search against Range or if filename exists within Files of said Chapter.
|
||||
/// </summary>
|
||||
/// <param name="chapters"></param>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public static Chapter GetChapterByRange(this IList<Chapter> chapters, ParserInfo info)
|
||||
{
|
||||
var specialTreatment = info.IsSpecialInfo();
|
||||
return specialTreatment
|
||||
? chapters.SingleOrDefault(c => c.Range == info.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath)))
|
||||
: chapters.SingleOrDefault(c => c.Range == info.Chapters);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
API/Extensions/ParserInfoListExtensions.cs
Normal file
34
API/Extensions/ParserInfoListExtensions.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
using API.Parser;
|
||||
|
||||
namespace API.Extensions
|
||||
{
|
||||
public static class ParserInfoListExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Selects distinct volume numbers by the "Volumes" key on the ParserInfo
|
||||
/// </summary>
|
||||
/// <param name="infos"></param>
|
||||
/// <returns></returns>
|
||||
public static IList<string> DistinctVolumes(this IList<ParserInfo> infos)
|
||||
{
|
||||
return infos.Select(p => p.Volumes).Distinct().ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a list of ParserInfos has a given chapter or not. Lookup occurs on Range property. If a chapter is
|
||||
/// special, then the <see cref="ParserInfo.Filename"/> is matched, else the <see cref="ParserInfo.Chapters"/> field is checked.
|
||||
/// </summary>
|
||||
/// <param name="infos"></param>
|
||||
/// <param name="chapter"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasInfo(this IList<ParserInfo> infos, Chapter chapter)
|
||||
{
|
||||
return chapter.IsSpecial ? infos.Any(v => v.Filename == chapter.Range)
|
||||
: infos.Any(v => v.Chapters == chapter.Range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
|
||||
namespace API.Extensions
|
||||
|
|
@ -13,15 +14,7 @@ namespace API.Extensions
|
|||
/// <returns></returns>
|
||||
public static bool NameInList(this Series series, IEnumerable<string> list)
|
||||
{
|
||||
foreach (var name in list)
|
||||
{
|
||||
if (Parser.Parser.Normalize(name) == series.NormalizedName || name == series.Name || name == series.LocalizedName || name == series.OriginalName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return list.Any(name => Parser.Parser.Normalize(name) == series.NormalizedName || Parser.Parser.Normalize(name) == Parser.Parser.Normalize(series.Name) || name == series.Name || name == series.LocalizedName || name == series.OriginalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
API/Extensions/VolumeListExtensions.cs
Normal file
38
API/Extensions/VolumeListExtensions.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
|
||||
namespace API.Extensions
|
||||
{
|
||||
public static class VolumeListExtensions
|
||||
{
|
||||
public static Volume FirstWithChapters(this IList<Volume> volumes, bool inBookSeries)
|
||||
{
|
||||
return inBookSeries
|
||||
? volumes.FirstOrDefault(v => v.Chapters.Any())
|
||||
: volumes.FirstOrDefault(v => v.Chapters.Any() && (v.Number == 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects the first Volume to get the cover image from. For a book with only a special, the special will be returned.
|
||||
/// If there are both specials and non-specials, then the first non-special will be returned.
|
||||
/// </summary>
|
||||
/// <param name="volumes"></param>
|
||||
/// <param name="libraryType"></param>
|
||||
/// <returns></returns>
|
||||
public static Volume GetCoverImage(this IList<Volume> volumes, LibraryType libraryType)
|
||||
{
|
||||
if (libraryType == LibraryType.Book)
|
||||
{
|
||||
return volumes.OrderBy(x => x.Number).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (volumes.Any(x => x.Number != 0))
|
||||
{
|
||||
return volumes.OrderBy(x => x.Number).FirstOrDefault(x => x.Number != 0);
|
||||
}
|
||||
return volumes.OrderBy(x => x.Number).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue