Trailer.cs 3.8 KB

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