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