Trailer.cs 2.8 KB

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