Trailer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, 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. [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. public override UnratedItem GetBlockUnratedType()
  49. {
  50. return UnratedItem.Trailer;
  51. }
  52. public TrailerInfo GetLookupInfo()
  53. {
  54. var info = GetItemLookupInfo<TrailerInfo>();
  55. info.IsLocalTrailer = TrailerTypes.Contains(TrailerType.LocalTrailer);
  56. if (!IsInMixedFolder)
  57. {
  58. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  59. }
  60. return info;
  61. }
  62. public override bool BeforeMetadataRefresh()
  63. {
  64. var hasChanges = base.BeforeMetadataRefresh();
  65. if (!ProductionYear.HasValue)
  66. {
  67. var info = LibraryManager.ParseName(Name);
  68. var yearInName = info.Year;
  69. if (yearInName.HasValue)
  70. {
  71. ProductionYear = yearInName;
  72. hasChanges = true;
  73. }
  74. else
  75. {
  76. // Try to get the year from the folder name
  77. if (!IsInMixedFolder)
  78. {
  79. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  80. yearInName = info.Year;
  81. if (yearInName.HasValue)
  82. {
  83. ProductionYear = yearInName;
  84. hasChanges = true;
  85. }
  86. }
  87. }
  88. }
  89. return hasChanges;
  90. }
  91. public override List<ExternalUrl> GetRelatedUrls()
  92. {
  93. var list = base.GetRelatedUrls();
  94. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  95. if (!string.IsNullOrWhiteSpace(imdbId))
  96. {
  97. list.Add(new ExternalUrl
  98. {
  99. Name = "Trakt",
  100. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  101. });
  102. }
  103. return list;
  104. }
  105. }
  106. }