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 { /// /// Class EntityResolutionHelper /// public static class EntityResolutionHelper { /// /// Any extension in this list is considered a video file - can be added to at runtime for extensibility /// public static List VideoFileExtensions = new List { ".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" }; /// /// Determines whether [is video file] [the specified path]. /// /// The path. /// true if [is video file] [the specified path]; otherwise, false. public static bool IsVideoFile(string path) { var extension = Path.GetExtension(path) ?? string.Empty; return VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase); } /// /// Ensures DateCreated and DateModified have values /// /// The item. /// The args. 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; } } } }