Trailer.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.Json.Serialization;
  4. using MediaBrowser.Controller.Providers;
  5. using MediaBrowser.Model.Configuration;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.Providers;
  8. namespace MediaBrowser.Controller.Entities
  9. {
  10. /// <summary>
  11. /// Class Trailer
  12. /// </summary>
  13. public class Trailer : Video, IHasLookupInfo<TrailerInfo>
  14. {
  15. public Trailer()
  16. {
  17. TrailerTypes = Array.Empty<TrailerType>();
  18. }
  19. public TrailerType[] TrailerTypes { get; set; }
  20. public override double GetDefaultPrimaryImageAspectRatio()
  21. => 2.0 / 3;
  22. public override UnratedItem GetBlockUnratedType()
  23. {
  24. return UnratedItem.Trailer;
  25. }
  26. public TrailerInfo GetLookupInfo()
  27. {
  28. var info = GetItemLookupInfo<TrailerInfo>();
  29. if (!IsInMixedFolder && IsFileProtocol)
  30. {
  31. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  32. }
  33. return info;
  34. }
  35. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  36. {
  37. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  38. if (!ProductionYear.HasValue)
  39. {
  40. var info = LibraryManager.ParseName(Name);
  41. var yearInName = info.Year;
  42. if (yearInName.HasValue)
  43. {
  44. ProductionYear = yearInName;
  45. hasChanges = true;
  46. }
  47. else
  48. {
  49. // Try to get the year from the folder name
  50. if (!IsInMixedFolder)
  51. {
  52. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  53. yearInName = info.Year;
  54. if (yearInName.HasValue)
  55. {
  56. ProductionYear = yearInName;
  57. hasChanges = true;
  58. }
  59. }
  60. }
  61. }
  62. return hasChanges;
  63. }
  64. public override List<ExternalUrl> GetRelatedUrls()
  65. {
  66. var list = base.GetRelatedUrls();
  67. var imdbId = this.GetProviderId(MetadataProviders.Imdb);
  68. if (!string.IsNullOrEmpty(imdbId))
  69. {
  70. list.Add(new ExternalUrl
  71. {
  72. Name = "Trakt",
  73. Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
  74. });
  75. }
  76. return list;
  77. }
  78. [JsonIgnore]
  79. public override bool StopRefreshIfLocalMetadataFound => false;
  80. }
  81. }