Movie.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.Threading;
  8. using System.Threading.Tasks;
  9. using MediaBrowser.Common.IO;
  10. using MediaBrowser.Controller.IO;
  11. using MediaBrowser.Model.IO;
  12. using MediaBrowser.Model.Providers;
  13. using MediaBrowser.Model.Serialization;
  14. namespace MediaBrowser.Controller.Entities.Movies
  15. {
  16. /// <summary>
  17. /// Class Movie
  18. /// </summary>
  19. public class Movie : Video, IHasSpecialFeatures, IHasBudget, IHasTrailers, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
  20. {
  21. public List<Guid> SpecialFeatureIds { get; set; }
  22. public Movie()
  23. {
  24. SpecialFeatureIds = new List<Guid>();
  25. RemoteTrailers = new List<MediaUrl>();
  26. LocalTrailerIds = new List<Guid>();
  27. RemoteTrailerIds = new List<Guid>();
  28. Taglines = new List<string>();
  29. }
  30. public string AwardSummary { get; set; }
  31. public float? Metascore { get; set; }
  32. public List<Guid> LocalTrailerIds { get; set; }
  33. public List<Guid> RemoteTrailerIds { get; set; }
  34. public List<MediaUrl> RemoteTrailers { get; set; }
  35. /// <summary>
  36. /// Gets or sets the taglines.
  37. /// </summary>
  38. /// <value>The taglines.</value>
  39. public List<string> Taglines { get; set; }
  40. /// <summary>
  41. /// Gets or sets the budget.
  42. /// </summary>
  43. /// <value>The budget.</value>
  44. public double? Budget { get; set; }
  45. /// <summary>
  46. /// Gets or sets the revenue.
  47. /// </summary>
  48. /// <value>The revenue.</value>
  49. public double? Revenue { get; set; }
  50. /// <summary>
  51. /// Gets or sets the name of the TMDB collection.
  52. /// </summary>
  53. /// <value>The name of the TMDB collection.</value>
  54. public string TmdbCollectionName { get; set; }
  55. [IgnoreDataMember]
  56. public string CollectionName
  57. {
  58. get { return TmdbCollectionName; }
  59. set { TmdbCollectionName = value; }
  60. }
  61. [IgnoreDataMember]
  62. protected override bool SupportsIsInMixedFolderDetection
  63. {
  64. get
  65. {
  66. return false;
  67. }
  68. }
  69. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  70. {
  71. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  72. // Must have a parent to have special features
  73. // In other words, it must be part of the Parent/Child tree
  74. if (LocationType == LocationType.FileSystem && GetParent() != null && !DetectIsInMixedFolder())
  75. {
  76. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  77. if (specialFeaturesChanged)
  78. {
  79. hasChanges = true;
  80. }
  81. }
  82. return hasChanges;
  83. }
  84. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  85. {
  86. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  87. var newItemIds = newItems.Select(i => i.Id).ToList();
  88. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  89. var tasks = newItems.Select(i => RefreshMetadataForOwnedItem(i, false, options, cancellationToken));
  90. await Task.WhenAll(tasks).ConfigureAwait(false);
  91. SpecialFeatureIds = newItemIds;
  92. return itemsChanged;
  93. }
  94. public override UnratedItem GetBlockUnratedType()
  95. {
  96. return UnratedItem.Movie;
  97. }
  98. public MovieInfo GetLookupInfo()
  99. {
  100. var info = GetItemLookupInfo<MovieInfo>();
  101. if (!DetectIsInMixedFolder())
  102. {
  103. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  104. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  105. {
  106. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  107. {
  108. // if the folder has the file extension, strip it
  109. name = System.IO.Path.GetFileNameWithoutExtension(name);
  110. }
  111. }
  112. info.Name = name;
  113. }
  114. return info;
  115. }
  116. public override bool BeforeMetadataRefresh()
  117. {
  118. var hasChanges = base.BeforeMetadataRefresh();
  119. if (!ProductionYear.HasValue)
  120. {
  121. var info = LibraryManager.ParseName(Name);
  122. var yearInName = info.Year;
  123. if (yearInName.HasValue)
  124. {
  125. ProductionYear = yearInName;
  126. hasChanges = true;
  127. }
  128. else
  129. {
  130. // Try to get the year from the folder name
  131. if (!DetectIsInMixedFolder())
  132. {
  133. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  134. yearInName = info.Year;
  135. if (yearInName.HasValue)
  136. {
  137. ProductionYear = yearInName;
  138. hasChanges = true;
  139. }
  140. }
  141. }
  142. }
  143. return hasChanges;
  144. }
  145. public override List<ExternalUrl> GetRelatedUrls()
  146. {
  147. var list = base.GetRelatedUrls();
  148. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  149. if (!string.IsNullOrWhiteSpace(imdbId))
  150. {
  151. list.Add(new ExternalUrl
  152. {
  153. Name = "Trakt",
  154. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  155. });
  156. }
  157. return list;
  158. }
  159. [IgnoreDataMember]
  160. public override bool StopRefreshIfLocalMetadataFound
  161. {
  162. get
  163. {
  164. // Need people id's from internet metadata
  165. return false;
  166. }
  167. }
  168. }
  169. }