Movie.cs 6.3 KB

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