Trailer.cs 2.8 KB

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