Movie.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 name of the TMDB collection.
  61. /// </summary>
  62. /// <value>The name of the TMDB collection.</value>
  63. public string TmdbCollectionName { get; set; }
  64. [IgnoreDataMember]
  65. public string CollectionName
  66. {
  67. get { return TmdbCollectionName; }
  68. set { TmdbCollectionName = value; }
  69. }
  70. /// <summary>
  71. /// Gets the trailer ids.
  72. /// </summary>
  73. /// <returns>List&lt;Guid&gt;.</returns>
  74. public List<Guid> GetTrailerIds()
  75. {
  76. var list = LocalTrailerIds.ToList();
  77. list.AddRange(RemoteTrailerIds);
  78. return list;
  79. }
  80. /// <summary>
  81. /// Gets the user data key.
  82. /// </summary>
  83. /// <returns>System.String.</returns>
  84. protected override string CreateUserDataKey()
  85. {
  86. var key = GetMovieUserDataKey(this);
  87. if (string.IsNullOrWhiteSpace(key))
  88. {
  89. key = base.CreateUserDataKey();
  90. }
  91. return key;
  92. }
  93. public static string GetMovieUserDataKey(BaseItem movie)
  94. {
  95. var key = movie.GetProviderId(MetadataProviders.Tmdb);
  96. if (string.IsNullOrWhiteSpace(key))
  97. {
  98. key = movie.GetProviderId(MetadataProviders.Imdb);
  99. }
  100. return key;
  101. }
  102. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  103. {
  104. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  105. // Must have a parent to have special features
  106. // In other words, it must be part of the Parent/Child tree
  107. if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
  108. {
  109. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  110. if (specialFeaturesChanged)
  111. {
  112. hasChanges = true;
  113. }
  114. }
  115. return hasChanges;
  116. }
  117. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  118. {
  119. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  120. var newItemIds = newItems.Select(i => i.Id).ToList();
  121. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  122. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  123. await Task.WhenAll(tasks).ConfigureAwait(false);
  124. SpecialFeatureIds = newItemIds;
  125. return itemsChanged;
  126. }
  127. public override UnratedItem GetBlockUnratedType()
  128. {
  129. return UnratedItem.Movie;
  130. }
  131. public MovieInfo GetLookupInfo()
  132. {
  133. var info = GetItemLookupInfo<MovieInfo>();
  134. if (!IsInMixedFolder)
  135. {
  136. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  137. }
  138. return info;
  139. }
  140. public override bool BeforeMetadataRefresh()
  141. {
  142. var hasChanges = base.BeforeMetadataRefresh();
  143. if (!ProductionYear.HasValue)
  144. {
  145. var info = LibraryManager.ParseName(Name);
  146. var yearInName = info.Year;
  147. if (yearInName.HasValue)
  148. {
  149. ProductionYear = yearInName;
  150. hasChanges = true;
  151. }
  152. else
  153. {
  154. // Try to get the year from the folder name
  155. if (!IsInMixedFolder)
  156. {
  157. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  158. yearInName = info.Year;
  159. if (yearInName.HasValue)
  160. {
  161. ProductionYear = yearInName;
  162. hasChanges = true;
  163. }
  164. }
  165. }
  166. }
  167. return hasChanges;
  168. }
  169. }
  170. }