Movie.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 tasks = newItems.Select(i => RefreshMetadataForOwnedItem(i, false, options, cancellationToken));
  69. await Task.WhenAll(tasks).ConfigureAwait(false);
  70. SpecialFeatureIds = newItemIds;
  71. return itemsChanged;
  72. }
  73. public override UnratedItem GetBlockUnratedType()
  74. {
  75. return UnratedItem.Movie;
  76. }
  77. public MovieInfo GetLookupInfo()
  78. {
  79. var info = GetItemLookupInfo<MovieInfo>();
  80. if (!IsInMixedFolder)
  81. {
  82. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  83. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  84. {
  85. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  86. {
  87. // if the folder has the file extension, strip it
  88. name = System.IO.Path.GetFileNameWithoutExtension(name);
  89. }
  90. }
  91. info.Name = name;
  92. }
  93. return info;
  94. }
  95. public override bool BeforeMetadataRefresh()
  96. {
  97. var hasChanges = base.BeforeMetadataRefresh();
  98. if (!ProductionYear.HasValue)
  99. {
  100. var info = LibraryManager.ParseName(Name);
  101. var yearInName = info.Year;
  102. if (yearInName.HasValue)
  103. {
  104. ProductionYear = yearInName;
  105. hasChanges = true;
  106. }
  107. else
  108. {
  109. // Try to get the year from the folder name
  110. if (!IsInMixedFolder)
  111. {
  112. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  113. yearInName = info.Year;
  114. if (yearInName.HasValue)
  115. {
  116. ProductionYear = yearInName;
  117. hasChanges = true;
  118. }
  119. }
  120. }
  121. }
  122. return hasChanges;
  123. }
  124. public override List<ExternalUrl> GetRelatedUrls()
  125. {
  126. var list = base.GetRelatedUrls();
  127. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  128. if (!string.IsNullOrWhiteSpace(imdbId))
  129. {
  130. list.Add(new ExternalUrl
  131. {
  132. Name = "Trakt",
  133. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  134. });
  135. }
  136. return list;
  137. }
  138. [IgnoreDataMember]
  139. public override bool StopRefreshIfLocalMetadataFound
  140. {
  141. get
  142. {
  143. // Need people id's from internet metadata
  144. return false;
  145. }
  146. }
  147. }
  148. }