Movie.cs 6.1 KB

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