EntityResolutionHelper.cs 3.1 KB

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