diff options
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
| -rw-r--r-- | MediaBrowser.Controller/Entities/BaseItem.cs | 284 |
1 files changed, 75 insertions, 209 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index a268e6d76..d313848fe 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1,15 +1,3 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller.Channels; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Dto; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Persistence; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Library; -using MediaBrowser.Model.Users; using System; using System.Collections.Generic; using System.Globalization; @@ -17,15 +5,27 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Extensions; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.IO; +using MediaBrowser.Model.Library; using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.MediaInfo; +using MediaBrowser.Model.Users; using Microsoft.Extensions.Logging; namespace MediaBrowser.Controller.Entities @@ -108,19 +108,10 @@ namespace MediaBrowser.Controller.Entities public Guid ChannelId { get; set; } [IgnoreDataMember] - public virtual bool SupportsAddingToPlaylist - { - get - { - return false; - } - } + public virtual bool SupportsAddingToPlaylist => false; [IgnoreDataMember] - public virtual bool AlwaysScanInternalMetadataPath - { - get { return false; } - } + public virtual bool AlwaysScanInternalMetadataPath => false; /// <summary> /// Gets a value indicating whether this instance is in mixed folder. @@ -130,31 +121,13 @@ namespace MediaBrowser.Controller.Entities public bool IsInMixedFolder { get; set; } [IgnoreDataMember] - public virtual bool SupportsPlayedStatus - { - get - { - return false; - } - } + public virtual bool SupportsPlayedStatus => false; [IgnoreDataMember] - public virtual bool SupportsPositionTicksResume - { - get - { - return false; - } - } + public virtual bool SupportsPositionTicksResume => false; [IgnoreDataMember] - public virtual bool SupportsRemoteImageDownloading - { - get - { - return true; - } - } + public virtual bool SupportsRemoteImageDownloading => true; private string _name; /// <summary> @@ -164,10 +137,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public virtual string Name { - get - { - return _name; - } + get => _name; set { _name = value; @@ -178,10 +148,7 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public bool IsUnaired - { - get { return PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; } - } + public bool IsUnaired => PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; [IgnoreDataMember] public int? TotalBitrate { get; set; } @@ -189,13 +156,7 @@ namespace MediaBrowser.Controller.Entities public ExtraType? ExtraType { get; set; } [IgnoreDataMember] - public bool IsThemeMedia - { - get - { - return ExtraType.HasValue && (ExtraType.Value == Model.Entities.ExtraType.ThemeSong || ExtraType.Value == Model.Entities.ExtraType.ThemeVideo); - } - } + public bool IsThemeMedia => ExtraType.HasValue && (ExtraType.Value == Model.Entities.ExtraType.ThemeSong || ExtraType.Value == Model.Entities.ExtraType.ThemeVideo); [IgnoreDataMember] public string OriginalTitle { get; set; } @@ -295,13 +256,7 @@ namespace MediaBrowser.Controller.Entities public string ExternalEtag { get; set; } [IgnoreDataMember] - public virtual bool IsHidden - { - get - { - return false; - } - } + public virtual bool IsHidden => false; public BaseItem GetOwner() { @@ -362,22 +317,10 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public bool IsFileProtocol - { - get - { - return IsPathProtocol(MediaProtocol.File); - } - } + public bool IsFileProtocol => IsPathProtocol(MediaProtocol.File); [IgnoreDataMember] - public bool HasPathProtocol - { - get - { - return PathProtocol.HasValue; - } - } + public bool HasPathProtocol => PathProtocol.HasValue; [IgnoreDataMember] public virtual bool SupportsLocalMetadata @@ -408,13 +351,7 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public virtual bool EnableAlphaNumericSorting - { - get - { - return true; - } - } + public virtual bool EnableAlphaNumericSorting => true; private List<Tuple<StringBuilder, bool>> GetSortChunks(string s1) { @@ -430,7 +367,7 @@ namespace MediaBrowser.Controller.Entities } char thisCh = s1[thisMarker]; - StringBuilder thisChunk = new StringBuilder(); + var thisChunk = new StringBuilder(); while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || SortHelper.InChunk(thisCh, thisChunk[0]))) { @@ -455,10 +392,7 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The primary image path.</value> [IgnoreDataMember] - public string PrimaryImagePath - { - get { return this.GetImagePath(ImageType.Primary); } - } + public string PrimaryImagePath => this.GetImagePath(ImageType.Primary); public bool IsMetadataFetcherEnabled(LibraryOptions libraryOptions, string name) { @@ -614,9 +548,9 @@ namespace MediaBrowser.Controller.Entities public static IMediaSourceManager MediaSourceManager { get; set; } /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. + /// Returns a <see cref="string" /> that represents this instance. /// </summary> - /// <returns>A <see cref="System.String" /> that represents this instance.</returns> + /// <returns>A <see cref="string" /> that represents this instance.</returns> public override string ToString() { return Name; @@ -637,13 +571,7 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The type of the media.</value> [IgnoreDataMember] - public virtual string MediaType - { - get - { - return null; - } - } + public virtual string MediaType => null; [IgnoreDataMember] public virtual string[] PhysicalLocations @@ -667,7 +595,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string ForcedSortName { - get { return _forcedSortName; } + get => _forcedSortName; set { _forcedSortName = value; _sortName = null; } } @@ -695,10 +623,7 @@ namespace MediaBrowser.Controller.Entities } return _sortName; } - set - { - _sortName = value; - } + set => _sortName = value; } public string GetInternalMetadataPath() @@ -816,7 +741,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public Folder Parent { - get { return GetParent() as Folder; } + get => GetParent() as Folder; set { @@ -1007,10 +932,7 @@ namespace MediaBrowser.Controller.Entities public int? ParentIndexNumber { get; set; } [IgnoreDataMember] - public virtual bool HasLocalAlternateVersions - { - get { return false; } - } + public virtual bool HasLocalAlternateVersions => false; [IgnoreDataMember] public string OfficialRatingForComparison @@ -1139,7 +1061,7 @@ namespace MediaBrowser.Controller.Entities { if (item == null) { - throw new ArgumentNullException("media"); + throw new ArgumentNullException(nameof(item)); } var protocol = item.PathProtocol; @@ -1426,22 +1348,13 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - protected virtual bool SupportsOwnedItems - { - get { return !ParentId.Equals(Guid.Empty) && IsFileProtocol; } - } + protected virtual bool SupportsOwnedItems => !ParentId.Equals(Guid.Empty) && IsFileProtocol; [IgnoreDataMember] - public virtual bool SupportsPeople - { - get { return false; } - } + public virtual bool SupportsPeople => false; [IgnoreDataMember] - public virtual bool SupportsThemeMedia - { - get { return false; } - } + public virtual bool SupportsThemeMedia => false; /// <summary> /// Refreshes owned items such as trailers, theme videos, special features, etc. @@ -1490,9 +1403,9 @@ namespace MediaBrowser.Controller.Entities private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken) { - var newItems = LibraryManager.FindTrailers(this, fileSystemChildren, options.DirectoryService).ToList(); + var newItems = LibraryManager.FindTrailers(this, fileSystemChildren, options.DirectoryService); - var newItemIds = newItems.Select(i => i.Id).ToArray(); + var newItemIds = newItems.Select(i => i.Id); var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds); var ownerId = item.Id; @@ -1501,8 +1414,7 @@ namespace MediaBrowser.Controller.Entities { var subOptions = new MetadataRefreshOptions(options); - if (!i.ExtraType.HasValue || - i.ExtraType.Value != Model.Entities.ExtraType.Trailer || + if (i.ExtraType != Model.Entities.ExtraType.Trailer || i.OwnerId != ownerId || !i.ParentId.Equals(Guid.Empty)) { @@ -1517,7 +1429,7 @@ namespace MediaBrowser.Controller.Entities await Task.WhenAll(tasks).ConfigureAwait(false); - item.LocalTrailerIds = newItemIds; + item.LocalTrailerIds = newItemIds.ToArray(); return itemsChanged; } @@ -1602,10 +1514,7 @@ namespace MediaBrowser.Controller.Entities public Dictionary<string, string> ProviderIds { get; set; } [IgnoreDataMember] - public virtual Folder LatestItemsIndexContainer - { - get { return null; } - } + public virtual Folder LatestItemsIndexContainer => null; public virtual double GetDefaultPrimaryImageAspectRatio() { @@ -1751,12 +1660,12 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <param name="user">The user.</param> /// <returns><c>true</c> if [is parental allowed] [the specified user]; otherwise, <c>false</c>.</returns> - /// <exception cref="System.ArgumentNullException">user</exception> + /// <exception cref="ArgumentNullException">user</exception> public bool IsParentalAllowed(User user) { if (user == null) { - throw new ArgumentNullException("user"); + throw new ArgumentNullException(nameof(user)); } if (!IsVisibleViaTags(user)) @@ -1901,12 +1810,12 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <param name="user">The user.</param> /// <returns><c>true</c> if the specified user is visible; otherwise, <c>false</c>.</returns> - /// <exception cref="System.ArgumentNullException">user</exception> + /// <exception cref="ArgumentNullException">user</exception> public virtual bool IsVisible(User user) { if (user == null) { - throw new ArgumentNullException("user"); + throw new ArgumentNullException(nameof(user)); } return IsParentalAllowed(user); @@ -1923,10 +1832,7 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public virtual bool SupportsInheritedParentImages - { - get { return false; } - } + public virtual bool SupportsInheritedParentImages => false; protected bool IsVisibleStandaloneInternal(User user, bool checkFolders) { @@ -1969,22 +1875,10 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value><c>true</c> if this instance is folder; otherwise, <c>false</c>.</value> [IgnoreDataMember] - public virtual bool IsFolder - { - get - { - return false; - } - } + public virtual bool IsFolder => false; [IgnoreDataMember] - public virtual bool IsDisplayedAsFolder - { - get - { - return false; - } - } + public virtual bool IsDisplayedAsFolder => false; public virtual string GetClientTypeName() { @@ -2070,24 +1964,18 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public virtual bool EnableRememberingTrackSelections - { - get - { - return true; - } - } + public virtual bool EnableRememberingTrackSelections => true; /// <summary> /// Adds a studio to the item /// </summary> /// <param name="name">The name.</param> - /// <exception cref="System.ArgumentNullException"></exception> + /// <exception cref="ArgumentNullException"></exception> public void AddStudio(string name) { if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } var current = Studios; @@ -2100,8 +1988,8 @@ namespace MediaBrowser.Controller.Entities } else { - var list = - Studios = current.Concat(new [] { name }).ToArray(); + var list = + Studios = current.Concat(new[] { name }).ToArray(); } } } @@ -2115,12 +2003,12 @@ namespace MediaBrowser.Controller.Entities /// Adds a genre to the item /// </summary> /// <param name="name">The name.</param> - /// <exception cref="System.ArgumentNullException"></exception> + /// <exception cref="ArgumentNullException"></exception> public void AddGenre(string name) { if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } var genres = Genres; @@ -2139,14 +2027,14 @@ namespace MediaBrowser.Controller.Entities /// <param name="datePlayed">The date played.</param> /// <param name="resetPosition">if set to <c>true</c> [reset position].</param> /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException"></exception> + /// <exception cref="ArgumentNullException"></exception> public virtual void MarkPlayed(User user, DateTime? datePlayed, bool resetPosition) { if (user == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException(nameof(user)); } var data = UserDataManager.GetUserData(user, this); @@ -2176,12 +2064,12 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <param name="user">The user.</param> /// <returns>Task.</returns> - /// <exception cref="System.ArgumentNullException"></exception> + /// <exception cref="ArgumentNullException"></exception> public virtual void MarkUnplayed(User user) { if (user == null) { - throw new ArgumentNullException(); + throw new ArgumentNullException(nameof(user)); } var data = UserDataManager.GetUserData(user, this); @@ -2215,7 +2103,7 @@ namespace MediaBrowser.Controller.Entities /// <param name="type">The type.</param> /// <param name="imageIndex">Index of the image.</param> /// <returns><c>true</c> if the specified type has image; otherwise, <c>false</c>.</returns> - /// <exception cref="System.ArgumentException">Backdrops should be accessed using Item.Backdrops</exception> + /// <exception cref="ArgumentException">Backdrops should be accessed using Item.Backdrops</exception> public bool HasImage(ImageType type, int imageIndex) { return GetImageInfo(type, imageIndex) != null; @@ -2241,7 +2129,7 @@ namespace MediaBrowser.Controller.Entities else { var currentCount = ImageInfos.Length; - ImageInfos = ImageInfos.Concat(new [] { image }) .ToArray(); + ImageInfos = ImageInfos.Concat(new[] { image }).ToArray(); } } @@ -2256,7 +2144,7 @@ namespace MediaBrowser.Controller.Entities if (image == null) { - ImageInfos = ImageInfos.Concat(new [] { GetImageInfo(file, type) }) .ToArray(); + ImageInfos = ImageInfos.Concat(new[] { GetImageInfo(file, type) }).ToArray(); } else { @@ -2343,9 +2231,9 @@ namespace MediaBrowser.Controller.Entities /// <param name="imageType">Type of the image.</param> /// <param name="imageIndex">Index of the image.</param> /// <returns>System.String.</returns> - /// <exception cref="System.InvalidOperationException"> + /// <exception cref="InvalidOperationException"> /// </exception> - /// <exception cref="System.ArgumentNullException">item</exception> + /// <exception cref="ArgumentNullException">item</exception> public string GetImagePath(ImageType imageType, int imageIndex) { var info = GetImageInfo(imageType, imageIndex); @@ -2405,7 +2293,7 @@ namespace MediaBrowser.Controller.Entities /// <param name="imageType">Type of the image.</param> /// <param name="images">The images.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> - /// <exception cref="System.ArgumentException">Cannot call AddImages with chapter images</exception> + /// <exception cref="ArgumentException">Cannot call AddImages with chapter images</exception> public bool AddImages(ImageType imageType, List<FileSystemMetadata> images) { if (imageType == ImageType.Chapter) @@ -2579,7 +2467,7 @@ namespace MediaBrowser.Controller.Entities { if (user == null) { - throw new ArgumentNullException("user"); + throw new ArgumentNullException(nameof(user)); } var userdata = UserDataManager.GetUserData(user, this); @@ -2813,22 +2701,10 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public virtual bool SupportsAncestors - { - get - { - return true; - } - } + public virtual bool SupportsAncestors => true; [IgnoreDataMember] - public virtual bool StopRefreshIfLocalMetadataFound - { - get - { - return true; - } - } + public virtual bool StopRefreshIfLocalMetadataFound => true; public virtual IEnumerable<Guid> GetIdsForAncestorQuery() { @@ -2915,14 +2791,9 @@ namespace MediaBrowser.Controller.Entities return GetExtras(); } - public virtual bool IsHD { - get - { - return Height >= 720; - } - } - public bool IsShortcut{ get; set;} - public string ShortcutPath{ get; set;} + public virtual bool IsHD => Height >= 720; + public bool IsShortcut { get; set; } + public string ShortcutPath { get; set; } public int Width { get; set; } public int Height { get; set; } public Guid[] ExtraIds { get; set; } @@ -2931,12 +2802,7 @@ namespace MediaBrowser.Controller.Entities return RunTimeTicks ?? 0; } // what does this do? - public static ExtraType[] DisplayExtraTypes = new[] {Model.Entities.ExtraType.ThemeSong, Model.Entities.ExtraType.ThemeVideo }; - public virtual bool SupportsExternalTransfer - { - get { - return false; - } - } + public static ExtraType[] DisplayExtraTypes = new[] { Model.Entities.ExtraType.ThemeSong, Model.Entities.ExtraType.ThemeVideo }; + public virtual bool SupportsExternalTransfer => false; } } |
