Movie.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 = this.GetProviderId(MetadataProviders.Tmdb);
  88. if (string.IsNullOrWhiteSpace(key))
  89. {
  90. key = this.GetProviderId(MetadataProviders.Imdb);
  91. }
  92. if (string.IsNullOrWhiteSpace(key))
  93. {
  94. key = base.CreateUserDataKey();
  95. }
  96. return key;
  97. }
  98. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  99. {
  100. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  101. // Must have a parent to have special features
  102. // In other words, it must be part of the Parent/Child tree
  103. if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder)
  104. {
  105. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  106. if (specialFeaturesChanged)
  107. {
  108. hasChanges = true;
  109. }
  110. }
  111. return hasChanges;
  112. }
  113. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  114. {
  115. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  116. var newItemIds = newItems.Select(i => i.Id).ToList();
  117. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  118. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  119. await Task.WhenAll(tasks).ConfigureAwait(false);
  120. SpecialFeatureIds = newItemIds;
  121. return itemsChanged;
  122. }
  123. protected override bool GetBlockUnratedValue(UserPolicy config)
  124. {
  125. return config.BlockUnratedItems.Contains(UnratedItem.Movie);
  126. }
  127. public MovieInfo GetLookupInfo()
  128. {
  129. var info = GetItemLookupInfo<MovieInfo>();
  130. if (!IsInMixedFolder)
  131. {
  132. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  133. }
  134. return info;
  135. }
  136. public override bool BeforeMetadataRefresh()
  137. {
  138. var hasChanges = base.BeforeMetadataRefresh();
  139. if (!ProductionYear.HasValue)
  140. {
  141. var info = LibraryManager.ParseName(Name);
  142. var yearInName = info.Year;
  143. if (yearInName.HasValue)
  144. {
  145. ProductionYear = yearInName;
  146. hasChanges = true;
  147. }
  148. else
  149. {
  150. // Try to get the year from the folder name
  151. if (!IsInMixedFolder)
  152. {
  153. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  154. yearInName = info.Year;
  155. if (yearInName.HasValue)
  156. {
  157. ProductionYear = yearInName;
  158. hasChanges = true;
  159. }
  160. }
  161. }
  162. }
  163. return hasChanges;
  164. }
  165. }
  166. }