Movie.cs 6.8 KB

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