Movie.cs 6.0 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.Threading;
  8. using System.Threading.Tasks;
  9. using MediaBrowser.Controller.IO;
  10. using MediaBrowser.Model.IO;
  11. using MediaBrowser.Model.Providers;
  12. using MediaBrowser.Model.Serialization;
  13. namespace MediaBrowser.Controller.Entities.Movies
  14. {
  15. /// <summary>
  16. /// Class Movie
  17. /// </summary>
  18. public class Movie : Video, IHasSpecialFeatures, IHasTrailers, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
  19. {
  20. public List<Guid> SpecialFeatureIds { get; set; }
  21. public Movie()
  22. {
  23. SpecialFeatureIds = new List<Guid>();
  24. RemoteTrailers = new List<MediaUrl>();
  25. LocalTrailerIds = new List<Guid>();
  26. RemoteTrailerIds = new List<Guid>();
  27. }
  28. public List<Guid> LocalTrailerIds { get; set; }
  29. public List<Guid> RemoteTrailerIds { get; set; }
  30. public List<MediaUrl> RemoteTrailers { get; set; }
  31. /// <summary>
  32. /// Gets or sets the name of the TMDB collection.
  33. /// </summary>
  34. /// <value>The name of the TMDB collection.</value>
  35. public string TmdbCollectionName { get; set; }
  36. [IgnoreDataMember]
  37. public string CollectionName
  38. {
  39. get { return TmdbCollectionName; }
  40. set { TmdbCollectionName = value; }
  41. }
  42. public override double? GetDefaultPrimaryImageAspectRatio()
  43. {
  44. double value = 2;
  45. value /= 3;
  46. return value;
  47. }
  48. [IgnoreDataMember]
  49. protected override bool SupportsIsInMixedFolderDetection
  50. {
  51. get
  52. {
  53. return false;
  54. }
  55. }
  56. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  57. {
  58. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  59. // Must have a parent to have special features
  60. // In other words, it must be part of the Parent/Child tree
  61. if (LocationType == LocationType.FileSystem && GetParent() != null && !DetectIsInMixedFolder())
  62. {
  63. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  64. if (specialFeaturesChanged)
  65. {
  66. hasChanges = true;
  67. }
  68. }
  69. return hasChanges;
  70. }
  71. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  72. {
  73. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  74. var newItemIds = newItems.Select(i => i.Id).ToList();
  75. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  76. var tasks = newItems.Select(i => RefreshMetadataForOwnedItem(i, false, options, cancellationToken));
  77. await Task.WhenAll(tasks).ConfigureAwait(false);
  78. SpecialFeatureIds = newItemIds;
  79. return itemsChanged;
  80. }
  81. public override UnratedItem GetBlockUnratedType()
  82. {
  83. return UnratedItem.Movie;
  84. }
  85. public MovieInfo GetLookupInfo()
  86. {
  87. var info = GetItemLookupInfo<MovieInfo>();
  88. if (!DetectIsInMixedFolder())
  89. {
  90. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  91. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  92. {
  93. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  94. {
  95. // if the folder has the file extension, strip it
  96. name = System.IO.Path.GetFileNameWithoutExtension(name);
  97. }
  98. }
  99. info.Name = name;
  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 (!DetectIsInMixedFolder())
  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. }