IHasMetadata.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. /// <param name="type">The type.</param>
  130. /// <param name="index1">The index1.</param>
  131. /// <param name="index2">The index2.</param>
  132. /// <returns>Task.</returns>
  133. Task SwapImages(ImageType type, int index1, int index2);
  134. /// <summary>
  135. /// Gets or sets the primary image path.
  136. /// </summary>
  137. /// <value>The primary image path.</value>
  138. string PrimaryImagePath { get; }
  139. /// <summary>
  140. /// Gets the preferred metadata language.
  141. /// </summary>
  142. /// <returns>System.String.</returns>
  143. string GetPreferredMetadataLanguage();
  144. /// <summary>
  145. /// Validates the images and returns true or false indicating if any were removed.
  146. /// </summary>
  147. bool ValidateImages(IDirectoryService directoryService);
  148. /// <summary>
  149. /// Gets a value indicating whether this instance is owned item.
  150. /// </summary>
  151. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  152. bool IsOwnedItem { get; }
  153. /// <summary>
  154. /// Gets the containing folder path.
  155. /// </summary>
  156. /// <value>The containing folder path.</value>
  157. string ContainingFolderPath { get; }
  158. /// <summary>
  159. /// Adds the images.
  160. /// </summary>
  161. /// <param name="imageType">Type of the image.</param>
  162. /// <param name="images">The images.</param>
  163. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  164. bool AddImages(ImageType imageType, List<FileSystemMetadata> images);
  165. /// <summary>
  166. /// Determines whether [is save local metadata enabled].
  167. /// </summary>
  168. /// <returns><c>true</c> if [is save local metadata enabled]; otherwise, <c>false</c>.</returns>
  169. bool IsSaveLocalMetadataEnabled();
  170. /// <summary>
  171. /// Gets a value indicating whether [supports local metadata].
  172. /// </summary>
  173. /// <value><c>true</c> if [supports local metadata]; otherwise, <c>false</c>.</value>
  174. bool SupportsLocalMetadata { get; }
  175. bool IsInMixedFolder { get; }
  176. /// <summary>
  177. /// Gets a value indicating whether this instance is locked.
  178. /// </summary>
  179. /// <value><c>true</c> if this instance is locked; otherwise, <c>false</c>.</value>
  180. bool IsLocked { get; }
  181. /// <summary>
  182. /// Gets a value indicating whether [supports remote image downloading].
  183. /// </summary>
  184. /// <value><c>true</c> if [supports remote image downloading]; otherwise, <c>false</c>.</value>
  185. bool SupportsRemoteImageDownloading { get; }
  186. /// <summary>
  187. /// Gets the internal metadata path.
  188. /// </summary>
  189. /// <returns>System.String.</returns>
  190. string GetInternalMetadataPath();
  191. /// <summary>
  192. /// Gets a value indicating whether [always scan internal metadata path].
  193. /// </summary>
  194. /// <value><c>true</c> if [always scan internal metadata path]; otherwise, <c>false</c>.</value>
  195. bool AlwaysScanInternalMetadataPath { get; }
  196. /// <summary>
  197. /// Determines whether [is internet metadata enabled].
  198. /// </summary>
  199. /// <returns><c>true</c> if [is internet metadata enabled]; otherwise, <c>false</c>.</returns>
  200. bool IsInternetMetadataEnabled();
  201. /// <summary>
  202. /// Removes the image.
  203. /// </summary>
  204. /// <param name="image">The image.</param>
  205. void RemoveImage(ItemImageInfo image);
  206. void RemoveImages(List<ItemImageInfo> images);
  207. /// <summary>
  208. /// Updates to repository.
  209. /// </summary>
  210. /// <param name="updateReason">The update reason.</param>
  211. /// <param name="cancellationToken">The cancellation token.</param>
  212. /// <returns>Task.</returns>
  213. Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken);
  214. /// <summary>
  215. /// Sets the image.
  216. /// </summary>
  217. /// <param name="image">The image.</param>
  218. /// <param name="index">The index.</param>
  219. void SetImage(ItemImageInfo image, int index);
  220. double? GetDefaultPrimaryImageAspectRatio();
  221. int? ProductionYear { get; set; }
  222. string[] Tags { get; set; }
  223. }
  224. public static class HasMetadataExtensions
  225. {
  226. /// <summary>
  227. /// Gets the image path.
  228. /// </summary>
  229. /// <param name="item">The item.</param>
  230. /// <param name="imageType">Type of the image.</param>
  231. /// <returns>System.String.</returns>
  232. public static string GetImagePath(this IHasMetadata item, ImageType imageType)
  233. {
  234. return item.GetImagePath(imageType, 0);
  235. }
  236. public static bool HasImage(this IHasMetadata item, ImageType imageType)
  237. {
  238. return item.HasImage(imageType, 0);
  239. }
  240. /// <summary>
  241. /// Sets the image path.
  242. /// </summary>
  243. /// <param name="item">The item.</param>
  244. /// <param name="imageType">Type of the image.</param>
  245. /// <param name="file">The file.</param>
  246. public static void SetImagePath(this IHasMetadata item, ImageType imageType, FileSystemMetadata file)
  247. {
  248. item.SetImagePath(imageType, 0, file);
  249. }
  250. /// <summary>
  251. /// Sets the image path.
  252. /// </summary>
  253. /// <param name="item">The item.</param>
  254. /// <param name="imageType">Type of the image.</param>
  255. /// <param name="file">The file.</param>
  256. public static void SetImagePath(this IHasMetadata item, ImageType imageType, string file)
  257. {
  258. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  259. {
  260. item.SetImage(new ItemImageInfo
  261. {
  262. Path = file,
  263. Type = imageType
  264. }, 0);
  265. }
  266. else
  267. {
  268. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  269. }
  270. }
  271. }
  272. }