Movie.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text.Json.Serialization;
  8. using Jellyfin.Data.Enums;
  9. using MediaBrowser.Controller.Providers;
  10. using MediaBrowser.Model.Entities;
  11. using MediaBrowser.Model.Providers;
  12. namespace MediaBrowser.Controller.Entities.Movies
  13. {
  14. /// <summary>
  15. /// Class Movie.
  16. /// </summary>
  17. public class Movie : Video, IHasSpecialFeatures, IHasTrailers, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
  18. {
  19. /// <inheritdoc />
  20. [JsonIgnore]
  21. public IReadOnlyList<Guid> SpecialFeatureIds => GetExtras()
  22. .Where(extra => extra.ExtraType is not null && extra is Video)
  23. .Select(extra => extra.Id)
  24. .ToArray();
  25. /// <inheritdoc />
  26. [JsonIgnore]
  27. public IReadOnlyList<BaseItem> LocalTrailers => GetExtras()
  28. .Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer)
  29. .ToArray();
  30. /// <summary>
  31. /// Gets or sets the name of the TMDb collection.
  32. /// </summary>
  33. /// <value>The name of the TMDb collection.</value>
  34. public string TmdbCollectionName { get; set; }
  35. [JsonIgnore]
  36. public string CollectionName
  37. {
  38. get => TmdbCollectionName;
  39. set => TmdbCollectionName = value;
  40. }
  41. public override double GetDefaultPrimaryImageAspectRatio()
  42. {
  43. // hack for tv plugins
  44. if (SourceType == SourceType.Channel)
  45. {
  46. return 0;
  47. }
  48. return 2.0 / 3;
  49. }
  50. /// <inheritdoc />
  51. public override UnratedItem GetBlockUnratedType()
  52. {
  53. return UnratedItem.Movie;
  54. }
  55. public MovieInfo GetLookupInfo()
  56. {
  57. var info = GetItemLookupInfo<MovieInfo>();
  58. if (!IsInMixedFolder)
  59. {
  60. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  61. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  62. {
  63. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  64. {
  65. // if the folder has the file extension, strip it
  66. name = System.IO.Path.GetFileNameWithoutExtension(name);
  67. }
  68. }
  69. info.Name = name;
  70. }
  71. return info;
  72. }
  73. /// <inheritdoc />
  74. public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
  75. {
  76. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
  77. if (!ProductionYear.HasValue)
  78. {
  79. var info = LibraryManager.ParseName(Name);
  80. var yearInName = info.Year;
  81. if (yearInName.HasValue)
  82. {
  83. ProductionYear = yearInName;
  84. hasChanges = true;
  85. }
  86. else
  87. {
  88. // Try to get the year from the folder name
  89. if (!IsInMixedFolder)
  90. {
  91. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  92. yearInName = info.Year;
  93. if (yearInName.HasValue)
  94. {
  95. ProductionYear = yearInName;
  96. hasChanges = true;
  97. }
  98. }
  99. }
  100. }
  101. return hasChanges;
  102. }
  103. }
  104. }