Trailer.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. protected override string CreateUserDataKey()
  52. {
  53. var key = Movie.GetMovieUserDataKey(this);
  54. if (!string.IsNullOrWhiteSpace(key))
  55. {
  56. key = key + "-trailer";
  57. // Make sure different trailers have their own data.
  58. if (RunTimeTicks.HasValue)
  59. {
  60. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  61. }
  62. return key;
  63. }
  64. return base.CreateUserDataKey();
  65. }
  66. public override UnratedItem GetBlockUnratedType()
  67. {
  68. return UnratedItem.Trailer;
  69. }
  70. public TrailerInfo GetLookupInfo()
  71. {
  72. var info = GetItemLookupInfo<TrailerInfo>();
  73. info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer);
  74. if (!IsInMixedFolder)
  75. {
  76. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  77. }
  78. return info;
  79. }
  80. public override bool BeforeMetadataRefresh()
  81. {
  82. var hasChanges = base.BeforeMetadataRefresh();
  83. if (!ProductionYear.HasValue)
  84. {
  85. var info = LibraryManager.ParseName(Name);
  86. var yearInName = info.Year;
  87. if (yearInName.HasValue)
  88. {
  89. ProductionYear = yearInName;
  90. hasChanges = true;
  91. }
  92. else
  93. {
  94. // Try to get the year from the folder name
  95. if (!IsInMixedFolder)
  96. {
  97. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  98. yearInName = info.Year;
  99. if (yearInName.HasValue)
  100. {
  101. ProductionYear = yearInName;
  102. hasChanges = true;
  103. }
  104. }
  105. }
  106. }
  107. return hasChanges;
  108. }
  109. }
  110. }