Movie.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Guid[] SpecialFeatureIds { get; set; }
  21. public Movie()
  22. {
  23. SpecialFeatureIds = EmptyGuidArray;
  24. RemoteTrailers = EmptyMediaUrlArray;
  25. LocalTrailerIds = EmptyGuidArray;
  26. RemoteTrailerIds = EmptyGuidArray;
  27. }
  28. public Guid[] LocalTrailerIds { get; set; }
  29. public Guid[] RemoteTrailerIds { get; set; }
  30. public 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. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  49. {
  50. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  51. // Must have a parent to have special features
  52. // In other words, it must be part of the Parent/Child tree
  53. if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
  54. {
  55. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  56. if (specialFeaturesChanged)
  57. {
  58. hasChanges = true;
  59. }
  60. }
  61. return hasChanges;
  62. }
  63. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  64. {
  65. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  66. var newItemIds = newItems.Select(i => i.Id).ToArray();
  67. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  68. var ownerId = Id;
  69. var tasks = newItems.Select(i =>
  70. {
  71. var subOptions = new MetadataRefreshOptions(options);
  72. if (i.OwnerId != ownerId)
  73. {
  74. i.OwnerId = ownerId;
  75. subOptions.ForceSave = true;
  76. }
  77. return RefreshMetadataForOwnedItem(i, false, subOptions, cancellationToken);
  78. });
  79. await Task.WhenAll(tasks).ConfigureAwait(false);
  80. SpecialFeatureIds = newItemIds;
  81. return itemsChanged;
  82. }
  83. public override UnratedItem GetBlockUnratedType()
  84. {
  85. return UnratedItem.Movie;
  86. }
  87. public MovieInfo GetLookupInfo()
  88. {
  89. var info = GetItemLookupInfo<MovieInfo>();
  90. if (!IsInMixedFolder)
  91. {
  92. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  93. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  94. {
  95. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  96. {
  97. // if the folder has the file extension, strip it
  98. name = System.IO.Path.GetFileNameWithoutExtension(name);
  99. }
  100. }
  101. info.Name = name;
  102. }
  103. return info;
  104. }
  105. public override bool BeforeMetadataRefresh()
  106. {
  107. var hasChanges = base.BeforeMetadataRefresh();
  108. if (!ProductionYear.HasValue)
  109. {
  110. var info = LibraryManager.ParseName(Name);
  111. var yearInName = info.Year;
  112. if (yearInName.HasValue)
  113. {
  114. ProductionYear = yearInName;
  115. hasChanges = true;
  116. }
  117. else
  118. {
  119. // Try to get the year from the folder name
  120. if (!IsInMixedFolder)
  121. {
  122. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  123. yearInName = info.Year;
  124. if (yearInName.HasValue)
  125. {
  126. ProductionYear = yearInName;
  127. hasChanges = true;
  128. }
  129. }
  130. }
  131. }
  132. return hasChanges;
  133. }
  134. public override List<ExternalUrl> GetRelatedUrls()
  135. {
  136. var list = base.GetRelatedUrls();
  137. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  138. if (!string.IsNullOrWhiteSpace(imdbId))
  139. {
  140. list.Add(new ExternalUrl
  141. {
  142. Name = "Trakt",
  143. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  144. });
  145. }
  146. return list;
  147. }
  148. [IgnoreDataMember]
  149. public override bool StopRefreshIfLocalMetadataFound
  150. {
  151. get
  152. {
  153. // Need people id's from internet metadata
  154. return false;
  155. }
  156. }
  157. }
  158. }