diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 61ad976ec3..6691080bc8 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -484,9 +484,9 @@ namespace MediaBrowser.Api /// Task. internal Task KillTranscodingJobs(string deviceId, string playSessionId, Func deleteFiles) { - return KillTranscodingJobs(j => !string.IsNullOrWhiteSpace(playSessionId) - ? string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase) - : string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase), deleteFiles); + return KillTranscodingJobs(j => string.IsNullOrWhiteSpace(playSessionId) + ? string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase) + : string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase), deleteFiles); } /// diff --git a/MediaBrowser.Api/ChannelService.cs b/MediaBrowser.Api/ChannelService.cs index e43e34133c..fd9b8c3968 100644 --- a/MediaBrowser.Api/ChannelService.cs +++ b/MediaBrowser.Api/ChannelService.cs @@ -117,8 +117,8 @@ namespace MediaBrowser.Api var val = Filters; return string.IsNullOrEmpty(val) - ? new ItemFilter[] { } - : val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true)); + ? Array.Empty() + : val.Split(',').Select(v => Enum.Parse(v, true)); } /// @@ -170,11 +170,9 @@ namespace MediaBrowser.Api /// IEnumerable{ItemFilter}. public IEnumerable GetFilters() { - var val = Filters; - - return string.IsNullOrEmpty(val) - ? new ItemFilter[] { } - : val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true)); + return string.IsNullOrEmpty(Filters) + ? Array.Empty() + : Filters.Split(',').Select(v => Enum.Parse(v, true)); } } diff --git a/MediaBrowser.Api/ItemLookupService.cs b/MediaBrowser.Api/ItemLookupService.cs index 5a7b1f37ae..0bbe7e1cfa 100644 --- a/MediaBrowser.Api/ItemLookupService.cs +++ b/MediaBrowser.Api/ItemLookupService.cs @@ -306,7 +306,8 @@ namespace MediaBrowser.Api Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath)); using (var stream = result.Content) { - using var fileStream = new FileStream(fullCachePath, + using var fileStream = new FileStream( + fullCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 9251343e8b..6f6c1864ed 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -393,6 +393,7 @@ namespace MediaBrowser.Api.Library { return true; } + if (string.Equals(type, "Season", StringComparison.OrdinalIgnoreCase) || string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase) || string.Equals(type, "MusicVideo", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 7c9e65fe7a..eb44cb4266 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -137,7 +137,9 @@ namespace MediaBrowser.Api.Playback var ext = outputFileExtension.ToLowerInvariant(); var folder = ServerConfigurationManager.GetTranscodePath(); - return EnableOutputInSubFolder ? Path.Combine(folder, filename, filename + ext) : Path.Combine(folder, filename + ext); + return EnableOutputInSubFolder + ? Path.Combine(folder, filename, filename + ext) + : Path.Combine(folder, filename + ext); } protected virtual string GetDefaultEncoderPreset() @@ -393,44 +395,36 @@ namespace MediaBrowser.Api.Playback request.Static = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); break; case 4: - { if (videoRequest != null) { videoRequest.VideoCodec = val; } break; - } case 5: request.AudioCodec = val; break; case 6: - { if (videoRequest != null) { videoRequest.AudioStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 7: - { if (videoRequest != null) { videoRequest.SubtitleStreamIndex = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 8: - { if (videoRequest != null) { videoRequest.VideoBitRate = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 9: request.AudioBitRate = int.Parse(val, CultureInfo.InvariantCulture); break; @@ -438,71 +432,57 @@ namespace MediaBrowser.Api.Playback request.MaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); break; case 11: - { if (videoRequest != null) { videoRequest.MaxFramerate = float.Parse(val, CultureInfo.InvariantCulture); } break; - } case 12: - { if (videoRequest != null) { videoRequest.MaxWidth = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 13: - { if (videoRequest != null) { videoRequest.MaxHeight = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 14: request.StartTimeTicks = long.Parse(val, CultureInfo.InvariantCulture); break; case 15: - { if (videoRequest != null) { videoRequest.Level = val; } break; - } case 16: - { if (videoRequest != null) { videoRequest.MaxRefFrames = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 17: - { if (videoRequest != null) { videoRequest.MaxVideoBitDepth = int.Parse(val, CultureInfo.InvariantCulture); } break; - } case 18: - { if (videoRequest != null) { videoRequest.Profile = val; } break; - } case 19: // cabac no longer used break; @@ -519,16 +499,13 @@ namespace MediaBrowser.Api.Playback // Duplicating ItemId because of MediaMonkey break; case 24: - { if (videoRequest != null) { videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; - } case 25: - { if (!string.IsNullOrWhiteSpace(val) && videoRequest != null) { if (Enum.TryParse(val, out SubtitleDeliveryMethod method)) @@ -538,52 +515,43 @@ namespace MediaBrowser.Api.Playback } break; - } case 26: request.TranscodingMaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture); break; case 27: - { if (videoRequest != null) { videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; - } case 28: request.Tag = val; break; case 29: - { if (videoRequest != null) { videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; - } case 30: request.SubtitleCodec = val; break; case 31: - { if (videoRequest != null) { videoRequest.RequireNonAnamorphic = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; - } case 32: - { if (videoRequest != null) { videoRequest.DeInterlace = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } break; - } case 33: request.TranscodeReasons = val; break; @@ -860,14 +828,11 @@ namespace MediaBrowser.Api.Playback { state.DeviceProfile = DlnaManager.GetProfile(state.Request.DeviceProfileId); } - else + else if (!string.IsNullOrWhiteSpace(state.Request.DeviceId)) { - if (!string.IsNullOrWhiteSpace(state.Request.DeviceId)) - { - var caps = DeviceManager.GetCapabilities(state.Request.DeviceId); + var caps = DeviceManager.GetCapabilities(state.Request.DeviceId); - state.DeviceProfile = caps != null ? caps.DeviceProfile : DlnaManager.GetProfile(headers); - } + state.DeviceProfile = caps == null ? DlnaManager.GetProfile(headers) : caps.DeviceProfile; } var profile = state.DeviceProfile; diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 8d5d2279ea..52962366c6 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -240,7 +240,8 @@ namespace MediaBrowser.Api.Playback.Hls protected Stream GetPlaylistFileStream(string path) { - return new FileStream(path, + return new FileStream( + path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index d4e2f44df6..15148d1c72 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -243,14 +243,12 @@ namespace MediaBrowser.Api result.StartDate = program.StartDate; break; case Series series: - { if (series.Status.HasValue) { result.Status = series.Status.Value.ToString(); } break; - } case MusicAlbum album: result.Artists = album.Artists; result.AlbumArtist = album.AlbumArtist; diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index 03cf7cabe5..eb2f5996ea 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -399,7 +399,7 @@ namespace MediaBrowser.Api.UserLibrary return string.IsNullOrEmpty(VideoTypes) ? Array.Empty() : VideoTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) - .Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray(); + .Select(v => Enum.Parse(v, true)).ToArray(); } /// @@ -411,9 +411,9 @@ namespace MediaBrowser.Api.UserLibrary var val = Filters; return string.IsNullOrEmpty(val) - ? new ItemFilter[] { } + ? Array.Empty() : val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). - Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true)).ToArray(); + Select(v => Enum.Parse(v, true)).ToArray(); } /// @@ -426,7 +426,7 @@ namespace MediaBrowser.Api.UserLibrary return string.IsNullOrEmpty(val) ? new ImageType[] { } - : val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToArray(); + : val.Split(',').Select(v => Enum.Parse(v, true)).ToArray(); } /// @@ -462,7 +462,9 @@ namespace MediaBrowser.Api.UserLibrary var sortOrderIndex = sortOrders.Length > i ? i : 0; var sortOrderValue = sortOrders.Length > sortOrderIndex ? sortOrders[sortOrderIndex] : null; - var sortOrder = string.Equals(sortOrderValue, "Descending", StringComparison.OrdinalIgnoreCase) ? MediaBrowser.Model.Entities.SortOrder.Descending : MediaBrowser.Model.Entities.SortOrder.Ascending; + var sortOrder = string.Equals(sortOrderValue, "Descending", StringComparison.OrdinalIgnoreCase) + ? MediaBrowser.Model.Entities.SortOrder.Descending + : MediaBrowser.Model.Entities.SortOrder.Ascending; result[i] = new ValueTuple(vals[i], sortOrder); } diff --git a/MediaBrowser.Api/VideosService.cs b/MediaBrowser.Api/VideosService.cs index 76e9f421d0..b11fd48d3c 100644 --- a/MediaBrowser.Api/VideosService.cs +++ b/MediaBrowser.Api/VideosService.cs @@ -138,15 +138,23 @@ namespace MediaBrowser.Api var videosWithVersions = items.Where(i => i.MediaSourceCount > 1) .ToList(); - var primaryVersion = videosWithVersions.FirstOrDefault() ?? items.OrderBy(i - => (i.Video3DFormat.HasValue || i.VideoType != Model.Entities.VideoType.VideoFile) ? 1 : 0) - .ThenByDescending(i => - { - var stream = i.GetDefaultVideoStream(); + var primaryVersion = videosWithVersions.FirstOrDefault(); + if (primaryVersion == null) + { + primaryVersion = items.OrderBy(i => + { + if (i.Video3DFormat.HasValue || i.VideoType != Model.Entities.VideoType.VideoFile) + { + return 1; + } - return stream?.Width ?? 0; - - }).First(); + return 0; + }) + .ThenByDescending(i => + { + return i.GetDefaultVideoStream()?.Width ?? 0; + }).First(); + } var list = primaryVersion.LinkedAlternateVersions.ToList();