IHasImages.cs 9.2 KB

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