From 1aff48b93b72fe7d418b4798f504bd0d145f44e8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 12 Dec 2016 00:49:19 -0500 Subject: move book support into the core --- .../Library/Resolvers/Audio/AudioResolver.cs | 6 ++ .../Library/Resolvers/Books/BookResolver.cs | 77 ++++++++++++++++++++++ .../Library/UserDataManager.cs | 2 +- 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs (limited to 'Emby.Server.Implementations/Library') diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs index d8805355a..2e3d81474 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; +using MediaBrowser.Controller.Entities; namespace Emby.Server.Implementations.Library.Resolvers.Audio { @@ -59,6 +60,11 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio { return new MediaBrowser.Controller.Entities.Audio.Audio(); } + + if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase)) + { + return new AudioBook(); + } } } diff --git a/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs new file mode 100644 index 000000000..4852c3c6a --- /dev/null +++ b/Emby.Server.Implementations/Library/Resolvers/Books/BookResolver.cs @@ -0,0 +1,77 @@ +using System; +using System.IO; +using System.Linq; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; + +namespace Emby.Server.Implementations.Library.Resolvers.Books +{ + /// + /// + /// + public class BookResolver : MediaBrowser.Controller.Resolvers.ItemResolver + { + private readonly string[] _validExtensions = {".pdf", ".epub", ".mobi", ".cbr", ".cbz"}; + + /// + /// + /// + /// + /// + protected override Book Resolve(ItemResolveArgs args) + { + var collectionType = args.GetCollectionType(); + + // Only process items that are in a collection folder containing books + if (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase)) + return null; + + if (args.IsDirectory) + { + return GetBook(args); + } + + var extension = Path.GetExtension(args.Path); + + if (extension != null && _validExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)) + { + // It's a book + return new Book + { + Path = args.Path, + IsInMixedFolder = true + }; + } + + return null; + } + + /// + /// + /// + /// + /// + private Book GetBook(ItemResolveArgs args) + { + var bookFiles = args.FileSystemChildren.Where(f => + { + var fileExtension = Path.GetExtension(f.FullName) ?? + string.Empty; + + return _validExtensions.Contains(fileExtension, + StringComparer + .OrdinalIgnoreCase); + }).ToList(); + + // Don't return a Book if there is more (or less) than one document in the directory + if (bookFiles.Count != 1) + return null; + + return new Book + { + Path = bookFiles[0].FullName + }; + } + } +} diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index c8dde1287..f4a30fc00 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -274,7 +274,7 @@ namespace Emby.Server.Implementations.Library positionTicks = 0; data.Played = false; } - if (item is Audio) + if (!item.SupportsPositionTicksResume) { positionTicks = 0; } -- cgit v1.2.3