EntityResolutionHelper.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. ".mts"
  45. };
  46. /// <summary>
  47. /// The audio file extensions
  48. /// </summary>
  49. private static readonly string[] AudioFileExtensions = new[] {
  50. ".mp3",
  51. ".flac",
  52. ".wma",
  53. ".aac",
  54. ".acc",
  55. ".m4a",
  56. ".m4b",
  57. ".wav",
  58. ".ape",
  59. ".ogg",
  60. ".oga"
  61. };
  62. /// <summary>
  63. /// Determines whether [is audio file] [the specified args].
  64. /// </summary>
  65. /// <param name="path">The path.</param>
  66. /// <returns><c>true</c> if [is audio file] [the specified args]; otherwise, <c>false</c>.</returns>
  67. public static bool IsAudioFile(string path)
  68. {
  69. return AudioFileExtensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase);
  70. }
  71. /// <summary>
  72. /// Determines whether [is video file] [the specified path].
  73. /// </summary>
  74. /// <param name="path">The path.</param>
  75. /// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns>
  76. public static bool IsVideoFile(string path)
  77. {
  78. var extension = Path.GetExtension(path) ?? String.Empty;
  79. return VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
  80. }
  81. /// <summary>
  82. /// Ensures DateCreated and DateModified have values
  83. /// </summary>
  84. /// <param name="item">The item.</param>
  85. /// <param name="args">The args.</param>
  86. public static void EnsureDates(BaseItem item, ItemResolveArgs args)
  87. {
  88. if (!Path.IsPathRooted(item.Path))
  89. {
  90. return;
  91. }
  92. // See if a different path came out of the resolver than what went in
  93. if (!args.Path.Equals(item.Path, StringComparison.OrdinalIgnoreCase))
  94. {
  95. var childData = args.IsDirectory ? args.GetFileSystemEntryByPath(item.Path) : null;
  96. if (childData != null)
  97. {
  98. item.DateCreated = childData.CreationTimeUtc;
  99. item.DateModified = childData.LastWriteTimeUtc;
  100. }
  101. else
  102. {
  103. var fileData = FileSystem.GetFileSystemInfo(item.Path);
  104. if (fileData.Exists)
  105. {
  106. item.DateCreated = fileData.CreationTimeUtc;
  107. item.DateModified = fileData.LastWriteTimeUtc;
  108. }
  109. }
  110. }
  111. else
  112. {
  113. item.DateCreated = args.FileInfo.CreationTimeUtc;
  114. item.DateModified = args.FileInfo.LastWriteTimeUtc;
  115. }
  116. }
  117. }
  118. }