Trailer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. using MediaBrowser.Model.Providers;
  9. namespace MediaBrowser.Controller.Entities
  10. {
  11. /// <summary>
  12. /// Class Trailer
  13. /// </summary>
  14. public class Trailer : Video, IHasCriticRating, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTaglines, IHasMetascore, IHasOriginalTitle, IHasLookupInfo<TrailerInfo>
  15. {
  16. public List<string> ProductionLocations { get; set; }
  17. public Trailer()
  18. {
  19. RemoteTrailers = new List<MediaUrl>();
  20. Taglines = new List<string>();
  21. Keywords = new List<string>();
  22. ProductionLocations = new List<string>();
  23. TrailerTypes = new List<TrailerType> { TrailerType.LocalTrailer };
  24. }
  25. public List<TrailerType> TrailerTypes { get; set; }
  26. public float? Metascore { get; set; }
  27. public List<MediaUrl> RemoteTrailers { get; set; }
  28. public List<string> Keywords { get; set; }
  29. [IgnoreDataMember]
  30. public bool IsLocalTrailer
  31. {
  32. get { return TrailerTypes.Contains(TrailerType.LocalTrailer); }
  33. }
  34. /// <summary>
  35. /// Gets or sets the taglines.
  36. /// </summary>
  37. /// <value>The taglines.</value>
  38. public List<string> Taglines { get; set; }
  39. /// <summary>
  40. /// Gets or sets the budget.
  41. /// </summary>
  42. /// <value>The budget.</value>
  43. public double? Budget { get; set; }
  44. /// <summary>
  45. /// Gets or sets the revenue.
  46. /// </summary>
  47. /// <value>The revenue.</value>
  48. public double? Revenue { get; set; }
  49. public override UnratedItem GetBlockUnratedType()
  50. {
  51. return UnratedItem.Trailer;
  52. }
  53. public TrailerInfo GetLookupInfo()
  54. {
  55. var info = GetItemLookupInfo<TrailerInfo>();
  56. info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer);
  57. if (!IsInMixedFolder)
  58. {
  59. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  60. }
  61. return info;
  62. }
  63. public override bool BeforeMetadataRefresh()
  64. {
  65. var hasChanges = base.BeforeMetadataRefresh();
  66. if (!ProductionYear.HasValue)
  67. {
  68. var info = LibraryManager.ParseName(Name);
  69. var yearInName = info.Year;
  70. if (yearInName.HasValue)
  71. {
  72. ProductionYear = yearInName;
  73. hasChanges = true;
  74. }
  75. else
  76. {
  77. // Try to get the year from the folder name
  78. if (!IsInMixedFolder)
  79. {
  80. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  81. yearInName = info.Year;
  82. if (yearInName.HasValue)
  83. {
  84. ProductionYear = yearInName;
  85. hasChanges = true;
  86. }
  87. }
  88. }
  89. }
  90. return hasChanges;
  91. }
  92. public override List<ExternalUrl> GetRelatedUrls()
  93. {
  94. var list = base.GetRelatedUrls();
  95. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  96. if (!string.IsNullOrWhiteSpace(imdbId))
  97. {
  98. list.Add(new ExternalUrl
  99. {
  100. Name = "Trakt",
  101. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  102. });
  103. }
  104. return list;
  105. }
  106. }
  107. }