Movie.cs 5.8 KB

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