Movie.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.Entities;
  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, IHasSoundtracks, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasPreferredMetadataLanguage, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>
  17. {
  18. public List<Guid> SpecialFeatureIds { get; set; }
  19. public List<Guid> SoundtrackIds { get; set; }
  20. public List<Guid> ThemeSongIds { get; set; }
  21. public List<Guid> ThemeVideoIds { get; set; }
  22. /// <summary>
  23. /// Gets or sets the preferred metadata country code.
  24. /// </summary>
  25. /// <value>The preferred metadata country code.</value>
  26. public string PreferredMetadataCountryCode { get; set; }
  27. public string PreferredMetadataLanguage { get; set; }
  28. public Movie()
  29. {
  30. SpecialFeatureIds = new List<Guid>();
  31. SoundtrackIds = new List<Guid>();
  32. RemoteTrailers = new List<MediaUrl>();
  33. LocalTrailerIds = new List<Guid>();
  34. ThemeSongIds = new List<Guid>();
  35. ThemeVideoIds = new List<Guid>();
  36. Taglines = new List<string>();
  37. Keywords = new List<string>();
  38. }
  39. public string AwardSummary { get; set; }
  40. public float? Metascore { get; set; }
  41. public List<Guid> LocalTrailerIds { 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 critic rating.
  61. /// </summary>
  62. /// <value>The critic rating.</value>
  63. public float? CriticRating { get; set; }
  64. /// <summary>
  65. /// Gets or sets the critic rating summary.
  66. /// </summary>
  67. /// <value>The critic rating summary.</value>
  68. public string CriticRatingSummary { get; set; }
  69. /// <summary>
  70. /// Gets or sets the name of the TMDB collection.
  71. /// </summary>
  72. /// <value>The name of the TMDB collection.</value>
  73. public string TmdbCollectionName { get; set; }
  74. /// <summary>
  75. /// Gets the user data key.
  76. /// </summary>
  77. /// <returns>System.String.</returns>
  78. public override string GetUserDataKey()
  79. {
  80. return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.GetUserDataKey();
  81. }
  82. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  83. {
  84. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  85. // Must have a parent to have special features
  86. // In other words, it must be part of the Parent/Child tree
  87. if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder)
  88. {
  89. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  90. if (specialFeaturesChanged)
  91. {
  92. hasChanges = true;
  93. }
  94. }
  95. return hasChanges;
  96. }
  97. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  98. {
  99. var newItems = LoadSpecialFeatures(fileSystemChildren, options.DirectoryService).ToList();
  100. var newItemIds = newItems.Select(i => i.Id).ToList();
  101. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  102. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  103. await Task.WhenAll(tasks).ConfigureAwait(false);
  104. SpecialFeatureIds = newItemIds;
  105. return itemsChanged;
  106. }
  107. /// <summary>
  108. /// Loads the special features.
  109. /// </summary>
  110. /// <returns>IEnumerable{Video}.</returns>
  111. private IEnumerable<Video> LoadSpecialFeatures(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
  112. {
  113. var files = fileSystemChildren.OfType<DirectoryInfo>()
  114. .Where(i => string.Equals(i.Name, "extras", StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, "specials", StringComparison.OrdinalIgnoreCase))
  115. .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly));
  116. return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
  117. {
  118. // Try to retrieve it from the db. If we don't find it, use the resolved version
  119. var dbItem = LibraryManager.GetItemById(video.Id) as Video;
  120. if (dbItem != null)
  121. {
  122. video = dbItem;
  123. }
  124. return video;
  125. // Sort them so that the list can be easily compared for changes
  126. }).OrderBy(i => i.Path).ToList();
  127. }
  128. protected override bool GetBlockUnratedValue(UserConfiguration config)
  129. {
  130. return config.BlockUnratedItems.Contains(UnratedItem.Movie);
  131. }
  132. public MovieInfo GetLookupInfo()
  133. {
  134. return GetItemLookupInfo<MovieInfo>();
  135. }
  136. public override bool BeforeMetadataRefresh()
  137. {
  138. var hasChanges = base.BeforeMetadataRefresh();
  139. if (!ProductionYear.HasValue)
  140. {
  141. int? yearInName = null;
  142. string name;
  143. NameParser.ParseName(Name, out name, out yearInName);
  144. if (yearInName.HasValue)
  145. {
  146. ProductionYear = yearInName;
  147. hasChanges = true;
  148. }
  149. }
  150. return hasChanges;
  151. }
  152. }
  153. }