Movie.cs 6.2 KB

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