From 54a36322bb19ceaeb9f4ae3a01fa54998d243ec8 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 3 Mar 2013 11:53:58 -0500 Subject: [PATCH 1/2] made base video resolver available for re-use --- MediaBrowser.Controller/Entities/BaseItem.cs | 1 + MediaBrowser.Controller/Entities/Folder.cs | 1 + .../Library/ILibraryManager.cs | 1 + MediaBrowser.Controller/Library/TVUtils.cs | 1 + .../MediaBrowser.Controller.csproj | 10 +-- .../Resolvers/BaseItemResolver.cs | 61 +++++++++++++++++++ .../Resolvers/BaseVideoResolver.cs | 56 +++++++++++++++++ .../EntityResolutionHelper.cs | 3 +- .../{Library => Resolvers}/IItemResolver.cs | 3 +- .../IResolverIgnoreRule.cs | 4 +- .../ResolverPriority.cs | 2 +- .../Library/CoreResolutionIgnoreRule.cs | 1 + .../Library/LibraryManager.cs | 1 + .../Library/ResolverHelper.cs | 1 + .../Library/Resolvers/Audio/AudioResolver.cs | 1 + .../Resolvers/Audio/MusicAlbumResolver.cs | 1 + .../Resolvers/Audio/MusicArtistResolver.cs | 1 + .../Library/Resolvers/BaseItemResolver.cs | 1 + .../Library/Resolvers/FolderResolver.cs | 1 + .../Library/Resolvers/LocalTrailerResolver.cs | 3 +- .../Library/Resolvers/Movies/MovieResolver.cs | 3 +- .../Library/Resolvers/TV/EpisodeResolver.cs | 3 +- .../Library/Resolvers/TV/SeriesResolver.cs | 1 + .../Library/Resolvers/VideoResolver.cs | 53 +--------------- .../ApplicationHost.cs | 1 + Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 28 files changed, 158 insertions(+), 67 deletions(-) create mode 100644 MediaBrowser.Controller/Resolvers/BaseItemResolver.cs create mode 100644 MediaBrowser.Controller/Resolvers/BaseVideoResolver.cs rename MediaBrowser.Controller/{Library => Resolvers}/EntityResolutionHelper.cs (97%) rename MediaBrowser.Controller/{Library => Resolvers}/IItemResolver.cs (86%) rename MediaBrowser.Controller/{Library => Resolvers}/IResolverIgnoreRule.cs (72%) rename MediaBrowser.Controller/{Library => Resolvers}/ResolverPriority.cs (91%) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 1d360098c..47c129dea 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Providers; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using System; diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 4e12a8686..c6f479029 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Sorting; using MediaBrowser.Model.Entities; using System; diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 7ba60e921..3f1930209 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs index e0ef188b8..d6a922ff4 100644 --- a/MediaBrowser.Controller/Library/TVUtils.cs +++ b/MediaBrowser.Controller/Library/TVUtils.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Controller.Library { diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 839cf2f40..2b3af2784 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -110,7 +110,9 @@ - + + + @@ -164,9 +166,9 @@ - - - + + + diff --git a/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs new file mode 100644 index 000000000..fc5157d5f --- /dev/null +++ b/MediaBrowser.Controller/Resolvers/BaseItemResolver.cs @@ -0,0 +1,61 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Controller.Resolvers +{ + /// + /// Class ItemResolver + /// + /// + public abstract class ItemResolver : IItemResolver + where T : BaseItem, new() + { + /// + /// Resolves the specified args. + /// + /// The args. + /// `0. + protected virtual T Resolve(ItemResolveArgs args) + { + return null; + } + + /// + /// Gets the priority. + /// + /// The priority. + public virtual ResolverPriority Priority + { + get + { + return ResolverPriority.First; + } + } + + /// + /// Sets initial values on the newly resolved item + /// + /// The item. + /// The args. + protected virtual void SetInitialItemValues(T item, ItemResolveArgs args) + { + } + + /// + /// Resolves the path. + /// + /// The args. + /// BaseItem. + BaseItem IItemResolver.ResolvePath(ItemResolveArgs args) + { + var item = Resolve(args); + + if (item != null) + { + SetInitialItemValues(item, args); + } + + return item; + } + } +} diff --git a/MediaBrowser.Controller/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Controller/Resolvers/BaseVideoResolver.cs new file mode 100644 index 000000000..c2536cd60 --- /dev/null +++ b/MediaBrowser.Controller/Resolvers/BaseVideoResolver.cs @@ -0,0 +1,56 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; +using System; +using System.IO; + +namespace MediaBrowser.Controller.Resolvers +{ + /// + /// Resolves a Path into a Video or Video subclass + /// + /// + public abstract class BaseVideoResolver : ItemResolver + where T : Video, new() + { + /// + /// Resolves the specified args. + /// + /// The args. + /// `0. + protected override T Resolve(ItemResolveArgs args) + { + // If the path is a file check for a matching extensions + if (!args.IsDirectory) + { + if (EntityResolutionHelper.IsVideoFile(args.Path)) + { + var extension = Path.GetExtension(args.Path); + + var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ? + VideoType.Iso : VideoType.VideoFile; + + return new T + { + VideoType = type, + Path = args.Path + }; + } + } + + return null; + } + + /// + /// Sets the initial item values. + /// + /// The item. + /// The args. + protected override void SetInitialItemValues(T item, ItemResolveArgs args) + { + base.SetInitialItemValues(item, args); + + item.VideoFormat = item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Digital3D : item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Sbs3D : VideoFormat.Standard; + } + } +} diff --git a/MediaBrowser.Controller/Library/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs similarity index 97% rename from MediaBrowser.Controller/Library/EntityResolutionHelper.cs rename to MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs index 07e0b5a11..dda2af0cf 100644 --- a/MediaBrowser.Controller/Library/EntityResolutionHelper.cs +++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs @@ -4,8 +4,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using MediaBrowser.Controller.Library; -namespace MediaBrowser.Controller.Library +namespace MediaBrowser.Controller.Resolvers { /// /// Class EntityResolutionHelper diff --git a/MediaBrowser.Controller/Library/IItemResolver.cs b/MediaBrowser.Controller/Resolvers/IItemResolver.cs similarity index 86% rename from MediaBrowser.Controller/Library/IItemResolver.cs rename to MediaBrowser.Controller/Resolvers/IItemResolver.cs index 721b787d3..780d5d013 100644 --- a/MediaBrowser.Controller/Library/IItemResolver.cs +++ b/MediaBrowser.Controller/Resolvers/IItemResolver.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; -namespace MediaBrowser.Controller.Library +namespace MediaBrowser.Controller.Resolvers { /// /// Interface IItemResolver diff --git a/MediaBrowser.Controller/Library/IResolverIgnoreRule.cs b/MediaBrowser.Controller/Resolvers/IResolverIgnoreRule.cs similarity index 72% rename from MediaBrowser.Controller/Library/IResolverIgnoreRule.cs rename to MediaBrowser.Controller/Resolvers/IResolverIgnoreRule.cs index c9c602089..e85535548 100644 --- a/MediaBrowser.Controller/Library/IResolverIgnoreRule.cs +++ b/MediaBrowser.Controller/Resolvers/IResolverIgnoreRule.cs @@ -1,4 +1,6 @@ -namespace MediaBrowser.Controller.Library +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Controller.Resolvers { /// /// Provides a base "rule" that anyone can use to have paths ignored by the resolver diff --git a/MediaBrowser.Controller/Library/ResolverPriority.cs b/MediaBrowser.Controller/Resolvers/ResolverPriority.cs similarity index 91% rename from MediaBrowser.Controller/Library/ResolverPriority.cs rename to MediaBrowser.Controller/Resolvers/ResolverPriority.cs index 1f266f371..63a107fda 100644 --- a/MediaBrowser.Controller/Library/ResolverPriority.cs +++ b/MediaBrowser.Controller/Resolvers/ResolverPriority.cs @@ -1,5 +1,5 @@  -namespace MediaBrowser.Controller.Library +namespace MediaBrowser.Controller.Resolvers { /// /// Enum ResolverPriority diff --git a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs index 98b8bea11..cebd5e192 100644 --- a/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs +++ b/MediaBrowser.Server.Implementations/Library/CoreResolutionIgnoreRule.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library { diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index e778b35df..b6e9fec17 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -6,6 +6,7 @@ using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.ScheduledTasks; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs index aea34b0be..f4e34ba62 100644 --- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs +++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using System.IO; using System.Text.RegularExpressions; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs index f8e0acb5a..42370c17f 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/AudioResolver.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Library; using System; using System.IO; using System.Linq; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs index 31016e2fc..6ca4338a4 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs index e48ad96c6..78f4b5a27 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using System.Linq; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs index a80a48290..a03eda263 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseItemResolver.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/FolderResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/FolderResolver.cs index c680af7d6..ebe36c16e 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/FolderResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/FolderResolver.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers { diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs index d0a0cd5c7..f8e9f32b5 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/LocalTrailerResolver.cs @@ -2,13 +2,14 @@ using MediaBrowser.Controller.Library; using System; using System.IO; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers { /// /// Class LocalTrailerResolver /// - public class LocalTrailerResolver : VideoResolver + public class LocalTrailerResolver : BaseVideoResolver { /// /// Resolves the specified args. diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 601ab6661..4dd7aceb4 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers.Movies; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; @@ -13,7 +14,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// /// Class MovieResolver /// - public class MovieResolver : VideoResolver + public class MovieResolver : BaseVideoResolver { /// /// Gets the priority. diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs index 6fa9711cc..717370590 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; @@ -8,7 +9,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV /// /// Class EpisodeResolver /// - public class EpisodeResolver : VideoResolver + public class EpisodeResolver : BaseVideoResolver { /// /// Resolves the specified args. diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index 642e52363..9f7881986 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; using System; using System.IO; diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs index 5a47f38cd..391a3d948 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/VideoResolver.cs @@ -1,15 +1,12 @@ using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Entities; -using System; -using System.IO; +using MediaBrowser.Controller.Resolvers; namespace MediaBrowser.Server.Implementations.Library.Resolvers { /// /// Resolves a Path into a Video /// - public class VideoResolver : VideoResolver