diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-03-03 11:53:58 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-03-03 11:53:58 -0500 |
| commit | 54a36322bb19ceaeb9f4ae3a01fa54998d243ec8 (patch) | |
| tree | 8b72eb5799db3daeb4a639fb783a4e2f1c2e1bf6 /MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs | |
| parent | 7b0b5a35382d0b43f298d7ef015d6fd3031a8c72 (diff) | |
made base video resolver available for re-use
Diffstat (limited to 'MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs')
| -rw-r--r-- | MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs new file mode 100644 index 000000000..dda2af0cf --- /dev/null +++ b/MediaBrowser.Controller/Resolvers/EntityResolutionHelper.cs @@ -0,0 +1,98 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Controller.Resolvers +{ + /// <summary> + /// Class EntityResolutionHelper + /// </summary> + public static class EntityResolutionHelper + { + /// <summary> + /// Any extension in this list is considered a video file - can be added to at runtime for extensibility + /// </summary> + public static List<string> VideoFileExtensions = new List<string> + { + ".mkv", + ".m2t", + ".m2ts", + ".img", + ".iso", + ".ts", + ".rmvb", + ".mov", + ".avi", + ".mpg", + ".mpeg", + ".wmv", + ".mp4", + ".divx", + ".dvr-ms", + ".wtv", + ".ogm", + ".ogv", + ".asf", + ".m4v", + ".flv", + ".f4v", + ".3gp", + ".webm" + }; + + /// <summary> + /// Determines whether [is video file] [the specified path]. + /// </summary> + /// <param name="path">The path.</param> + /// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns> + public static bool IsVideoFile(string path) + { + var extension = Path.GetExtension(path) ?? string.Empty; + return VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase); + } + + /// <summary> + /// Ensures DateCreated and DateModified have values + /// </summary> + /// <param name="item">The item.</param> + /// <param name="args">The args.</param> + public static void EnsureDates(BaseItem item, ItemResolveArgs args) + { + if (!Path.IsPathRooted(item.Path)) + { + return; + } + + // See if a different path came out of the resolver than what went in + if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase)) + { + var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null; + + if (childData.HasValue) + { + item.DateCreated = childData.Value.CreationTimeUtc; + item.DateModified = childData.Value.LastWriteTimeUtc; + } + else + { + var fileData = FileSystem.GetFileData(item.Path); + + if (fileData.HasValue) + { + item.DateCreated = fileData.Value.CreationTimeUtc; + item.DateModified = fileData.Value.LastWriteTimeUtc; + } + } + } + else + { + item.DateCreated = args.FileInfo.CreationTimeUtc; + item.DateModified = args.FileInfo.LastWriteTimeUtc; + } + } + } +} |
