diff options
Diffstat (limited to 'MediaBrowser.Controller/Entities')
23 files changed, 226 insertions, 245 deletions
diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index e671e5c71..d789033f1 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -67,14 +67,14 @@ namespace MediaBrowser.Controller.Entities { lock (_childIdsLock) { - if (_childrenIds == null || _childrenIds.Length == 0) + if (_childrenIds is null || _childrenIds.Length == 0) { var list = base.LoadChildren(); _childrenIds = list.Select(i => i.Id).ToArray(); return list; } - return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i != null).ToList(); + return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i is not null).ToList(); } } @@ -120,7 +120,7 @@ namespace MediaBrowser.Controller.Entities var path = ContainingFolderPath; - var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, directoryService) + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager) { FileInfo = FileSystem.GetDirectoryInfo(path) }; diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 29f7bf92b..c7216a320 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -81,8 +81,8 @@ namespace MediaBrowser.Controller.Entities.Audio /// <returns>System.String.</returns> protected override string CreateSortName() { - return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) - + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + Name; + return (ParentIndexNumber is not null ? ParentIndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + + (IndexNumber is not null ? IndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + Name; } public override List<string> GetUserDataKeys() diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index 6555de855..2dbd513a1 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -138,7 +138,7 @@ namespace MediaBrowser.Controller.Entities.Audio var artist = GetMusicArtist(new DtoOptions(false)); - if (artist != null) + if (artist is not null) { id.ArtistProviderIds = artist.ProviderIds; } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 7f5f9f74b..1e868194e 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -47,7 +47,7 @@ namespace MediaBrowser.Controller.Entities /// The supported image extensions. /// </summary> public static readonly string[] SupportedImageExtensions - = new[] { ".png", ".jpg", ".jpeg", ".tbn", ".gif" }; + = new[] { ".png", ".jpg", ".jpeg", ".webp", ".tbn", ".gif" }; private static readonly List<string> _supportedExtensions = new List<string>(SupportedImageExtensions) { @@ -56,6 +56,7 @@ namespace MediaBrowser.Controller.Entities ".srt", ".vtt", ".sub", + ".sup", ".idx", ".txt", ".edl", @@ -128,6 +129,13 @@ namespace MediaBrowser.Controller.Entities public string Album { get; set; } /// <summary> + /// Gets or sets the LUFS value. + /// </summary> + /// <value>The LUFS Value.</value> + [JsonIgnore] + public float LUFS { get; set; } + + /// <summary> /// Gets or sets the channel identifier. /// </summary> /// <value>The channel identifier.</value> @@ -494,7 +502,7 @@ namespace MediaBrowser.Controller.Entities { get { - if (_sortName == null) + if (_sortName is null) { if (!string.IsNullOrEmpty(ForcedSortName)) { @@ -553,7 +561,7 @@ namespace MediaBrowser.Controller.Entities public string OfficialRating { get; set; } [JsonIgnore] - public int InheritedParentalRatingValue { get; set; } + public int? InheritedParentalRatingValue { get; set; } /// <summary> /// Gets or sets the critic rating. @@ -658,7 +666,7 @@ namespace MediaBrowser.Controller.Entities } var parent = DisplayParent; - if (parent != null) + if (parent is not null) { return parent.OfficialRatingForComparison; } @@ -679,7 +687,7 @@ namespace MediaBrowser.Controller.Entities } var parent = DisplayParent; - if (parent != null) + if (parent is not null) { return parent.CustomRatingForComparison; } @@ -800,16 +808,14 @@ namespace MediaBrowser.Controller.Entities { return allowed.Contains(ChannelId); } - else - { - var collectionFolders = LibraryManager.GetCollectionFolders(this, allCollectionFolders); - foreach (var folder in collectionFolders) + var collectionFolders = LibraryManager.GetCollectionFolders(this, allCollectionFolders); + + foreach (var folder in collectionFolders) + { + if (allowed.Contains(folder.Id)) { - if (allowed.Contains(folder.Id)) - { - return true; - } + return true; } } @@ -880,7 +886,7 @@ namespace MediaBrowser.Controller.Entities /// <returns>System.String.</returns> protected virtual string CreateSortName() { - if (Name == null) + if (Name is null) { return null; // some items may not have name filled in properly } @@ -892,16 +898,6 @@ namespace MediaBrowser.Controller.Entities var sortable = Name.Trim().ToLowerInvariant(); - foreach (var removeChar in ConfigurationManager.Configuration.SortRemoveCharacters) - { - sortable = sortable.Replace(removeChar, string.Empty, StringComparison.Ordinal); - } - - foreach (var replaceChar in ConfigurationManager.Configuration.SortReplaceCharacters) - { - sortable = sortable.Replace(replaceChar, " ", StringComparison.Ordinal); - } - foreach (var search in ConfigurationManager.Configuration.SortRemoveWords) { // Remove from beginning if a space follows @@ -920,12 +916,22 @@ namespace MediaBrowser.Controller.Entities } } + foreach (var removeChar in ConfigurationManager.Configuration.SortRemoveCharacters) + { + sortable = sortable.Replace(removeChar, string.Empty, StringComparison.Ordinal); + } + + foreach (var replaceChar in ConfigurationManager.Configuration.SortReplaceCharacters) + { + sortable = sortable.Replace(replaceChar, " ", StringComparison.Ordinal); + } + return ModifySortChunks(sortable); } - internal static string ModifySortChunks(string name) + internal static string ModifySortChunks(ReadOnlySpan<char> name) { - void AppendChunk(StringBuilder builder, bool isDigitChunk, ReadOnlySpan<char> chunk) + static void AppendChunk(StringBuilder builder, bool isDigitChunk, ReadOnlySpan<char> chunk) { if (isDigitChunk && chunk.Length < 10) { @@ -935,7 +941,7 @@ namespace MediaBrowser.Controller.Entities builder.Append(chunk); } - if (name.Length == 0) + if (name.IsEmpty) { return string.Empty; } @@ -949,13 +955,13 @@ namespace MediaBrowser.Controller.Entities var isDigit = char.IsDigit(name[i]); if (isDigit != isDigitChunk) { - AppendChunk(builder, isDigitChunk, name.AsSpan(chunkStart, i - chunkStart)); + AppendChunk(builder, isDigitChunk, name.Slice(chunkStart, i - chunkStart)); chunkStart = i; isDigitChunk = isDigit; } } - AppendChunk(builder, isDigitChunk, name.AsSpan(chunkStart)); + AppendChunk(builder, isDigitChunk, name.Slice(chunkStart)); // logger.LogDebug("ModifySortChunks Start: {0} End: {1}", name, builder.ToString()); return builder.ToString().RemoveDiacritics(); @@ -976,7 +982,7 @@ namespace MediaBrowser.Controller.Entities { var parent = GetParent(); - while (parent != null) + while (parent is not null) { yield return parent; @@ -1073,7 +1079,7 @@ namespace MediaBrowser.Controller.Entities { var stream = i.VideoStream; - return stream == null || stream.Width == null ? 0 : stream.Width.Value; + return stream is null || stream.Width is null ? 0 : stream.Width.Value; }) .ToList(); } @@ -1114,7 +1120,7 @@ namespace MediaBrowser.Controller.Entities } var video = item as Video; - if (video != null) + if (video is not null) { info.IsoType = video.IsoType; info.VideoType = video.VideoType; @@ -1153,7 +1159,7 @@ namespace MediaBrowser.Controller.Entities info.SupportsDirectStream = MediaSourceManager.SupportsDirectStream(info.Path, info.Protocol); } - if (video != null && video.VideoType != VideoType.VideoFile) + if (video is not null && video.VideoType != VideoType.VideoFile) { info.SupportsDirectStream = false; } @@ -1330,7 +1336,7 @@ namespace MediaBrowser.Controller.Entities public void SetParent(Folder parent) { - ParentId = parent == null ? Guid.Empty : parent.Id; + ParentId = parent is null ? Guid.Empty : parent.Id; } /// <summary> @@ -1533,12 +1539,6 @@ namespace MediaBrowser.Controller.Entities } var maxAllowedRating = user.MaxParentalAgeRating; - - if (maxAllowedRating == null) - { - return true; - } - var rating = CustomRatingForComparison; if (string.IsNullOrEmpty(rating)) @@ -1548,12 +1548,13 @@ namespace MediaBrowser.Controller.Entities if (string.IsNullOrEmpty(rating)) { + Logger.LogDebug("{0} has no parental rating set.", Name); return !GetBlockUnratedValue(user); } var value = LocalizationManager.GetRatingLevel(rating); - // Could not determine the integer value + // Could not determine rating level if (!value.HasValue) { var isAllowed = !GetBlockUnratedValue(user); @@ -1566,7 +1567,7 @@ namespace MediaBrowser.Controller.Entities return isAllowed; } - return value.Value <= maxAllowedRating.Value; + return !maxAllowedRating.HasValue || value.Value <= maxAllowedRating.Value; } public int? GetInheritedParentalRatingValue() @@ -1606,6 +1607,12 @@ namespace MediaBrowser.Controller.Entities return false; } + var allowedTagsPreference = user.GetPreference(PreferenceKind.AllowedTags); + if (allowedTagsPreference.Any() && !allowedTagsPreference.Any(i => Tags.Contains(i, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + return true; } @@ -1620,10 +1627,10 @@ namespace MediaBrowser.Controller.Entities } /// <summary> - /// Gets the block unrated value. + /// Gets a bool indicating if access to the unrated item is blocked or not. /// </summary> /// <param name="user">The configuration.</param> - /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> + /// <returns><c>true</c> if blocked, <c>false</c> otherwise.</returns> protected virtual bool GetBlockUnratedValue(User user) { // Don't block plain folders that are unrated. Let the media underneath get blocked @@ -1692,7 +1699,7 @@ namespace MediaBrowser.Controller.Entities var itemById = LibraryManager.GetItemById(info.ItemId.Value); - if (itemById != null) + if (itemById is not null) { return itemById; } @@ -1701,7 +1708,7 @@ namespace MediaBrowser.Controller.Entities var item = FindLinkedChild(info); // If still null, log - if (item == null) + if (item is null) { // Don't keep searching over and over info.ItemId = Guid.Empty; @@ -1725,7 +1732,7 @@ namespace MediaBrowser.Controller.Entities var itemByPath = LibraryManager.FindByPath(path, null); - if (itemByPath == null) + if (itemByPath is null) { Logger.LogWarning("Unable to find linked item at path {0}", info.Path); } @@ -1737,7 +1744,7 @@ namespace MediaBrowser.Controller.Entities { var item = LibraryManager.GetItemById(info.LibraryItemId); - if (item == null) + if (item is null) { Logger.LogWarning("Unable to find linked item at path {0}", info.Path); } @@ -1755,10 +1762,7 @@ namespace MediaBrowser.Controller.Entities /// <exception cref="ArgumentNullException">Throws if name is null.</exception> public void AddStudio(string name) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + ArgumentException.ThrowIfNullOrEmpty(name); var current = Studios; @@ -1791,10 +1795,7 @@ namespace MediaBrowser.Controller.Entities /// <exception cref="ArgumentNullException">Throwns if name is null.</exception> public void AddGenre(string name) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + ArgumentException.ThrowIfNullOrEmpty(name); var genres = Genres; if (!genres.Contains(name, StringComparison.OrdinalIgnoreCase)) @@ -1892,7 +1893,7 @@ namespace MediaBrowser.Controller.Entities var existingImage = GetImageInfo(image.Type, index); - if (existingImage == null) + if (existingImage is null) { AddImage(image); } @@ -1915,7 +1916,7 @@ namespace MediaBrowser.Controller.Entities var image = GetImageInfo(type, index); - if (image == null) + if (image is null) { AddImage(GetImageInfo(file, type)); } @@ -1942,7 +1943,7 @@ namespace MediaBrowser.Controller.Entities { var info = GetImageInfo(type, index); - if (info == null) + if (info is null) { // Nothing to do return; @@ -2035,7 +2036,7 @@ namespace MediaBrowser.Controller.Entities { var chapter = ItemRepository.GetChapter(this, imageIndex); - if (chapter == null) + if (chapter is null) { return null; } @@ -2060,7 +2061,7 @@ namespace MediaBrowser.Controller.Entities { var artist = FindParent<MusicArtist>(); - if (artist != null) + if (artist is not null) { return artist.GetImages(imageType).ElementAtOrDefault(imageIndex); } @@ -2147,7 +2148,7 @@ namespace MediaBrowser.Controller.Entities foreach (var newImage in images) { - if (newImage == null) + if (newImage is null) { throw new ArgumentException("null image found in list"); } @@ -2155,7 +2156,7 @@ namespace MediaBrowser.Controller.Entities var existing = existingImages .Find(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase)); - if (existing == null) + if (existing is null) { newImageList.Add(newImage); } @@ -2241,7 +2242,7 @@ namespace MediaBrowser.Controller.Entities var info1 = GetImageInfo(type, index1); var info2 = GetImageInfo(type, index2); - if (info1 == null || info2 == null) + if (info1 is null || info2 is null) { // Nothing to do return Task.CompletedTask; @@ -2274,14 +2275,14 @@ namespace MediaBrowser.Controller.Entities { var userdata = UserDataManager.GetUserData(user, this); - return userdata != null && userdata.Played; + return userdata is not null && userdata.Played; } public bool IsFavoriteOrLiked(User user) { var userdata = UserDataManager.GetUserData(user, this); - return userdata != null && (userdata.IsFavorite || (userdata.Likes ?? false)); + return userdata is not null && (userdata.IsFavorite || (userdata.Likes ?? false)); } public virtual bool IsUnplayed(User user) @@ -2290,7 +2291,7 @@ namespace MediaBrowser.Controller.Entities var userdata = UserDataManager.GetUserData(user, this); - return userdata == null || !userdata.Played; + return userdata is null || !userdata.Played; } ItemLookupInfo IHasLookupInfo<ItemLookupInfo>.GetLookupInfo() @@ -2445,18 +2446,23 @@ namespace MediaBrowser.Controller.Entities // Try to retrieve it from the db. If we don't find it, use the resolved version var video = LibraryManager.GetItemById(id) as Video; - if (video == null) + if (video is null) { video = LibraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path)) as Video; newOptions.ForceSave = true; } - if (video == null) + if (video is null) { return Task.FromResult(true); } + if (video.OwnerId.Equals(default)) + { + video.OwnerId = this.Id; + } + return RefreshMetadataForOwnedItem(video, copyTitleMetadata, newOptions, cancellationToken); } @@ -2511,7 +2517,7 @@ namespace MediaBrowser.Controller.Entities var item = this; - var inheritedParentalRatingValue = item.GetInheritedParentalRatingValue() ?? 0; + var inheritedParentalRatingValue = item.GetInheritedParentalRatingValue() ?? null; if (inheritedParentalRatingValue != item.InheritedParentalRatingValue) { item.InheritedParentalRatingValue = inheritedParentalRatingValue; @@ -2565,7 +2571,7 @@ namespace MediaBrowser.Controller.Entities { return ExtraIds .Select(LibraryManager.GetItemById) - .Where(i => i != null) + .Where(i => i is not null) .OrderBy(i => i.SortName); } @@ -2578,7 +2584,7 @@ namespace MediaBrowser.Controller.Entities { return ExtraIds .Select(LibraryManager.GetItemById) - .Where(i => i != null) + .Where(i => i is not null) .Where(i => i.ExtraType.HasValue && extraTypes.Contains(i.ExtraType.Value)) .OrderBy(i => i.SortName); } diff --git a/MediaBrowser.Controller/Entities/BaseItemExtensions.cs b/MediaBrowser.Controller/Entities/BaseItemExtensions.cs index 948eb4375..615d236c7 100644 --- a/MediaBrowser.Controller/Entities/BaseItemExtensions.cs +++ b/MediaBrowser.Controller/Entities/BaseItemExtensions.cs @@ -89,13 +89,13 @@ namespace MediaBrowser.Controller.Entities } var v = sourceProp.GetValue(source); - if (v == null) + if (v is null) { continue; } var p = destProps.Find(x => x.Name == sourceProp.Name); - if (p != null) + if (p is not null) { p.SetValue(dest, v); } diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 7dc7f774d..095b261c0 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -288,7 +288,7 @@ namespace MediaBrowser.Controller.Entities { var path = ContainingFolderPath; - var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, directoryService) + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager) { FileInfo = FileSystem.GetDirectoryInfo(path), Parent = GetParent() as Folder, @@ -355,8 +355,7 @@ namespace MediaBrowser.Controller.Entities return PhysicalLocations .Where(i => !FileSystem.AreEqual(i, Path)) .SelectMany(i => GetPhysicalParents(i, rootChildren)) - .GroupBy(x => x.Id) - .Select(x => x.First()); + .DistinctBy(x => x.Id); } private IEnumerable<Folder> GetPhysicalParents(string path, List<Folder> rootChildren) diff --git a/MediaBrowser.Controller/Entities/Extensions.cs b/MediaBrowser.Controller/Entities/Extensions.cs index 1acb92fdc..3005bee0a 100644 --- a/MediaBrowser.Controller/Entities/Extensions.cs +++ b/MediaBrowser.Controller/Entities/Extensions.cs @@ -17,16 +17,11 @@ namespace MediaBrowser.Controller.Entities /// <param name="url">Trailer URL.</param> public static void AddTrailerUrl(this BaseItem item, string url) { - ArgumentNullException.ThrowIfNull(url); - - if (url.Length == 0) - { - throw new ArgumentException("String can't be empty", nameof(url)); - } + ArgumentException.ThrowIfNullOrEmpty(url); var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase)); - if (current == null) + if (current is null) { var mediaUrl = new MediaUrl { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 808f91810..84952295c 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -483,7 +483,7 @@ namespace MediaBrowser.Controller.Entities } }); - if (container != null) + if (container is not null) { await RefreshAllMetadataForContainer(container, refreshOptions, innerProgress, cancellationToken).ConfigureAwait(false); } @@ -515,7 +515,7 @@ namespace MediaBrowser.Controller.Entities async () => { var series = container as Series; - if (series != null) + if (series is not null) { await series.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); } @@ -529,7 +529,7 @@ namespace MediaBrowser.Controller.Entities { var container = child as IMetadataContainer; - if (container != null) + if (container is not null) { await RefreshAllMetadataForContainer(container, refreshOptions, progress, cancellationToken).ConfigureAwait(false); } @@ -703,7 +703,7 @@ namespace MediaBrowser.Controller.Entities IEnumerable<BaseItem> items; Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager); - if (query.User == null) + if (query.User is null) { items = GetRecursiveChildren(filter); } @@ -730,7 +730,7 @@ namespace MediaBrowser.Controller.Entities return LibraryManager.GetItemsResult(query); } - private QueryResult<BaseItem> QueryWithPostFiltering2(InternalItemsQuery query) + protected QueryResult<BaseItem> QueryWithPostFiltering2(InternalItemsQuery query) { var startIndex = query.StartIndex; var limit = query.Limit; @@ -741,7 +741,7 @@ namespace MediaBrowser.Controller.Entities IEnumerable<BaseItem> itemsList = LibraryManager.GetItemList(query); var user = query.User; - if (user != null) + if (user is not null) { // needed for boxsets itemsList = itemsList.Where(i => i.IsVisibleStandalone(query.User)); @@ -961,7 +961,7 @@ namespace MediaBrowser.Controller.Entities IEnumerable<BaseItem> items; - if (query.User == null) + if (query.User is null) { items = Children.Where(filter); } @@ -984,7 +984,7 @@ namespace MediaBrowser.Controller.Entities var user = query.User; // Check recursive - don't substitute in plain folder views - if (user != null) + if (user is not null) { items = CollapseBoxSetItemsIfNeeded(items, query, this, user, ConfigurationManager, CollectionManager); } @@ -1069,7 +1069,7 @@ namespace MediaBrowser.Controller.Entities if (!param.HasValue) { - if (user != null && !configurationManager.Configuration.EnableGroupingIntoCollections) + if (user is not null && !configurationManager.Configuration.EnableGroupingIntoCollections) { return false; } @@ -1272,7 +1272,7 @@ namespace MediaBrowser.Controller.Entities { ArgumentNullException.ThrowIfNull(user); - return GetChildren(user, includeLinkedChildren, null); + return GetChildren(user, includeLinkedChildren, new InternalItemsQuery(user)); } public virtual List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query) @@ -1300,8 +1300,15 @@ namespace MediaBrowser.Controller.Entities /// <summary> /// Adds the children to list. /// </summary> - private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query) + private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query, HashSet<Folder> visitedFolders = null) { + // Prevent infinite recursion of nested folders + visitedFolders ??= new HashSet<Folder>(); + if (!visitedFolders.Add(this)) + { + return; + } + // If Query.AlbumFolders is set, then enforce the format as per the db in that it permits sub-folders in music albums. IEnumerable<BaseItem> children = null; if ((query?.DisplayAlbumFolders ?? false) && (this is MusicAlbum)) @@ -1311,47 +1318,38 @@ namespace MediaBrowser.Controller.Entities } // If there are not sub-folders, proceed as normal. - if (children == null) + if (children is null) { children = GetEligibleChildrenForRecursiveChildren(user); } - foreach (var child in children) + AddChildrenFromCollection(children, user, includeLinkedChildren, result, recursive, query, visitedFolders); + + if (includeLinkedChildren) { - bool? isVisibleToUser = null; + AddChildrenFromCollection(GetLinkedChildren(user), user, includeLinkedChildren, result, recursive, query, visitedFolders); + } + } - if (query == null || UserViewBuilder.FilterItem(child, query)) + private void AddChildrenFromCollection(IEnumerable<BaseItem> children, User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, InternalItemsQuery query, HashSet<Folder> visitedFolders) + { + foreach (var child in children) + { + if (!child.IsVisible(user)) { - isVisibleToUser = child.IsVisible(user); - - if (isVisibleToUser.Value) - { - result[child.Id] = child; - } + continue; } - if (isVisibleToUser ?? child.IsVisible(user)) + if (query is null || UserViewBuilder.FilterItem(child, query)) { - if (recursive && child.IsFolder) - { - var folder = (Folder)child; - - folder.AddChildren(user, includeLinkedChildren, result, true, query); - } + result[child.Id] = child; } - } - if (includeLinkedChildren) - { - foreach (var child in GetLinkedChildren(user)) + if (recursive && child.IsFolder) { - if (query == null || UserViewBuilder.FilterItem(child, query)) - { - if (child.IsVisible(user)) - { - result[child.Id] = child; - } - } + var folder = (Folder)child; + + folder.AddChildren(user, includeLinkedChildren, result, true, query, visitedFolders); } } } @@ -1402,7 +1400,7 @@ namespace MediaBrowser.Controller.Entities { foreach (var child in Children) { - if (filter == null || filter(child)) + if (filter is null || filter(child)) { result[child.Id] = child; } @@ -1420,7 +1418,7 @@ namespace MediaBrowser.Controller.Entities { foreach (var child in GetLinkedChildren()) { - if (filter == null || filter(child)) + if (filter is null || filter(child)) { result[child.Id] = child; } @@ -1441,7 +1439,7 @@ namespace MediaBrowser.Controller.Entities { var child = GetLinkedChild(i); - if (child != null) + if (child is not null) { list.Add(child); } @@ -1467,7 +1465,7 @@ namespace MediaBrowser.Controller.Entities var child = GetLinkedChild(i); - if (child != null && child.Id.Equals(itemId)) + if (child is not null && child.Id.Equals(itemId)) { return true; } @@ -1478,7 +1476,7 @@ namespace MediaBrowser.Controller.Entities public List<BaseItem> GetLinkedChildren(User user) { - if (!FilterLinkedChildrenPerUser || user == null) + if (!FilterLinkedChildrenPerUser || user is null) { return GetLinkedChildren(); } @@ -1504,7 +1502,7 @@ namespace MediaBrowser.Controller.Entities { var child = GetLinkedChild(i); - if (child == null) + if (child is null) { continue; } @@ -1547,7 +1545,7 @@ namespace MediaBrowser.Controller.Entities { return LinkedChildren .Select(i => new Tuple<LinkedChild, BaseItem>(i, GetLinkedChild(i))) - .Where(i => i.Item2 != null); + .Where(i => i.Item2 is not null); } protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, IReadOnlyList<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken) @@ -1605,7 +1603,7 @@ namespace MediaBrowser.Controller.Entities return null; } }) - .Where(i => i != null) + .Where(i => i is not null) .ToList(); var currentShortcutLinks = LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut).ToList(); @@ -1662,7 +1660,7 @@ namespace MediaBrowser.Controller.Entities { // The querying doesn't support virtual unaired var episode = item as Episode; - if (episode != null && episode.IsUnaired) + if (episode is not null && episode.IsUnaired) { continue; } @@ -1719,7 +1717,7 @@ namespace MediaBrowser.Controller.Entities return; } - if (itemDto != null) + if (itemDto is not null) { if (fields.ContainsField(ItemFields.RecursiveItemCount)) { diff --git a/MediaBrowser.Controller/Entities/IHasShares.cs b/MediaBrowser.Controller/Entities/IHasShares.cs deleted file mode 100644 index e6fa27703..000000000 --- a/MediaBrowser.Controller/Entities/IHasShares.cs +++ /dev/null @@ -1,11 +0,0 @@ -#nullable disable - -#pragma warning disable CA1819, CS1591 - -namespace MediaBrowser.Controller.Entities -{ - public interface IHasShares - { - Share[] Shares { get; set; } - } -} diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 1bf528538..a51299284 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -26,6 +26,7 @@ namespace MediaBrowser.Controller.Entities EnableTotalRecordCount = true; ExcludeArtistIds = Array.Empty<Guid>(); ExcludeInheritedTags = Array.Empty<string>(); + IncludeInheritedTags = Array.Empty<string>(); ExcludeItemIds = Array.Empty<Guid>(); ExcludeItemTypes = Array.Empty<BaseItemKind>(); ExcludeTags = Array.Empty<string>(); @@ -55,7 +56,7 @@ namespace MediaBrowser.Controller.Entities public InternalItemsQuery(User? user) : this() { - if (user != null) + if (user is not null) { SetUser(user); } @@ -95,6 +96,8 @@ namespace MediaBrowser.Controller.Entities public string[] ExcludeInheritedTags { get; set; } + public string[] IncludeInheritedTags { get; set; } + public IReadOnlyList<string> Genres { get; set; } public bool? IsSpecialSeason { get; set; } @@ -316,7 +319,7 @@ namespace MediaBrowser.Controller.Entities { set { - if (value == null) + if (value is null) { ParentId = Guid.Empty; ParentType = null; @@ -368,6 +371,7 @@ namespace MediaBrowser.Controller.Entities } ExcludeInheritedTags = user.GetPreference(PreferenceKind.BlockedTags); + IncludeInheritedTags = user.GetPreference(PreferenceKind.AllowedTags); User = user; } diff --git a/MediaBrowser.Controller/Entities/ItemImageInfo.cs b/MediaBrowser.Controller/Entities/ItemImageInfo.cs index ea8555dbf..0171af27c 100644 --- a/MediaBrowser.Controller/Entities/ItemImageInfo.cs +++ b/MediaBrowser.Controller/Entities/ItemImageInfo.cs @@ -39,6 +39,6 @@ namespace MediaBrowser.Controller.Entities public string BlurHash { get; set; } [JsonIgnore] - public bool IsLocalFile => Path == null || !Path.StartsWith("http", StringComparison.OrdinalIgnoreCase); + public bool IsLocalFile => Path is null || !Path.StartsWith("http", StringComparison.OrdinalIgnoreCase); } } diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs index 882abc927..66210cb6c 100644 --- a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs +++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs @@ -104,7 +104,7 @@ namespace MediaBrowser.Controller.Entities.Movies public override bool IsAuthorizedToDelete(User user, List<Folder> allCollectionFolders) { - return true; + return user.HasPermission(PermissionKind.IsAdministrator) || user.HasPermission(PermissionKind.EnableCollectionManagement); } public override bool IsSaveLocalMetadataEnabled() diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index 77e70f8fb..81f6248fa 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Entities.Movies /// <inheritdoc /> [JsonIgnore] public IReadOnlyList<Guid> SpecialFeatureIds => GetExtras() - .Where(extra => extra.ExtraType != null && extra is Video) + .Where(extra => extra.ExtraType is not null && extra is Video) .Select(extra => extra.Id) .ToArray(); @@ -33,9 +33,9 @@ namespace MediaBrowser.Controller.Entities.Movies .ToArray(); /// <summary> - /// Gets or sets the name of the TMDB collection. + /// Gets or sets the name of the TMDb collection. /// </summary> - /// <value>The name of the TMDB collection.</value> + /// <value>The name of the TMDb collection.</value> public string TmdbCollectionName { get; set; } [JsonIgnore] diff --git a/MediaBrowser.Controller/Entities/PeopleHelper.cs b/MediaBrowser.Controller/Entities/PeopleHelper.cs index 8571bfcea..5292bd772 100644 --- a/MediaBrowser.Controller/Entities/PeopleHelper.cs +++ b/MediaBrowser.Controller/Entities/PeopleHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Jellyfin.Data.Enums; using MediaBrowser.Model.Entities; namespace MediaBrowser.Controller.Entities @@ -12,48 +13,44 @@ namespace MediaBrowser.Controller.Entities public static void AddPerson(List<PersonInfo> people, PersonInfo person) { ArgumentNullException.ThrowIfNull(person); - - if (string.IsNullOrEmpty(person.Name)) - { - throw new ArgumentException("The person's name was empty or null.", nameof(person)); - } + ArgumentException.ThrowIfNullOrEmpty(person.Name); // Normalize if (string.Equals(person.Role, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)) { - person.Type = PersonType.GuestStar; + person.Type = PersonKind.GuestStar; } else if (string.Equals(person.Role, PersonType.Director, StringComparison.OrdinalIgnoreCase)) { - person.Type = PersonType.Director; + person.Type = PersonKind.Director; } else if (string.Equals(person.Role, PersonType.Producer, StringComparison.OrdinalIgnoreCase)) { - person.Type = PersonType.Producer; + person.Type = PersonKind.Producer; } else if (string.Equals(person.Role, PersonType.Writer, StringComparison.OrdinalIgnoreCase)) { - person.Type = PersonType.Writer; + person.Type = PersonKind.Writer; } // If the type is GuestStar and there's already an Actor entry, then update it to avoid dupes - if (string.Equals(person.Type, PersonType.GuestStar, StringComparison.OrdinalIgnoreCase)) + if (person.Type == PersonKind.GuestStar) { - var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase)); + var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && p.Type == PersonKind.Actor); - if (existing != null) + if (existing is not null) { - existing.Type = PersonType.GuestStar; + existing.Type = PersonKind.GuestStar; MergeExisting(existing, person); return; } } - if (string.Equals(person.Type, PersonType.Actor, StringComparison.OrdinalIgnoreCase)) + if (person.Type == PersonKind.Actor) { // If the actor already exists without a role and we have one, fill it in - var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type.Equals(PersonType.Actor, StringComparison.OrdinalIgnoreCase) || p.Type.Equals(PersonType.GuestStar, StringComparison.OrdinalIgnoreCase))); - if (existing == null) + var existing = people.FirstOrDefault(p => p.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase) && (p.Type == PersonKind.Actor || p.Type == PersonKind.GuestStar)); + if (existing is null) { // Wasn't there - add it people.Add(person); @@ -72,11 +69,11 @@ namespace MediaBrowser.Controller.Entities else { var existing = people.FirstOrDefault(p => - string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) && - string.Equals(p.Type, person.Type, StringComparison.OrdinalIgnoreCase)); + string.Equals(p.Name, person.Name, StringComparison.OrdinalIgnoreCase) + && p.Type == person.Type); // Check for dupes based on the combination of Name and Type - if (existing == null) + if (existing is null) { people.Add(person); } diff --git a/MediaBrowser.Controller/Entities/PersonInfo.cs b/MediaBrowser.Controller/Entities/PersonInfo.cs index 2b689ae7e..3df0b0b78 100644 --- a/MediaBrowser.Controller/Entities/PersonInfo.cs +++ b/MediaBrowser.Controller/Entities/PersonInfo.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using Jellyfin.Data.Enums; using MediaBrowser.Model.Entities; namespace MediaBrowser.Controller.Entities @@ -36,7 +37,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the type. /// </summary> /// <value>The type.</value> - public string Type { get; set; } + public PersonKind Type { get; set; } /// <summary> /// Gets or sets the ascending sort order. @@ -57,10 +58,6 @@ namespace MediaBrowser.Controller.Entities return Name; } - public bool IsType(string type) - { - return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase) - || string.Equals(Role, type, StringComparison.OrdinalIgnoreCase); - } + public bool IsType(PersonKind type) => Type == type || string.Equals(type.ToString(), Role, StringComparison.OrdinalIgnoreCase); } } diff --git a/MediaBrowser.Controller/Entities/Share.cs b/MediaBrowser.Controller/Entities/Share.cs deleted file mode 100644 index 64f446eef..000000000 --- a/MediaBrowser.Controller/Entities/Share.cs +++ /dev/null @@ -1,13 +0,0 @@ -#nullable disable - -#pragma warning disable CS1591 - -namespace MediaBrowser.Controller.Entities -{ - public class Share - { - public string UserId { get; set; } - - public bool CanEdit { get; set; } - } -} diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 15b721fe6..597b4cecb 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -136,7 +136,7 @@ namespace MediaBrowser.Controller.Entities.TV public string FindSeriesSortName() { var series = Series; - return series == null ? SeriesName : series.SortName; + return series is null ? SeriesName : series.SortName; } public override double GetDefaultPrimaryImageAspectRatio() @@ -155,7 +155,7 @@ namespace MediaBrowser.Controller.Entities.TV var list = base.GetUserDataKeys(); var series = Series; - if (series != null && ParentIndexNumber.HasValue && IndexNumber.HasValue) + if (series is not null && ParentIndexNumber.HasValue && IndexNumber.HasValue) { var seriesUserDataKeys = series.GetUserDataKeys(); var take = seriesUserDataKeys.Count; @@ -181,14 +181,14 @@ namespace MediaBrowser.Controller.Entities.TV public string FindSeriesPresentationUniqueKey() { var series = Series; - return series == null ? null : series.PresentationUniqueKey; + return series is null ? null : series.PresentationUniqueKey; } public string FindSeasonName() { var season = Season; - if (season == null) + if (season is null) { if (ParentIndexNumber.HasValue) { @@ -204,7 +204,7 @@ namespace MediaBrowser.Controller.Entities.TV public string FindSeriesName() { var series = Series; - return series == null ? SeriesName : series.Name; + return series is null ? SeriesName : series.Name; } public Guid FindSeasonId() @@ -212,11 +212,11 @@ namespace MediaBrowser.Controller.Entities.TV var season = FindParent<Season>(); // Episodes directly in series folder - if (season == null) + if (season is null) { var series = Series; - if (series != null && ParentIndexNumber.HasValue) + if (series is not null && ParentIndexNumber.HasValue) { var findNumber = ParentIndexNumber.Value; @@ -226,7 +226,7 @@ namespace MediaBrowser.Controller.Entities.TV } } - return season == null ? Guid.Empty : season.Id; + return season is null ? Guid.Empty : season.Id; } /// <summary> @@ -235,8 +235,8 @@ namespace MediaBrowser.Controller.Entities.TV /// <returns>System.String.</returns> protected override string CreateSortName() { - return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("000 - ", CultureInfo.InvariantCulture) : string.Empty) - + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + Name; + return (ParentIndexNumber is not null ? ParentIndexNumber.Value.ToString("000 - ", CultureInfo.InvariantCulture) : string.Empty) + + (IndexNumber is not null ? IndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + Name; } /// <summary> @@ -262,7 +262,7 @@ namespace MediaBrowser.Controller.Entities.TV public Guid FindSeriesId() { var series = FindParent<Series>(); - return series == null ? Guid.Empty : series.Id; + return series is null ? Guid.Empty : series.Id; } public override IEnumerable<Guid> GetAncestorIds() @@ -302,12 +302,17 @@ namespace MediaBrowser.Controller.Entities.TV var series = Series; - if (series != null) + if (series is not null) { id.SeriesProviderIds = series.ProviderIds; id.SeriesDisplayOrder = series.DisplayOrder; } + if (Season is not null) + { + id.SeasonProviderIds = Season.ProviderIds; + } + id.IsMissingEpisode = IsMissingEpisode; id.IndexNumberEnd = IndexNumberEnd; @@ -320,7 +325,7 @@ namespace MediaBrowser.Controller.Entities.TV if (!IsLocked) { - if (SourceType == SourceType.Library) + if (SourceType == SourceType.Library || SourceType == SourceType.LiveTV) { try { diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index 599d35da6..0a040a3c2 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -64,7 +64,7 @@ namespace MediaBrowser.Controller.Entities.TV { var series = Series; - if (series != null) + if (series is not null) { return series.Path; } @@ -93,7 +93,7 @@ namespace MediaBrowser.Controller.Entities.TV public string FindSeriesSortName() { var series = Series; - return series == null ? SeriesName : series.SortName; + return series is null ? SeriesName : series.SortName; } public override List<string> GetUserDataKeys() @@ -101,7 +101,7 @@ namespace MediaBrowser.Controller.Entities.TV var list = base.GetUserDataKeys(); var series = Series; - if (series != null) + if (series is not null) { var newList = series.GetUserDataKeys(); var suffix = (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture); @@ -129,7 +129,7 @@ namespace MediaBrowser.Controller.Entities.TV if (IndexNumber.HasValue) { var series = Series; - if (series != null) + if (series is not null) { return series.PresentationUniqueKey + "-" + (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture); } @@ -144,12 +144,12 @@ namespace MediaBrowser.Controller.Entities.TV /// <returns>System.String.</returns> protected override string CreateSortName() { - return IndexNumber != null ? IndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) : Name; + return IndexNumber is not null ? IndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) : Name; } protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query) { - if (query.User == null) + if (query.User is null) { return base.GetItemsInternal(query); } @@ -208,13 +208,13 @@ namespace MediaBrowser.Controller.Entities.TV public string FindSeriesPresentationUniqueKey() { var series = Series; - return series == null ? null : series.PresentationUniqueKey; + return series is null ? null : series.PresentationUniqueKey; } public string FindSeriesName() { var series = Series; - return series == null ? SeriesName : series.Name; + return series is null ? SeriesName : series.Name; } public Guid FindSeriesId() @@ -233,7 +233,7 @@ namespace MediaBrowser.Controller.Entities.TV var series = Series; - if (series != null) + if (series is not null) { id.SeriesProviderIds = series.ProviderIds; } diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index d66802a64..a49c1609d 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -28,6 +28,7 @@ namespace MediaBrowser.Controller.Entities.TV public Series() { AirDays = Array.Empty<DayOfWeek>(); + SeasonNames = new Dictionary<int, string>(); } public DayOfWeek[] AirDays { get; set; } @@ -35,6 +36,9 @@ namespace MediaBrowser.Controller.Entities.TV public string AirTime { get; set; } [JsonIgnore] + public Dictionary<int, string> SeasonNames { get; set; } + + [JsonIgnore] public override bool SupportsAddingToPlaylist => true; [JsonIgnore] @@ -218,7 +222,7 @@ namespace MediaBrowser.Controller.Entities.TV query.IncludeItemTypes = new[] { BaseItemKind.Season }; query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }; - if (user != null && !user.DisplayMissingEpisodes) + if (user is not null && !user.DisplayMissingEpisodes) { query.IsMissing = false; } @@ -266,7 +270,7 @@ namespace MediaBrowser.Controller.Entities.TV DtoOptions = options }; - if (user == null || !user.DisplayMissingEpisodes) + if (user is null || !user.DisplayMissingEpisodes) { query.IsMissing = false; } @@ -283,7 +287,7 @@ namespace MediaBrowser.Controller.Entities.TV // This depends on settings for that series // When this happens, remove the duplicate from season 0 - return allEpisodes.GroupBy(i => i.Id).Select(x => x.First()).Reverse(); + return allEpisodes.DistinctBy(i => i.Id).Reverse(); } public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken) @@ -369,7 +373,7 @@ namespace MediaBrowser.Controller.Entities.TV OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, DtoOptions = options }; - if (user != null) + if (user is not null) { if (!user.DisplayMissingEpisodes) { @@ -384,7 +388,7 @@ namespace MediaBrowser.Controller.Entities.TV public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, IEnumerable<BaseItem> allSeriesEpisodes, DtoOptions options) { - if (allSeriesEpisodes == null) + if (allSeriesEpisodes is null) { return GetSeasonEpisodes(parentSeason, user, options); } @@ -426,7 +430,7 @@ namespace MediaBrowser.Controller.Entities.TV } var season = episodeItem.Season; - return season != null && string.Equals(GetUniqueSeriesKey(season), seasonPresentationKey, StringComparison.OrdinalIgnoreCase); + return season is not null && string.Equals(GetUniqueSeriesKey(season), seasonPresentationKey, StringComparison.OrdinalIgnoreCase); }); } @@ -448,7 +452,7 @@ namespace MediaBrowser.Controller.Entities.TV { var episode = i; - if (episode != null) + if (episode is not null) { var currentSeasonNumber = episode.AiredSeasonNumber; diff --git a/MediaBrowser.Controller/Entities/UserItemData.cs b/MediaBrowser.Controller/Entities/UserItemData.cs index 50ba9ef30..ecca440f0 100644 --- a/MediaBrowser.Controller/Entities/UserItemData.cs +++ b/MediaBrowser.Controller/Entities/UserItemData.cs @@ -105,7 +105,7 @@ namespace MediaBrowser.Controller.Entities { get { - if (Rating != null) + if (Rating is not null) { return Rating >= MinLikeValue; } diff --git a/MediaBrowser.Controller/Entities/UserRootFolder.cs b/MediaBrowser.Controller/Entities/UserRootFolder.cs index e547db523..69743b926 100644 --- a/MediaBrowser.Controller/Entities/UserRootFolder.cs +++ b/MediaBrowser.Controller/Entities/UserRootFolder.cs @@ -56,14 +56,14 @@ namespace MediaBrowser.Controller.Entities { lock (_childIdsLock) { - if (_childrenIds == null) + if (_childrenIds is null) { var list = base.LoadChildren(); _childrenIds = list.Select(i => i.Id).ToList(); return list; } - return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i != null).ToList(); + return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i is not null).ToList(); } } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index f467a6038..c276ab463 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -46,7 +46,7 @@ namespace MediaBrowser.Controller.Entities { var user = query.User; - // if (query.IncludeItemTypes != null && + // if (query.IncludeItemTypes is not null && // query.IncludeItemTypes.Length == 1 && // string.Equals(query.IncludeItemTypes[0], "Playlist", StringComparison.OrdinalIgnoreCase)) // { @@ -263,7 +263,7 @@ namespace MediaBrowser.Controller.Entities return null; } }) - .Where(i => i != null) + .Where(i => i is not null) .Select(i => GetUserViewWithName(SpecialFolder.MovieGenre, i.SortName, parent)); return GetResult(genres, query); @@ -391,7 +391,7 @@ namespace MediaBrowser.Controller.Entities return null; } }) - .Where(i => i != null) + .Where(i => i is not null) .Select(i => GetUserViewWithName(SpecialFolder.TvGenre, i.SortName, parent)); return GetResult(genres, query); @@ -559,7 +559,7 @@ namespace MediaBrowser.Controller.Entities var val = query.Is3D.Value; var video = item as Video; - if (video == null || val != video.Video3DFormat.HasValue) + if (video is null || val != video.Video3DFormat.HasValue) { return false; } @@ -689,7 +689,7 @@ namespace MediaBrowser.Controller.Entities var video = item as Video; - if (video == null || val != video.HasSubtitles) + if (video is null || val != video.HasSubtitles) { return false; } @@ -776,7 +776,7 @@ namespace MediaBrowser.Controller.Entities if (query.VideoTypes.Length > 0) { var video = item as Video; - if (video == null || !query.VideoTypes.Contains(video.VideoType)) + if (video is null || !query.VideoTypes.Contains(video.VideoType)) { return false; } @@ -791,7 +791,7 @@ namespace MediaBrowser.Controller.Entities if (query.StudioIds.Length > 0 && !query.StudioIds.Any(id => { var studioItem = libraryManager.GetItemById(id); - return studioItem != null && item.Studios.Contains(studioItem.Name, StringComparison.OrdinalIgnoreCase); + return studioItem is not null && item.Studios.Contains(studioItem.Name, StringComparison.OrdinalIgnoreCase); })) { return false; @@ -801,7 +801,7 @@ namespace MediaBrowser.Controller.Entities if (query.GenreIds.Count > 0 && !query.GenreIds.Any(id => { var genreItem = libraryManager.GetItemById(id); - return genreItem != null && item.Genres.Contains(genreItem.Name, StringComparison.OrdinalIgnoreCase); + return genreItem is not null && item.Genres.Contains(genreItem.Name, StringComparison.OrdinalIgnoreCase); })) { return false; @@ -913,7 +913,7 @@ namespace MediaBrowser.Controller.Entities { var episode = item as Episode; - if (episode == null) + if (episode is null) { return false; } @@ -929,7 +929,7 @@ namespace MediaBrowser.Controller.Entities private IEnumerable<BaseItem> GetMediaFolders(User user) { - if (user == null) + if (user is null) { return _libraryManager.RootFolder .Children @@ -945,14 +945,14 @@ namespace MediaBrowser.Controller.Entities private BaseItem[] GetMediaFolders(User user, IEnumerable<string> viewTypes) { - if (user == null) + if (user is null) { return GetMediaFolders(null) .Where(i => { var folder = i as ICollectionFolder; - return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparison.OrdinalIgnoreCase); + return folder is not null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparison.OrdinalIgnoreCase); }).ToArray(); } @@ -961,13 +961,13 @@ namespace MediaBrowser.Controller.Entities { var folder = i as ICollectionFolder; - return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparison.OrdinalIgnoreCase); + return folder is not null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparison.OrdinalIgnoreCase); }).ToArray(); } private BaseItem[] GetMediaFolders(Folder parent, User user, IEnumerable<string> viewTypes) { - if (parent == null || parent is UserView) + if (parent is null || parent is UserView) { return GetMediaFolders(user, viewTypes); } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 5de2e0f50..5b7abea10 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -373,7 +373,7 @@ namespace MediaBrowser.Controller.Entities { return LinkedAlternateVersions .Select(GetLinkedChild) - .Where(i => i != null) + .Where(i => i is not null) .OfType<Video>() .OrderBy(i => i.SortName); } @@ -386,7 +386,7 @@ namespace MediaBrowser.Controller.Entities { return GetAdditionalPartIds() .Select(i => LibraryManager.GetItemById(i)) - .Where(i => i != null) + .Where(i => i is not null) .OfType<Video>() .OrderBy(i => i.SortName); } @@ -469,7 +469,7 @@ namespace MediaBrowser.Controller.Entities var localAlternates = GetLocalAlternateVersionIds() .Select(i => LibraryManager.GetItemById(i)) - .Where(i => i != null); + .Where(i => i is not null); foreach (var item in localAlternates) { @@ -542,7 +542,7 @@ namespace MediaBrowser.Controller.Entities return i.Item1 is Video video ? video.GetLocalAlternateVersionIds() : Enumerable.Empty<Guid>(); }) .Select(LibraryManager.GetItemById) - .Where(i => i != null) + .Where(i => i is not null) .ToList(); list.AddRange(localAlternates.Select(i => (i, MediaSourceType.Default))); |
