Trailer.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /// <summary>
  32. /// Gets or sets the taglines.
  33. /// </summary>
  34. /// <value>The taglines.</value>
  35. public List<string> Taglines { get; set; }
  36. /// <summary>
  37. /// Gets or sets the budget.
  38. /// </summary>
  39. /// <value>The budget.</value>
  40. public double? Budget { get; set; }
  41. /// <summary>
  42. /// Gets or sets the revenue.
  43. /// </summary>
  44. /// <value>The revenue.</value>
  45. public double? Revenue { get; set; }
  46. /// <summary>
  47. /// Gets or sets the critic rating.
  48. /// </summary>
  49. /// <value>The critic rating.</value>
  50. public float? CriticRating { get; set; }
  51. /// <summary>
  52. /// Gets or sets the critic rating summary.
  53. /// </summary>
  54. /// <value>The critic rating summary.</value>
  55. public string CriticRatingSummary { get; set; }
  56. protected override string CreateUserDataKey()
  57. {
  58. var key = Movie.GetMovieUserDataKey(this);
  59. if (!string.IsNullOrWhiteSpace(key))
  60. {
  61. key = key + "-trailer";
  62. // Make sure different trailers have their own data.
  63. if (RunTimeTicks.HasValue)
  64. {
  65. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  66. }
  67. return key;
  68. }
  69. return base.CreateUserDataKey();
  70. }
  71. public override UnratedItem GetBlockUnratedType()
  72. {
  73. return UnratedItem.Trailer;
  74. }
  75. public TrailerInfo GetLookupInfo()
  76. {
  77. var info = GetItemLookupInfo<TrailerInfo>();
  78. info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer);
  79. if (!IsInMixedFolder)
  80. {
  81. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  82. }
  83. return info;
  84. }
  85. public override bool BeforeMetadataRefresh()
  86. {
  87. var hasChanges = base.BeforeMetadataRefresh();
  88. if (!ProductionYear.HasValue)
  89. {
  90. var info = LibraryManager.ParseName(Name);
  91. var yearInName = info.Year;
  92. if (yearInName.HasValue)
  93. {
  94. ProductionYear = yearInName;
  95. hasChanges = true;
  96. }
  97. else
  98. {
  99. // Try to get the year from the folder name
  100. if (!IsInMixedFolder)
  101. {
  102. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  103. yearInName = info.Year;
  104. if (yearInName.HasValue)
  105. {
  106. ProductionYear = yearInName;
  107. hasChanges = true;
  108. }
  109. }
  110. }
  111. }
  112. return hasChanges;
  113. }
  114. }
  115. }