Movie.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Configuration;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Users;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using CommonIO;
  13. using MediaBrowser.Common.IO;
  14. namespace MediaBrowser.Controller.Entities.Movies
  15. {
  16. /// <summary>
  17. /// Class Movie
  18. /// </summary>
  19. public class Movie : Video, IHasCriticRating, IHasSpecialFeatures, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping, IHasOriginalTitle
  20. {
  21. public List<Guid> SpecialFeatureIds { get; set; }
  22. public string OriginalTitle { get; set; }
  23. public List<Guid> ThemeSongIds { get; set; }
  24. public List<Guid> ThemeVideoIds { get; set; }
  25. public List<string> ProductionLocations { get; set; }
  26. public Movie()
  27. {
  28. SpecialFeatureIds = new List<Guid>();
  29. RemoteTrailers = new List<MediaUrl>();
  30. LocalTrailerIds = new List<Guid>();
  31. RemoteTrailerIds = new List<Guid>();
  32. ThemeSongIds = new List<Guid>();
  33. ThemeVideoIds = new List<Guid>();
  34. Taglines = new List<string>();
  35. Keywords = new List<string>();
  36. ProductionLocations = new List<string>();
  37. }
  38. public string AwardSummary { get; set; }
  39. public float? Metascore { get; set; }
  40. public List<Guid> LocalTrailerIds { get; set; }
  41. public List<Guid> RemoteTrailerIds { get; set; }
  42. public List<string> Keywords { get; set; }
  43. public List<MediaUrl> RemoteTrailers { get; set; }
  44. /// <summary>
  45. /// Gets or sets the taglines.
  46. /// </summary>
  47. /// <value>The taglines.</value>
  48. public List<string> Taglines { get; set; }
  49. /// <summary>
  50. /// Gets or sets the budget.
  51. /// </summary>
  52. /// <value>The budget.</value>
  53. public double? Budget { get; set; }
  54. /// <summary>
  55. /// Gets or sets the revenue.
  56. /// </summary>
  57. /// <value>The revenue.</value>
  58. public double? Revenue { get; set; }
  59. /// <summary>
  60. /// Gets or sets the critic rating.
  61. /// </summary>
  62. /// <value>The critic rating.</value>
  63. public float? CriticRating { get; set; }
  64. /// <summary>
  65. /// Gets or sets the critic rating summary.
  66. /// </summary>
  67. /// <value>The critic rating summary.</value>
  68. public string CriticRatingSummary { get; set; }
  69. /// <summary>
  70. /// Gets or sets the name of the TMDB collection.
  71. /// </summary>
  72. /// <value>The name of the TMDB collection.</value>
  73. public string TmdbCollectionName { get; set; }
  74. [IgnoreDataMember]
  75. public string CollectionName
  76. {
  77. get { return TmdbCollectionName; }
  78. set { TmdbCollectionName = value; }
  79. }
  80. /// <summary>
  81. /// Gets the trailer ids.
  82. /// </summary>
  83. /// <returns>List&lt;Guid&gt;.</returns>
  84. public List<Guid> GetTrailerIds()
  85. {
  86. var list = LocalTrailerIds.ToList();
  87. list.AddRange(RemoteTrailerIds);
  88. return list;
  89. }
  90. /// <summary>
  91. /// Gets the user data key.
  92. /// </summary>
  93. /// <returns>System.String.</returns>
  94. protected override string CreateUserDataKey()
  95. {
  96. var key = GetMovieUserDataKey(this);
  97. if (string.IsNullOrWhiteSpace(key))
  98. {
  99. key = base.CreateUserDataKey();
  100. }
  101. return key;
  102. }
  103. public static string GetMovieUserDataKey(BaseItem movie)
  104. {
  105. var key = movie.GetProviderId(MetadataProviders.Tmdb);
  106. if (string.IsNullOrWhiteSpace(key))
  107. {
  108. key = movie.GetProviderId(MetadataProviders.Imdb);
  109. }
  110. return key;
  111. }
  112. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  113. {
  114. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  115. // Must have a parent to have special features
  116. // In other words, it must be part of the Parent/Child tree
  117. if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
  118. {
  119. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  120. if (specialFeaturesChanged)
  121. {
  122. hasChanges = true;
  123. }
  124. }
  125. return hasChanges;
  126. }
  127. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  128. {
  129. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  130. var newItemIds = newItems.Select(i => i.Id).ToList();
  131. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  132. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  133. await Task.WhenAll(tasks).ConfigureAwait(false);
  134. SpecialFeatureIds = newItemIds;
  135. return itemsChanged;
  136. }
  137. public override UnratedItem GetBlockUnratedType()
  138. {
  139. return UnratedItem.Movie;
  140. }
  141. public MovieInfo GetLookupInfo()
  142. {
  143. var info = GetItemLookupInfo<MovieInfo>();
  144. if (!IsInMixedFolder)
  145. {
  146. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  147. }
  148. return info;
  149. }
  150. public override bool BeforeMetadataRefresh()
  151. {
  152. var hasChanges = base.BeforeMetadataRefresh();
  153. if (!ProductionYear.HasValue)
  154. {
  155. var info = LibraryManager.ParseName(Name);
  156. var yearInName = info.Year;
  157. if (yearInName.HasValue)
  158. {
  159. ProductionYear = yearInName;
  160. hasChanges = true;
  161. }
  162. else
  163. {
  164. // Try to get the year from the folder name
  165. if (!IsInMixedFolder)
  166. {
  167. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  168. yearInName = info.Year;
  169. if (yearInName.HasValue)
  170. {
  171. ProductionYear = yearInName;
  172. hasChanges = true;
  173. }
  174. }
  175. }
  176. }
  177. return hasChanges;
  178. }
  179. }
  180. }