Movie.cs 6.8 KB

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