Trailer.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. public TrailerType[] TrailerTypes { get; set; }
  23. public override double GetDefaultPrimaryImageAspectRatio()
  24. => 2.0 / 3;
  25. public override UnratedItem GetBlockUnratedType()
  26. {
  27. return UnratedItem.Trailer;
  28. }
  29. public TrailerInfo GetLookupInfo()
  30. {
  31. var info = GetItemLookupInfo<TrailerInfo>();
  32. if (!IsInMixedFolder && IsFileProtocol)
  33. {
  34. info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
  35. }
  36. return info;
  37. }
  38. public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
  39. {
  40. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
  41. if (!ProductionYear.HasValue)
  42. {
  43. var info = LibraryManager.ParseName(Name);
  44. var yearInName = info.Year;
  45. if (yearInName.HasValue)
  46. {
  47. ProductionYear = yearInName;
  48. hasChanges = true;
  49. }
  50. else
  51. {
  52. // Try to get the year from the folder name
  53. if (!IsInMixedFolder)
  54. {
  55. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  56. yearInName = info.Year;
  57. if (yearInName.HasValue)
  58. {
  59. ProductionYear = yearInName;
  60. hasChanges = true;
  61. }
  62. }
  63. }
  64. }
  65. return hasChanges;
  66. }
  67. }
  68. }