2
0

IHasImages.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Entities;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using CommonIO;
  8. using MediaBrowser.Common.IO;
  9. using MediaBrowser.Controller.Library;
  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. /// <summary>
  134. /// Gets a value indicating whether this instance is in mixed folder.
  135. /// </summary>
  136. /// <value><c>true</c> if this instance is in mixed folder; otherwise, <c>false</c>.</value>
  137. bool IsInMixedFolder { get; }
  138. /// <summary>
  139. /// Gets a value indicating whether this instance is locked.
  140. /// </summary>
  141. /// <value><c>true</c> if this instance is locked; otherwise, <c>false</c>.</value>
  142. bool IsLocked { get; }
  143. /// <summary>
  144. /// Gets a value indicating whether [supports remote image downloading].
  145. /// </summary>
  146. /// <value><c>true</c> if [supports remote image downloading]; otherwise, <c>false</c>.</value>
  147. bool SupportsRemoteImageDownloading { get; }
  148. /// <summary>
  149. /// Gets the internal metadata path.
  150. /// </summary>
  151. /// <returns>System.String.</returns>
  152. string GetInternalMetadataPath();
  153. /// <summary>
  154. /// Gets a value indicating whether [always scan internal metadata path].
  155. /// </summary>
  156. /// <value><c>true</c> if [always scan internal metadata path]; otherwise, <c>false</c>.</value>
  157. bool AlwaysScanInternalMetadataPath { get; }
  158. /// <summary>
  159. /// Determines whether [is internet metadata enabled].
  160. /// </summary>
  161. /// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
  162. bool IsInternetMetadataEnabled();
  163. /// <summary>
  164. /// Removes the image.
  165. /// </summary>
  166. /// <param name="image">The image.</param>
  167. void RemoveImage(ItemImageInfo image);
  168. /// <summary>
  169. /// Updates to repository.
  170. /// </summary>
  171. /// <param name="updateReason">The update reason.</param>
  172. /// <param name="cancellationToken">The cancellation token.</param>
  173. /// <returns>Task.</returns>
  174. Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
  175. /// <summary>
  176. /// Sets the image.
  177. /// </summary>
  178. /// <param name="image">The image.</param>
  179. /// <param name="index">The index.</param>
  180. void SetImage(ItemImageInfo image, int index);
  181. }
  182. public static class HasImagesExtensions
  183. {
  184. /// <summary>
  185. /// Gets the image path.
  186. /// </summary>
  187. /// <param name="item">The item.</param>
  188. /// <param name="imageType">Type of the image.</param>
  189. /// <returns>System.String.</returns>
  190. public static string GetImagePath(this IHasImages item, ImageType imageType)
  191. {
  192. return item.GetImagePath(imageType, 0);
  193. }
  194. public static bool HasImage(this IHasImages item, ImageType imageType)
  195. {
  196. return item.HasImage(imageType, 0);
  197. }
  198. /// <summary>
  199. /// Sets the image path.
  200. /// </summary>
  201. /// <param name="item">The item.</param>
  202. /// <param name="imageType">Type of the image.</param>
  203. /// <param name="file">The file.</param>
  204. public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemMetadata file)
  205. {
  206. item.SetImagePath(imageType, 0, file);
  207. }
  208. /// <summary>
  209. /// Sets the image path.
  210. /// </summary>
  211. /// <param name="item">The item.</param>
  212. /// <param name="imageType">Type of the image.</param>
  213. /// <param name="file">The file.</param>
  214. public static void SetImagePath(this IHasImages item, ImageType imageType, string file)
  215. {
  216. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  217. {
  218. item.SetImage(new ItemImageInfo
  219. {
  220. Path = file,
  221. Type = imageType
  222. }, 0);
  223. }
  224. else
  225. {
  226. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  227. }
  228. }
  229. }
  230. }