Trailer.cs 2.8 KB

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