Movie.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 != 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. [JsonIgnore]
  42. public override bool StopRefreshIfLocalMetadataFound => false;
  43. public override double GetDefaultPrimaryImageAspectRatio()
  44. {
  45. // hack for tv plugins
  46. if (SourceType == SourceType.Channel)
  47. {
  48. return 0;
  49. }
  50. return 2.0 / 3;
  51. }
  52. /// <inheritdoc />
  53. public override UnratedItem GetBlockUnratedType()
  54. {
  55. return UnratedItem.Movie;
  56. }
  57. public MovieInfo GetLookupInfo()
  58. {
  59. var info = GetItemLookupInfo<MovieInfo>();
  60. if (!IsInMixedFolder)
  61. {
  62. var name = System.IO.Path.GetFileName(ContainingFolderPath);
  63. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  64. {
  65. if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
  66. {
  67. // if the folder has the file extension, strip it
  68. name = System.IO.Path.GetFileNameWithoutExtension(name);
  69. }
  70. }
  71. info.Name = name;
  72. }
  73. return info;
  74. }
  75. /// <inheritdoc />
  76. public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
  77. {
  78. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
  79. if (!ProductionYear.HasValue)
  80. {
  81. var info = LibraryManager.ParseName(Name);
  82. var yearInName = info.Year;
  83. if (yearInName.HasValue)
  84. {
  85. ProductionYear = yearInName;
  86. hasChanges = true;
  87. }
  88. else
  89. {
  90. // Try to get the year from the folder name
  91. if (!IsInMixedFolder)
  92. {
  93. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  94. yearInName = info.Year;
  95. if (yearInName.HasValue)
  96. {
  97. ProductionYear = yearInName;
  98. hasChanges = true;
  99. }
  100. }
  101. }
  102. }
  103. return hasChanges;
  104. }
  105. /// <inheritdoc />
  106. public override List<ExternalUrl> GetRelatedUrls()
  107. {
  108. var list = base.GetRelatedUrls();
  109. var imdbId = this.GetProviderId(MetadataProvider.Imdb);
  110. if (!string.IsNullOrEmpty(imdbId))
  111. {
  112. list.Add(new ExternalUrl
  113. {
  114. Name = "Trakt",
  115. Url = string.Format(CultureInfo.InvariantCulture, "https://trakt.tv/movies/{0}", imdbId)
  116. });
  117. }
  118. return list;
  119. }
  120. }
  121. }