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.Controller.IO;
  7. using MediaBrowser.Controller.Library;
  8. using MediaBrowser.Model.IO;
  9. namespace MediaBrowser.Controller.Entities
  10. {
  11. public interface IHasImages : IHasProviderIds, IHasUserData
  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 or sets the primary image path.
  88. /// </summary>
  89. /// <value>The primary image path.</value>
  90. string PrimaryImagePath { get; }
  91. /// <summary>
  92. /// Gets the preferred metadata language.
  93. /// </summary>
  94. /// <returns>System.String.</returns>
  95. string GetPreferredMetadataLanguage();
  96. /// <summary>
  97. /// Validates the images and returns true or false indicating if any were removed.
  98. /// </summary>
  99. bool ValidateImages(IDirectoryService directoryService);
  100. /// <summary>
  101. /// Gets a value indicating whether this instance is owned item.
  102. /// </summary>
  103. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  104. bool IsOwnedItem { get; }
  105. /// <summary>
  106. /// Gets the containing folder path.
  107. /// </summary>
  108. /// <value>The containing folder path.</value>
  109. string ContainingFolderPath { get; }
  110. /// <summary>
  111. /// Adds the images.
  112. /// </summary>
  113. /// <param name="imageType">Type of the image.</param>
  114. /// <param name="images">The images.</param>
  115. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  116. bool AddImages(ImageType imageType, List<FileSystemMetadata> images);
  117. /// <summary>
  118. /// Determines whether [is save local metadata enabled].
  119. /// </summary>
  120. /// <returns><c>true</c> if [is save local metadata enabled]; otherwise, <c>false</c>.</returns>
  121. bool IsSaveLocalMetadataEnabled();
  122. /// <summary>
  123. /// Gets a value indicating whether [supports local metadata].
  124. /// </summary>
  125. /// <value><c>true</c> if [supports local metadata]; otherwise, <c>false</c>.</value>
  126. bool SupportsLocalMetadata { get; }
  127. bool IsInMixedFolder { get; }
  128. /// <summary>
  129. /// Gets a value indicating whether this instance is locked.
  130. /// </summary>
  131. /// <value><c>true</c> if this instance is locked; otherwise, <c>false</c>.</value>
  132. bool IsLocked { get; }
  133. /// <summary>
  134. /// Gets a value indicating whether [supports remote image downloading].
  135. /// </summary>
  136. /// <value><c>true</c> if [supports remote image downloading]; otherwise, <c>false</c>.</value>
  137. bool SupportsRemoteImageDownloading { get; }
  138. /// <summary>
  139. /// Gets the internal metadata path.
  140. /// </summary>
  141. /// <returns>System.String.</returns>
  142. string GetInternalMetadataPath();
  143. /// <summary>
  144. /// Gets a value indicating whether [always scan internal metadata path].
  145. /// </summary>
  146. /// <value><c>true</c> if [always scan internal metadata path]; otherwise, <c>false</c>.</value>
  147. bool AlwaysScanInternalMetadataPath { get; }
  148. /// <summary>
  149. /// Determines whether [is internet metadata enabled].
  150. /// </summary>
  151. /// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
  152. bool IsInternetMetadataEnabled();
  153. /// <summary>
  154. /// Removes the image.
  155. /// </summary>
  156. /// <param name="image">The image.</param>
  157. void RemoveImage(ItemImageInfo image);
  158. /// <summary>
  159. /// Updates to repository.
  160. /// </summary>
  161. /// <param name="updateReason">The update reason.</param>
  162. /// <param name="cancellationToken">The cancellation token.</param>
  163. /// <returns>Task.</returns>
  164. Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
  165. /// <summary>
  166. /// Sets the image.
  167. /// </summary>
  168. /// <param name="image">The image.</param>
  169. /// <param name="index">The index.</param>
  170. void SetImage(ItemImageInfo image, int index);
  171. double? GetDefaultPrimaryImageAspectRatio();
  172. int? ProductionYear { get; set; }
  173. List<string> Tags { get; set; }
  174. }
  175. public static class HasImagesExtensions
  176. {
  177. /// <summary>
  178. /// Gets the image path.
  179. /// </summary>
  180. /// <param name="item">The item.</param>
  181. /// <param name="imageType">Type of the image.</param>
  182. /// <returns>System.String.</returns>
  183. public static string GetImagePath(this IHasImages item, ImageType imageType)
  184. {
  185. return item.GetImagePath(imageType, 0);
  186. }
  187. public static bool HasImage(this IHasImages item, ImageType imageType)
  188. {
  189. return item.HasImage(imageType, 0);
  190. }
  191. /// <summary>
  192. /// Sets the image path.
  193. /// </summary>
  194. /// <param name="item">The item.</param>
  195. /// <param name="imageType">Type of the image.</param>
  196. /// <param name="file">The file.</param>
  197. public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemMetadata file)
  198. {
  199. item.SetImagePath(imageType, 0, file);
  200. }
  201. /// <summary>
  202. /// Sets the image path.
  203. /// </summary>
  204. /// <param name="item">The item.</param>
  205. /// <param name="imageType">Type of the image.</param>
  206. /// <param name="file">The file.</param>
  207. public static void SetImagePath(this IHasImages item, ImageType imageType, string file)
  208. {
  209. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  210. {
  211. item.SetImage(new ItemImageInfo
  212. {
  213. Path = file,
  214. Type = imageType
  215. }, 0);
  216. }
  217. else
  218. {
  219. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  220. }
  221. }
  222. }
  223. }