IHasImages.cs 9.1 KB

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