From 5fdd7ec6725a3acb3365e92c090f2e90bbbf122f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Nov 2014 15:44:08 -0500 Subject: add new naming project --- .../Library/Resolvers/BaseVideoResolver.cs | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs new file mode 100644 index 000000000..9ff1223b0 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -0,0 +1,96 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; +using MediaBrowser.Naming.Video; +using System; + +namespace MediaBrowser.Server.Implementations.Library.Resolvers +{ + /// + /// Resolves a Path into a Video or Video subclass + /// + /// + public abstract class BaseVideoResolver : Controller.Resolvers.ItemResolver + where T : Video, new() + { + protected readonly ILibraryManager LibraryManager; + + protected BaseVideoResolver(ILibraryManager libraryManager) + { + LibraryManager = libraryManager; + } + + /// + /// Resolves the specified args. + /// + /// The args. + /// `0. + protected override T Resolve(ItemResolveArgs args) + { + return ResolveVideo(args); + } + + /// + /// Resolves the video. + /// + /// The type of the T video type. + /// The args. + /// ``0. + protected TVideoType ResolveVideo(ItemResolveArgs args) + where TVideoType : Video, new() + { + // If the path is a file check for a matching extensions + if (!args.IsDirectory) + { + var parser = new VideoFileParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger()); + var videoInfo = parser.ParseFile(args.Path); + + if (videoInfo == null) + { + return null; + } + + var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase); + + if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut) + { + var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ? + VideoType.Iso : + VideoType.VideoFile; + + var path = args.Path; + + var video = new TVideoType + { + VideoType = type, + Path = path, + IsInMixedFolder = true, + IsPlaceHolder = videoInfo.IsStub, + IsShortcut = isShortcut, + Name = videoInfo.Name + }; + + if (videoInfo.IsStub) + { + if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.Dvd; + } + else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.HdDvd; + } + else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase)) + { + video.VideoType = VideoType.BluRay; + } + } + + return video; + } + } + + return null; + } + } +} -- cgit v1.2.3