IHasImages.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Entities;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Common.IO;
  7. using MediaBrowser.Controller.IO;
  8. using MediaBrowser.Controller.Library;
  9. using MediaBrowser.Model.IO;
  10. namespace MediaBrowser.Controller.Entities
  11. {
  12. public interface IHasImages : IHasProviderIds, IHasId
  13. {
  14. /// <summary>
  15. /// Gets the name.
  16. /// </summary>
  17. /// <value>The name.</value>
  18. string Name { get; set; }
  19. /// <summary>
  20. /// Gets the path.
  21. /// </summary>
  22. /// <value>The path.</value>
  23. string Path { get; set; }
  24. /// <summary>
  25. /// Gets the file name without extension.
  26. /// </summary>
  27. /// <value>The file name without extension.</value>
  28. string FileNameWithoutExtension { get; }
  29. /// <summary>
  30. /// Gets the type of the location.
  31. /// </summary>
  32. /// <value>The type of the location.</value>
  33. LocationType LocationType { get; }
  34. /// <summary>
  35. /// Gets the locked fields.
  36. /// </summary>
  37. /// <value>The locked fields.</value>
  38. List<MetadataFields> LockedFields { get; }
  39. /// <summary>
  40. /// Gets the images.
  41. /// </summary>
  42. /// <param name="imageType">Type of the image.</param>
  43. /// <returns>IEnumerable{ItemImageInfo}.</returns>
  44. IEnumerable<ItemImageInfo> GetImages(ImageType imageType);
  45. /// <summary>
  46. /// Gets the image path.
  47. /// </summary>
  48. /// <param name="imageType">Type of the image.</param>
  49. /// <param name="imageIndex">Index of the image.</param>
  50. /// <returns>System.String.</returns>
  51. string GetImagePath(ImageType imageType, int imageIndex);
  52. /// <summary>
  53. /// Gets the image information.
  54. /// </summary>
  55. /// <param name="imageType">Type of the image.</param>
  56. /// <param name="imageIndex">Index of the image.</param>
  57. /// <returns>ItemImageInfo.</returns>
  58. ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex);
  59. /// <summary>
  60. /// Sets the image.
  61. /// </summary>
  62. /// <param name="type">The type.</param>
  63. /// <param name="index">The index.</param>
  64. /// <param name="file">The file.</param>
  65. void SetImagePath(ImageType type, int index, FileSystemMetadata file);
  66. /// <summary>
  67. /// Determines whether the specified type has image.
  68. /// </summary>
  69. /// <param name="type">The type.</param>
  70. /// <param name="imageIndex">Index of the image.</param>
  71. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  72. bool HasImage(ImageType type, int imageIndex);
  73. /// <summary>
  74. /// Allowses the multiple images.
  75. /// </summary>
  76. /// <param name="type">The type.</param>
  77. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  78. bool AllowsMultipleImages(ImageType type);
  79. /// <summary>
  80. /// Swaps the images.
  81. /// </summary>
  82. /// <param name="type">The type.</param>
  83. /// <param name="index1">The index1.</param>
  84. /// <param name="index2">The index2.</param>
  85. /// <returns>Task.</returns>
  86. Task SwapImages(ImageType type, int index1, int index2);
  87. /// <summary>
  88. /// Gets the display type of the media.
  89. /// </summary>
  90. /// <value>The display type of the media.</value>
  91. string DisplayMediaType { get; set; }
  92. /// <summary>
  93. /// Gets or sets the primary image path.
  94. /// </summary>
  95. /// <value>The primary image path.</value>
  96. string PrimaryImagePath { get; }
  97. /// <summary>
  98. /// Gets the preferred metadata language.
  99. /// </summary>
  100. /// <returns>System.String.</returns>
  101. string GetPreferredMetadataLanguage();
  102. /// <summary>
  103. /// Validates the images and returns true or false indicating if any were removed.
  104. /// </summary>
  105. bool ValidateImages(IDirectoryService directoryService);
  106. /// <summary>
  107. /// Gets a value indicating whether this instance is owned item.
  108. /// </summary>
  109. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  110. bool IsOwnedItem { get; }
  111. /// <summary>
  112. /// Gets the containing folder path.
  113. /// </summary>
  114. /// <value>The containing folder path.</value>
  115. string ContainingFolderPath { get; }
  116. /// <summary>
  117. /// Adds the images.
  118. /// </summary>
  119. /// <param name="imageType">Type of the image.</param>
  120. /// <param name="images">The images.</param>
  121. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  122. bool AddImages(ImageType imageType, List<FileSystemMetadata> images);
  123. /// <summary>
  124. /// Determines whether [is save local metadata enabled].
  125. /// </summary>
  126. /// <returns><c>true</c> if [is save local metadata enabled]; otherwise, <c>false</c>.</returns>
  127. bool IsSaveLocalMetadataEnabled();
  128. /// <summary>
  129. /// Gets a value indicating whether [supports local metadata].
  130. /// </summary>
  131. /// <value><c>true</c> if [supports local metadata]; otherwise, <c>false</c>.</value>
  132. bool SupportsLocalMetadata { get; }
  133. bool DetectIsInMixedFolder();
  134. /// <summary>
  135. /// Gets a value indicating whether this instance is locked.
  136. /// </summary>
  137. /// <value><c>true</c> if this instance is locked; otherwise, <c>false</c>.</value>
  138. bool IsLocked { get; }
  139. /// <summary>
  140. /// Gets a value indicating whether [supports remote image downloading].
  141. /// </summary>
  142. /// <value><c>true</c> if [supports remote image downloading]; otherwise, <c>false</c>.</value>
  143. bool SupportsRemoteImageDownloading { get; }
  144. /// <summary>
  145. /// Gets the internal metadata path.
  146. /// </summary>
  147. /// <returns>System.String.</returns>
  148. string GetInternalMetadataPath();
  149. /// <summary>
  150. /// Gets a value indicating whether [always scan internal metadata path].
  151. /// </summary>
  152. /// <value><c>true</c> if [always scan internal metadata path]; otherwise, <c>false</c>.</value>
  153. bool AlwaysScanInternalMetadataPath { get; }
  154. /// <summary>
  155. /// Determines whether [is internet metadata enabled].
  156. /// </summary>
  157. /// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
  158. bool IsInternetMetadataEnabled();
  159. /// <summary>
  160. /// Removes the image.
  161. /// </summary>
  162. /// <param name="image">The image.</param>
  163. void RemoveImage(ItemImageInfo image);
  164. /// <summary>
  165. /// Updates to repository.
  166. /// </summary>
  167. /// <param name="updateReason">The update reason.</param>
  168. /// <param name="cancellationToken">The cancellation token.</param>
  169. /// <returns>Task.</returns>
  170. Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
  171. /// <summary>
  172. /// Sets the image.
  173. /// </summary>
  174. /// <param name="image">The image.</param>
  175. /// <param name="index">The index.</param>
  176. void SetImage(ItemImageInfo image, int index);
  177. }
  178. public static class HasImagesExtensions
  179. {
  180. /// <summary>
  181. /// Gets the image path.
  182. /// </summary>
  183. /// <param name="item">The item.</param>
  184. /// <param name="imageType">Type of the image.</param>
  185. /// <returns>System.String.</returns>
  186. public static string GetImagePath(this IHasImages item, ImageType imageType)
  187. {
  188. return item.GetImagePath(imageType, 0);
  189. }
  190. public static bool HasImage(this IHasImages item, ImageType imageType)
  191. {
  192. return item.HasImage(imageType, 0);
  193. }
  194. /// <summary>
  195. /// Sets the image path.
  196. /// </summary>
  197. /// <param name="item">The item.</param>
  198. /// <param name="imageType">Type of the image.</param>
  199. /// <param name="file">The file.</param>
  200. public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemMetadata file)
  201. {
  202. item.SetImagePath(imageType, 0, file);
  203. }
  204. /// <summary>
  205. /// Sets the image path.
  206. /// </summary>
  207. /// <param name="item">The item.</param>
  208. /// <param name="imageType">Type of the image.</param>
  209. /// <param name="file">The file.</param>
  210. public static void SetImagePath(this IHasImages item, ImageType imageType, string file)
  211. {
  212. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  213. {
  214. item.SetImage(new ItemImageInfo
  215. {
  216. Path = file,
  217. Type = imageType
  218. }, 0);
  219. }
  220. else
  221. {
  222. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  223. }
  224. }
  225. }
  226. }