Movie.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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, 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 name of the TMDB collection.
  42. /// </summary>
  43. /// <value>The name of the TMDB collection.</value>
  44. public string TmdbCollectionName { get; set; }
  45. [IgnoreDataMember]
  46. public string CollectionName
  47. {
  48. get { return TmdbCollectionName; }
  49. set { TmdbCollectionName = value; }
  50. }
  51. public override double? GetDefaultPrimaryImageAspectRatio()
  52. {
  53. double value = 2;
  54. value /= 3;
  55. return value;
  56. }
  57. [IgnoreDataMember]
  58. protected override bool SupportsIsInMixedFolderDetection
  59. {
  60. get
  61. {
  62. return false;
  63. }
  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 && !DetectIsInMixedFolder())
  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 => RefreshMetadataForOwnedItem(i, false, 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 (!DetectIsInMixedFolder())
  98. {
  99. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  100. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  101. {
  102. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  103. {
  104. // if the folder has the file extension, strip it
  105. name = System.IO.Path.GetFileNameWithoutExtension(name);
  106. }
  107. }
  108. info.Name = name;
  109. }
  110. return info;
  111. }
  112. public override bool BeforeMetadataRefresh()
  113. {
  114. var hasChanges = base.BeforeMetadataRefresh();
  115. if (!ProductionYear.HasValue)
  116. {
  117. var info = LibraryManager.ParseName(Name);
  118. var yearInName = info.Year;
  119. if (yearInName.HasValue)
  120. {
  121. ProductionYear = yearInName;
  122. hasChanges = true;
  123. }
  124. else
  125. {
  126. // Try to get the year from the folder name
  127. if (!DetectIsInMixedFolder())
  128. {
  129. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  130. yearInName = info.Year;
  131. if (yearInName.HasValue)
  132. {
  133. ProductionYear = yearInName;
  134. hasChanges = true;
  135. }
  136. }
  137. }
  138. }
  139. return hasChanges;
  140. }
  141. public override List<ExternalUrl> GetRelatedUrls()
  142. {
  143. var list = base.GetRelatedUrls();
  144. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  145. if (!string.IsNullOrWhiteSpace(imdbId))
  146. {
  147. list.Add(new ExternalUrl
  148. {
  149. Name = "Trakt",
  150. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  151. });
  152. }
  153. return list;
  154. }
  155. [IgnoreDataMember]
  156. public override bool StopRefreshIfLocalMetadataFound
  157. {
  158. get
  159. {
  160. // Need people id's from internet metadata
  161. return false;
  162. }
  163. }
  164. }
  165. }