IHasMetadata.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Providers;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.IO;
  9. namespace MediaBrowser.Controller.Entities
  10. {
  11. /// <summary>
  12. /// Interface IHasMetadata
  13. /// </summary>
  14. public interface IHasMetadata : IHasProviderIds, IHasUserData
  15. {
  16. /// <summary>
  17. /// Gets the preferred metadata country code.
  18. /// </summary>
  19. /// <returns>System.String.</returns>
  20. string GetPreferredMetadataCountryCode();
  21. /// <summary>
  22. /// Gets the date modified.
  23. /// </summary>
  24. /// <value>The date modified.</value>
  25. DateTime DateModified { get; set; }
  26. /// <summary>
  27. /// Gets or sets the date last saved.
  28. /// </summary>
  29. /// <value>The date last saved.</value>
  30. DateTime DateLastSaved { get; set; }
  31. SourceType SourceType { get; }
  32. /// <summary>
  33. /// Gets or sets the date last refreshed.
  34. /// </summary>
  35. /// <value>The date last refreshed.</value>
  36. DateTime DateLastRefreshed { get; set; }
  37. /// <summary>
  38. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  39. /// </summary>
  40. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  41. bool BeforeMetadataRefresh();
  42. /// <summary>
  43. /// Afters the metadata refresh.
  44. /// </summary>
  45. void AfterMetadataRefresh();
  46. /// <summary>
  47. /// Gets a value indicating whether [supports people].
  48. /// </summary>
  49. /// <value><c>true</c> if [supports people]; otherwise, <c>false</c>.</value>
  50. bool SupportsPeople { get; }
  51. bool RequiresRefresh();
  52. bool EnableRefreshOnDateModifiedChange { get; }
  53. string PresentationUniqueKey { get; set; }
  54. string GetPresentationUniqueKey();
  55. string CreatePresentationUniqueKey();
  56. bool StopRefreshIfLocalMetadataFound { get; }
  57. int? GetInheritedParentalRatingValue();
  58. int InheritedParentalRatingValue { get; set; }
  59. List<string> GetInheritedTags();
  60. long? RunTimeTicks { get; set; }
  61. /// <summary>
  62. /// Gets the name.
  63. /// </summary>
  64. /// <value>The name.</value>
  65. string Name { get; set; }
  66. /// <summary>
  67. /// Gets the path.
  68. /// </summary>
  69. /// <value>The path.</value>
  70. string Path { get; set; }
  71. /// <summary>
  72. /// Gets the file name without extension.
  73. /// </summary>
  74. /// <value>The file name without extension.</value>
  75. string FileNameWithoutExtension { get; }
  76. /// <summary>
  77. /// Gets the type of the location.
  78. /// </summary>
  79. /// <value>The type of the location.</value>
  80. LocationType LocationType { get; }
  81. /// <summary>
  82. /// Gets the locked fields.
  83. /// </summary>
  84. /// <value>The locked fields.</value>
  85. MetadataFields[] LockedFields { get; }
  86. /// <summary>
  87. /// Gets the images.
  88. /// </summary>
  89. /// <param name="imageType">Type of the image.</param>
  90. /// <returns>IEnumerable{ItemImageInfo}.</returns>
  91. IEnumerable<ItemImageInfo> GetImages(ImageType imageType);
  92. /// <summary>
  93. /// Gets the image path.
  94. /// </summary>
  95. /// <param name="imageType">Type of the image.</param>
  96. /// <param name="imageIndex">Index of the image.</param>
  97. /// <returns>System.String.</returns>
  98. string GetImagePath(ImageType imageType, int imageIndex);
  99. /// <summary>
  100. /// Gets the image information.
  101. /// </summary>
  102. /// <param name="imageType">Type of the image.</param>
  103. /// <param name="imageIndex">Index of the image.</param>
  104. /// <returns>ItemImageInfo.</returns>
  105. ItemImageInfo GetImageInfo(ImageType imageType, int imageIndex);
  106. /// <summary>
  107. /// Sets the image.
  108. /// </summary>
  109. /// <param name="type">The type.</param>
  110. /// <param name="index">The index.</param>
  111. /// <param name="file">The file.</param>
  112. void SetImagePath(ImageType type, int index, FileSystemMetadata file);
  113. /// <summary>
  114. /// Determines whether the specified type has image.
  115. /// </summary>
  116. /// <param name="type">The type.</param>
  117. /// <param name="imageIndex">Index of the image.</param>
  118. /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns>
  119. bool HasImage(ImageType type, int imageIndex);
  120. /// <summary>
  121. /// Allowses the multiple images.
  122. /// </summary>
  123. /// <param name="type">The type.</param>
  124. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  125. bool AllowsMultipleImages(ImageType type);
  126. /// <summary>
  127. /// Swaps the images.
  128. /// </summary>
  129. void SwapImages(ImageType type, int index1, int index2);
  130. /// <summary>
  131. /// Gets or sets the primary image path.
  132. /// </summary>
  133. /// <value>The primary image path.</value>
  134. string PrimaryImagePath { get; }
  135. /// <summary>
  136. /// Gets the preferred metadata language.
  137. /// </summary>
  138. /// <returns>System.String.</returns>
  139. string GetPreferredMetadataLanguage();
  140. /// <summary>
  141. /// Validates the images and returns true or false indicating if any were removed.
  142. /// </summary>
  143. bool ValidateImages(IDirectoryService directoryService);
  144. /// <summary>
  145. /// Gets a value indicating whether this instance is owned item.
  146. /// </summary>
  147. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  148. bool IsOwnedItem { get; }
  149. /// <summary>
  150. /// Gets the containing folder path.
  151. /// </summary>
  152. /// <value>The containing folder path.</value>
  153. string ContainingFolderPath { get; }
  154. /// <summary>
  155. /// Adds the images.
  156. /// </summary>
  157. /// <param name="imageType">Type of the image.</param>
  158. /// <param name="images">The images.</param>
  159. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  160. bool AddImages(ImageType imageType, List<FileSystemMetadata> images);
  161. /// <summary>
  162. /// Determines whether [is save local metadata enabled].
  163. /// </summary>
  164. /// <returns><c>true</c> if [is save local metadata enabled]; otherwise, <c>false</c>.</returns>
  165. bool IsSaveLocalMetadataEnabled();
  166. /// <summary>
  167. /// Gets a value indicating whether [supports local metadata].
  168. /// </summary>
  169. /// <value><c>true</c> if [supports local metadata]; otherwise, <c>false</c>.</value>
  170. bool SupportsLocalMetadata { get; }
  171. bool IsInMixedFolder { get; }
  172. /// <summary>
  173. /// Gets a value indicating whether this instance is locked.
  174. /// </summary>
  175. /// <value><c>true</c> if this instance is locked; otherwise, <c>false</c>.</value>
  176. bool IsLocked { get; }
  177. /// <summary>
  178. /// Gets a value indicating whether [supports remote image downloading].
  179. /// </summary>
  180. /// <value><c>true</c> if [supports remote image downloading]; otherwise, <c>false</c>.</value>
  181. bool SupportsRemoteImageDownloading { get; }
  182. /// <summary>
  183. /// Gets the internal metadata path.
  184. /// </summary>
  185. /// <returns>System.String.</returns>
  186. string GetInternalMetadataPath();
  187. /// <summary>
  188. /// Gets a value indicating whether [always scan internal metadata path].
  189. /// </summary>
  190. /// <value><c>true</c> if [always scan internal metadata path]; otherwise, <c>false</c>.</value>
  191. bool AlwaysScanInternalMetadataPath { get; }
  192. /// <summary>
  193. /// Determines whether [is internet metadata enabled].
  194. /// </summary>
  195. /// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
  196. bool IsInternetMetadataEnabled();
  197. /// <summary>
  198. /// Removes the image.
  199. /// </summary>
  200. /// <param name="image">The image.</param>
  201. void RemoveImage(ItemImageInfo image);
  202. void RemoveImages(List<ItemImageInfo> images);
  203. /// <summary>
  204. /// Updates to repository.
  205. /// </summary>
  206. void UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
  207. /// <summary>
  208. /// Sets the image.
  209. /// </summary>
  210. /// <param name="image">The image.</param>
  211. /// <param name="index">The index.</param>
  212. void SetImage(ItemImageInfo image, int index);
  213. double? GetDefaultPrimaryImageAspectRatio();
  214. int? ProductionYear { get; set; }
  215. string[] Tags { get; set; }
  216. ItemUpdateType OnMetadataChanged();
  217. }
  218. public static class HasMetadataExtensions
  219. {
  220. /// <summary>
  221. /// Gets the image path.
  222. /// </summary>
  223. /// <param name="item">The item.</param>
  224. /// <param name="imageType">Type of the image.</param>
  225. /// <returns>System.String.</returns>
  226. public static string GetImagePath(this IHasMetadata item, ImageType imageType)
  227. {
  228. return item.GetImagePath(imageType, 0);
  229. }
  230. public static bool HasImage(this IHasMetadata item, ImageType imageType)
  231. {
  232. return item.HasImage(imageType, 0);
  233. }
  234. /// <summary>
  235. /// Sets the image path.
  236. /// </summary>
  237. /// <param name="item">The item.</param>
  238. /// <param name="imageType">Type of the image.</param>
  239. /// <param name="file">The file.</param>
  240. public static void SetImagePath(this IHasMetadata item, ImageType imageType, FileSystemMetadata file)
  241. {
  242. item.SetImagePath(imageType, 0, file);
  243. }
  244. /// <summary>
  245. /// Sets the image path.
  246. /// </summary>
  247. /// <param name="item">The item.</param>
  248. /// <param name="imageType">Type of the image.</param>
  249. /// <param name="file">The file.</param>
  250. public static void SetImagePath(this IHasMetadata item, ImageType imageType, string file)
  251. {
  252. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  253. {
  254. item.SetImage(new ItemImageInfo
  255. {
  256. Path = file,
  257. Type = imageType
  258. }, 0);
  259. }
  260. else
  261. {
  262. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  263. }
  264. }
  265. }
  266. }