Trailer.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Configuration;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Users;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using MediaBrowser.Controller.Entities.Movies;
  11. namespace MediaBrowser.Controller.Entities
  12. {
  13. /// <summary>
  14. /// Class Trailer
  15. /// </summary>
  16. public class Trailer : Video, IHasCriticRating, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTaglines, IHasMetascore, IHasLookupInfo<TrailerInfo>
  17. {
  18. public List<string> ProductionLocations { get; set; }
  19. public Trailer()
  20. {
  21. RemoteTrailers = new List<MediaUrl>();
  22. Taglines = new List<string>();
  23. Keywords = new List<string>();
  24. ProductionLocations = new List<string>();
  25. TrailerTypes = new List<TrailerType>();
  26. }
  27. public List<TrailerType> TrailerTypes { get; set; }
  28. public float? Metascore { get; set; }
  29. public List<MediaUrl> RemoteTrailers { get; set; }
  30. public List<string> Keywords { get; set; }
  31. [IgnoreDataMember]
  32. public bool IsLocalTrailer
  33. {
  34. get { return TrailerTypes.Contains(TrailerType.LocalTrailer); }
  35. }
  36. /// <summary>
  37. /// Gets or sets the taglines.
  38. /// </summary>
  39. /// <value>The taglines.</value>
  40. public List<string> Taglines { get; set; }
  41. /// <summary>
  42. /// Gets or sets the budget.
  43. /// </summary>
  44. /// <value>The budget.</value>
  45. public double? Budget { get; set; }
  46. /// <summary>
  47. /// Gets or sets the revenue.
  48. /// </summary>
  49. /// <value>The revenue.</value>
  50. public double? Revenue { get; set; }
  51. /// <summary>
  52. /// Gets or sets the critic rating.
  53. /// </summary>
  54. /// <value>The critic rating.</value>
  55. public float? CriticRating { get; set; }
  56. /// <summary>
  57. /// Gets or sets the critic rating summary.
  58. /// </summary>
  59. /// <value>The critic rating summary.</value>
  60. public string CriticRatingSummary { get; set; }
  61. protected override string CreateUserDataKey()
  62. {
  63. var key = Movie.GetMovieUserDataKey(this);
  64. if (!string.IsNullOrWhiteSpace(key))
  65. {
  66. key = key + "-trailer";
  67. // Make sure different trailers have their own data.
  68. if (RunTimeTicks.HasValue)
  69. {
  70. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  71. }
  72. return key;
  73. }
  74. return base.CreateUserDataKey();
  75. }
  76. public override UnratedItem GetBlockUnratedType()
  77. {
  78. return UnratedItem.Trailer;
  79. }
  80. public TrailerInfo GetLookupInfo()
  81. {
  82. var info = GetItemLookupInfo<TrailerInfo>();
  83. info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer);
  84. if (!IsInMixedFolder)
  85. {
  86. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  87. }
  88. return info;
  89. }
  90. public override bool BeforeMetadataRefresh()
  91. {
  92. var hasChanges = base.BeforeMetadataRefresh();
  93. if (!ProductionYear.HasValue)
  94. {
  95. var info = LibraryManager.ParseName(Name);
  96. var yearInName = info.Year;
  97. if (yearInName.HasValue)
  98. {
  99. ProductionYear = yearInName;
  100. hasChanges = true;
  101. }
  102. else
  103. {
  104. // Try to get the year from the folder name
  105. if (!IsInMixedFolder)
  106. {
  107. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  108. yearInName = info.Year;
  109. if (yearInName.HasValue)
  110. {
  111. ProductionYear = yearInName;
  112. hasChanges = true;
  113. }
  114. }
  115. }
  116. }
  117. return hasChanges;
  118. }
  119. }
  120. }