Movie.cs 6.2 KB

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