Movie.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.Runtime.Serialization;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using CommonIO;
  11. namespace MediaBrowser.Controller.Entities.Movies
  12. {
  13. /// <summary>
  14. /// Class Movie
  15. /// </summary>
  16. public class Movie : Video, IHasCriticRating, IHasSpecialFeatures, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping, IHasOriginalTitle
  17. {
  18. public List<Guid> SpecialFeatureIds { get; set; }
  19. public List<Guid> ThemeSongIds { get; set; }
  20. public List<Guid> ThemeVideoIds { get; set; }
  21. public List<string> ProductionLocations { get; set; }
  22. public Movie()
  23. {
  24. SpecialFeatureIds = new List<Guid>();
  25. RemoteTrailers = new List<MediaUrl>();
  26. LocalTrailerIds = new List<Guid>();
  27. RemoteTrailerIds = new List<Guid>();
  28. ThemeSongIds = new List<Guid>();
  29. ThemeVideoIds = new List<Guid>();
  30. Taglines = new List<string>();
  31. Keywords = new List<string>();
  32. ProductionLocations = new List<string>();
  33. }
  34. public string AwardSummary { get; set; }
  35. public float? Metascore { get; set; }
  36. public List<Guid> LocalTrailerIds { get; set; }
  37. public List<Guid> RemoteTrailerIds { get; set; }
  38. public List<string> Keywords { get; set; }
  39. public List<MediaUrl> RemoteTrailers { get; set; }
  40. /// <summary>
  41. /// Gets or sets the taglines.
  42. /// </summary>
  43. /// <value>The taglines.</value>
  44. public List<string> Taglines { get; set; }
  45. /// <summary>
  46. /// Gets or sets the budget.
  47. /// </summary>
  48. /// <value>The budget.</value>
  49. public double? Budget { get; set; }
  50. /// <summary>
  51. /// Gets or sets the revenue.
  52. /// </summary>
  53. /// <value>The revenue.</value>
  54. public double? Revenue { get; set; }
  55. /// <summary>
  56. /// Gets or sets the name of the TMDB collection.
  57. /// </summary>
  58. /// <value>The name of the TMDB collection.</value>
  59. public string TmdbCollectionName { get; set; }
  60. [IgnoreDataMember]
  61. public string CollectionName
  62. {
  63. get { return TmdbCollectionName; }
  64. set { TmdbCollectionName = value; }
  65. }
  66. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  67. {
  68. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  69. // Must have a parent to have special features
  70. // In other words, it must be part of the Parent/Child tree
  71. if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
  72. {
  73. var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  74. if (specialFeaturesChanged)
  75. {
  76. hasChanges = true;
  77. }
  78. }
  79. return hasChanges;
  80. }
  81. private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  82. {
  83. var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
  84. var newItemIds = newItems.Select(i => i.Id).ToList();
  85. var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
  86. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  87. await Task.WhenAll(tasks).ConfigureAwait(false);
  88. SpecialFeatureIds = newItemIds;
  89. return itemsChanged;
  90. }
  91. public override UnratedItem GetBlockUnratedType()
  92. {
  93. return UnratedItem.Movie;
  94. }
  95. public MovieInfo GetLookupInfo()
  96. {
  97. var info = GetItemLookupInfo<MovieInfo>();
  98. if (!IsInMixedFolder)
  99. {
  100. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  101. }
  102. return info;
  103. }
  104. public override bool BeforeMetadataRefresh()
  105. {
  106. var hasChanges = base.BeforeMetadataRefresh();
  107. if (!ProductionYear.HasValue)
  108. {
  109. var info = LibraryManager.ParseName(Name);
  110. var yearInName = info.Year;
  111. if (yearInName.HasValue)
  112. {
  113. ProductionYear = yearInName;
  114. hasChanges = true;
  115. }
  116. else
  117. {
  118. // Try to get the year from the folder name
  119. if (!IsInMixedFolder)
  120. {
  121. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  122. yearInName = info.Year;
  123. if (yearInName.HasValue)
  124. {
  125. ProductionYear = yearInName;
  126. hasChanges = true;
  127. }
  128. }
  129. }
  130. }
  131. return hasChanges;
  132. }
  133. }
  134. }