EntityResolutionHelper.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.IO;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. namespace MediaBrowser.Controller.Library
  8. {
  9. /// <summary>
  10. /// Class EntityResolutionHelper
  11. /// </summary>
  12. public static class EntityResolutionHelper
  13. {
  14. /// <summary>
  15. /// Any extension in this list is considered a video file - can be added to at runtime for extensibility
  16. /// </summary>
  17. public static List<string> VideoFileExtensions = new List<string>
  18. {
  19. ".mkv",
  20. ".m2t",
  21. ".m2ts",
  22. ".img",
  23. ".iso",
  24. ".ts",
  25. ".rmvb",
  26. ".mov",
  27. ".avi",
  28. ".mpg",
  29. ".mpeg",
  30. ".wmv",
  31. ".mp4",
  32. ".divx",
  33. ".dvr-ms",
  34. ".wtv",
  35. ".ogm",
  36. ".ogv",
  37. ".asf",
  38. ".m4v",
  39. ".flv",
  40. ".f4v",
  41. ".3gp",
  42. ".webm"
  43. };
  44. /// <summary>
  45. /// Determines whether [is video file] [the specified path].
  46. /// </summary>
  47. /// <param name="path">The path.</param>
  48. /// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns>
  49. public static bool IsVideoFile(string path)
  50. {
  51. var extension = Path.GetExtension(path) ?? string.Empty;
  52. return VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
  53. }
  54. /// <summary>
  55. /// Ensures DateCreated and DateModified have values
  56. /// </summary>
  57. /// <param name="item">The item.</param>
  58. /// <param name="args">The args.</param>
  59. public static void EnsureDates(BaseItem item, ItemResolveArgs args)
  60. {
  61. if (!Path.IsPathRooted(item.Path))
  62. {
  63. return;
  64. }
  65. // See if a different path came out of the resolver than what went in
  66. if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase))
  67. {
  68. var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
  69. if (childData.HasValue)
  70. {
  71. item.DateCreated = childData.Value.CreationTimeUtc;
  72. item.DateModified = childData.Value.LastWriteTimeUtc;
  73. }
  74. else
  75. {
  76. var fileData = FileSystem.GetFileData(item.Path);
  77. if (fileData.HasValue)
  78. {
  79. item.DateCreated = fileData.Value.CreationTimeUtc;
  80. item.DateModified = fileData.Value.LastWriteTimeUtc;
  81. }
  82. }
  83. }
  84. else
  85. {
  86. item.DateCreated = args.FileInfo.CreationTimeUtc;
  87. item.DateModified = args.FileInfo.LastWriteTimeUtc;
  88. }
  89. }
  90. }
  91. }