From cb26cb94579b772fa7825c6769dc7ace38217168 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 10 Oct 2016 14:18:28 -0400 Subject: [PATCH] update program queries --- MediaBrowser.Api/FilterService.cs | 7 +++- MediaBrowser.Api/GamesService.cs | 2 +- MediaBrowser.Api/Movies/MoviesService.cs | 12 +++--- MediaBrowser.Api/SimilarItemsHelper.cs | 2 +- MediaBrowser.Api/TvShowsService.cs | 4 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 2 +- .../Entities/InternalItemsQuery.cs | 9 +++-- MediaBrowser.Controller/LiveTv/LiveStream.cs | 15 +++---- MediaBrowser.Model/Dto/MediaSourceInfo.cs | 2 - .../Collections/CollectionManager.cs | 40 +++---------------- .../Library/SearchEngine.cs | 1 + .../LiveTv/EmbyTV/EmbyTV.cs | 24 +++++------ .../LiveTv/LiveTvManager.cs | 6 +-- .../Persistence/SqliteItemRepository.cs | 14 +++++-- .../Native/BaseMonoApp.cs | 5 --- .../ApplicationHost.cs | 14 +------ .../INativeApp.cs | 2 - .../Native/WindowsApp.cs | 11 ----- 18 files changed, 64 insertions(+), 108 deletions(-) diff --git a/MediaBrowser.Api/FilterService.cs b/MediaBrowser.Api/FilterService.cs index 557b1c625..57aa5575f 100644 --- a/MediaBrowser.Api/FilterService.cs +++ b/MediaBrowser.Api/FilterService.cs @@ -106,7 +106,12 @@ namespace MediaBrowser.Api IncludeItemTypes = request.GetIncludeItemTypes(), Recursive = true, EnableTotalRecordCount = false, - Fields = new List { ItemFields.Genres, ItemFields.Tags } + DtoOptions = new Controller.Dto.DtoOptions + { + Fields = new List { ItemFields.Genres, ItemFields.Tags }, + EnableImages = false, + EnableUserData = false + } }; return query; diff --git a/MediaBrowser.Api/GamesService.cs b/MediaBrowser.Api/GamesService.cs index a2e065f30..efa69d333 100644 --- a/MediaBrowser.Api/GamesService.cs +++ b/MediaBrowser.Api/GamesService.cs @@ -210,7 +210,7 @@ namespace MediaBrowser.Api typeof(Game).Name }, SimilarTo = item, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).ToList(); diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index dac4e9b50..559bca755 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Movies IsMovie = true, SimilarTo = item, EnableGroupByMetadataKey = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).ToList(); @@ -200,7 +200,7 @@ namespace MediaBrowser.Api.Movies ParentId = parentIdGuid, Recursive = true, IsPlayed = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }; var recentlyPlayedMovies = _libraryManager.GetItemList(query).ToList(); @@ -224,7 +224,7 @@ namespace MediaBrowser.Api.Movies EnableGroupByMetadataKey = true, ParentId = parentIdGuid, Recursive = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).ToList(); @@ -306,7 +306,7 @@ namespace MediaBrowser.Api.Movies IncludeItemTypes = itemTypes.ToArray(), IsMovie = true, EnableGroupByMetadataKey = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N")) .Take(itemLimit) @@ -344,7 +344,7 @@ namespace MediaBrowser.Api.Movies IncludeItemTypes = itemTypes.ToArray(), IsMovie = true, EnableGroupByMetadataKey = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).DistinctBy(i => i.GetProviderId(MetadataProviders.Imdb) ?? Guid.NewGuid().ToString("N")) .Take(itemLimit) @@ -381,7 +381,7 @@ namespace MediaBrowser.Api.Movies IsMovie = true, SimilarTo = item, EnableGroupByMetadataKey = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).ToList(); diff --git a/MediaBrowser.Api/SimilarItemsHelper.cs b/MediaBrowser.Api/SimilarItemsHelper.cs index 65cd3eaab..ddcb6b7bf 100644 --- a/MediaBrowser.Api/SimilarItemsHelper.cs +++ b/MediaBrowser.Api/SimilarItemsHelper.cs @@ -82,7 +82,7 @@ namespace MediaBrowser.Api { IncludeItemTypes = includeTypes.Select(i => i.Name).ToArray(), Recursive = true, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }; // ExcludeArtistIds diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 8c5d1c2f5..ef93d2fc9 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -312,7 +312,7 @@ namespace MediaBrowser.Api typeof(Series).Name }, SimilarTo = item, - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }).ToList(); @@ -346,7 +346,7 @@ namespace MediaBrowser.Api Limit = request.Limit, ParentId = parentIdGuid, Recursive = true, - Fields = options.Fields + DtoOptions = options }).ToList(); diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index eabb2ab8f..6a9b5631b 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -239,7 +239,7 @@ namespace MediaBrowser.Api.UserLibrary AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater, EnableTotalRecordCount = request.EnableTotalRecordCount, ExcludeItemIds = request.GetExcludeItemIds(), - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }; if (!string.IsNullOrWhiteSpace(request.Ids)) diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 444f472ab..f375e1b1c 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using MediaBrowser.Model.Configuration; using System.Linq; +using MediaBrowser.Controller.Dto; using MediaBrowser.Model.Querying; namespace MediaBrowser.Controller.Entities @@ -159,10 +160,12 @@ namespace MediaBrowser.Controller.Entities public DateTime? MinDateCreated { get; set; } public DateTime? MinDateLastSaved { get; set; } - public List Fields { get; set; } + public DtoOptions DtoOptions { get; set; } public bool HasField(ItemFields name) { + var fields = DtoOptions.Fields; + switch (name) { case ItemFields.ProductionLocations: @@ -185,7 +188,7 @@ namespace MediaBrowser.Controller.Entities case ItemFields.Tags: case ItemFields.DateLastMediaAdded: case ItemFields.CriticRatingSummary: - return Fields.Count == 0 || Fields.Contains(name); + return fields.Count == 0 || fields.Contains(name); default: return true; } @@ -196,7 +199,7 @@ namespace MediaBrowser.Controller.Entities GroupByPresentationUniqueKey = true; EnableTotalRecordCount = true; - Fields = new List(); + DtoOptions = new DtoOptions(); AlbumNames = new string[] { }; ArtistNames = new string[] { }; ExcludeArtistIds = new string[] { }; diff --git a/MediaBrowser.Controller/LiveTv/LiveStream.cs b/MediaBrowser.Controller/LiveTv/LiveStream.cs index a5d432a54..0908c3ecc 100644 --- a/MediaBrowser.Controller/LiveTv/LiveStream.cs +++ b/MediaBrowser.Controller/LiveTv/LiveStream.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Dto; @@ -9,13 +10,16 @@ namespace MediaBrowser.Controller.LiveTv { public MediaSourceInfo OriginalMediaSource { get; set; } public MediaSourceInfo OpenedMediaSource { get; set; } - public DateTime DateOpened { get; set; } - public int ConsumerCount { get; set; } + public int ConsumerCount { + get { return SharedStreamIds.Count; } + } public ITunerHost TunerHost { get; set; } public string OriginalStreamId { get; set; } public bool EnableStreamSharing { get; set; } public string UniqueId = Guid.NewGuid().ToString("N"); + public List SharedStreamIds = new List(); + public LiveStream(MediaSourceInfo mediaSource) { OriginalMediaSource = mediaSource; @@ -23,12 +27,9 @@ namespace MediaBrowser.Controller.LiveTv EnableStreamSharing = true; } - public async Task Open(CancellationToken cancellationToken) + public Task Open(CancellationToken cancellationToken) { - await OpenInternal(cancellationToken).ConfigureAwait(false); - DateOpened = DateTime.UtcNow; - - OpenedMediaSource.DateLiveStreamOpened = DateOpened; + return OpenInternal(cancellationToken); } protected virtual Task OpenInternal(CancellationToken cancellationToken) diff --git a/MediaBrowser.Model/Dto/MediaSourceInfo.cs b/MediaBrowser.Model/Dto/MediaSourceInfo.cs index 1c7875890..8149e3ff5 100644 --- a/MediaBrowser.Model/Dto/MediaSourceInfo.cs +++ b/MediaBrowser.Model/Dto/MediaSourceInfo.cs @@ -54,8 +54,6 @@ namespace MediaBrowser.Model.Dto public string TranscodingSubProtocol { get; set; } public string TranscodingContainer { get; set; } - public DateTime? DateLiveStreamOpened { get; set; } - public MediaSourceInfo() { Formats = new List(); diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 1b6c44c5e..cb2bd645d 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -219,7 +219,9 @@ namespace MediaBrowser.Server.Implementations.Collections foreach (var itemId in itemIds) { - var child = collection.LinkedChildren.FirstOrDefault(i => i.ItemId.HasValue && i.ItemId.Value == itemId); + var childItem = _libraryManager.GetItemById(itemId); + + var child = collection.LinkedChildren.FirstOrDefault(i => (i.ItemId.HasValue && i.ItemId.Value == itemId) || (childItem != null && string.Equals(childItem.Path, i.Path, StringComparison.OrdinalIgnoreCase))); if (child == null) { @@ -228,47 +230,15 @@ namespace MediaBrowser.Server.Implementations.Collections list.Add(child); - var childItem = _libraryManager.GetItemById(itemId); - if (childItem != null) { itemList.Add(childItem); } } - var shortcutFiles = _fileSystem - .GetFilePaths(collection.Path) - .Where(i => _fileSystem.IsShortcut(i)) - .ToList(); - - var shortcutFilesToDelete = list.Where(child => !string.IsNullOrWhiteSpace(child.Path) && child.Type == LinkedChildType.Shortcut) - .Select(child => shortcutFiles.FirstOrDefault(i => string.Equals(child.Path, _fileSystem.ResolveShortcut(i), StringComparison.OrdinalIgnoreCase))) - .Where(i => !string.IsNullOrWhiteSpace(i)) - .ToList(); - - foreach (var file in shortcutFilesToDelete) + foreach (var child in list) { - _iLibraryMonitor.ReportFileSystemChangeBeginning(file); - } - - try - { - foreach (var file in shortcutFilesToDelete) - { - _fileSystem.DeleteFile(file); - } - - foreach (var child in list) - { - collection.LinkedChildren.Remove(child); - } - } - finally - { - foreach (var file in shortcutFilesToDelete) - { - _iLibraryMonitor.ReportFileSystemChangeComplete(file, false); - } + collection.LinkedChildren.Remove(child); } collection.UpdateRatingToContent(); diff --git a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs index a6d6b5cb8..40cca7bab 100644 --- a/MediaBrowser.Server.Implementations/Library/SearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/SearchEngine.cs @@ -105,6 +105,7 @@ namespace MediaBrowser.Server.Implementations.Library var includeItemTypes = (query.IncludeItemTypes ?? new string[] { }).ToList(); excludeItemTypes.Add(typeof(Year).Name); + excludeItemTypes.Add(typeof(Folder).Name); if (query.IncludeGenres && (includeItemTypes.Count == 0 || includeItemTypes.Contains("Genre", StringComparer.OrdinalIgnoreCase))) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index ee8d40797..9781775d5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -882,7 +882,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } private readonly SemaphoreSlim _liveStreamsSemaphore = new SemaphoreSlim(1, 1); - private readonly Dictionary _liveStreams = new Dictionary(); + private readonly List _liveStreams = new List(); public async Task GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken) { @@ -921,7 +921,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { - return _liveStreams.Values + return _liveStreams .FirstOrDefault(i => string.Equals(i.UniqueId, uniqueId, StringComparison.OrdinalIgnoreCase)); } finally @@ -937,16 +937,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV await _liveStreamsSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); - var result = _liveStreams.Values.FirstOrDefault(i => string.Equals(i.OriginalStreamId, streamId, StringComparison.OrdinalIgnoreCase)); + var result = _liveStreams.FirstOrDefault(i => string.Equals(i.OriginalStreamId, streamId, StringComparison.OrdinalIgnoreCase)); if (result != null && result.EnableStreamSharing) { - result.ConsumerCount++; + var openedMediaSource = CloneMediaSource(result.OpenedMediaSource, result.EnableStreamSharing); + result.SharedStreamIds.Add(openedMediaSource.Id); + _liveStreamsSemaphore.Release(); _logger.Info("Live stream {0} consumer count is now {1}", streamId, result.ConsumerCount); - var openedMediaSource = CloneMediaSource(result.OpenedMediaSource, result.EnableStreamSharing); - _liveStreamsSemaphore.Release(); return new Tuple(result, openedMediaSource, result.TunerHost); } @@ -960,9 +960,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV var openedMediaSource = CloneMediaSource(result.OpenedMediaSource, result.EnableStreamSharing); - _liveStreams[openedMediaSource.Id] = result; + result.SharedStreamIds.Add(openedMediaSource.Id); + _liveStreams.Add(result); - result.ConsumerCount++; result.TunerHost = hostInstance; result.OriginalStreamId = streamId; @@ -1047,16 +1047,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { - LiveStream stream; - if (_liveStreams.TryGetValue(id, out stream)) + var stream = _liveStreams.FirstOrDefault(i => i.SharedStreamIds.Contains(id)); + if (stream != null) { - stream.ConsumerCount--; + stream.SharedStreamIds.Remove(id); _logger.Info("Live stream {0} consumer count is now {1}", id, stream.ConsumerCount); if (stream.ConsumerCount <= 0) { - _liveStreams.Remove(id); + _liveStreams.Remove(stream); _logger.Info("Closing live stream {0}", id); diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index cf441f58e..a295320ec 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -871,7 +871,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv SortOrder = query.SortOrder ?? SortOrder.Ascending, EnableTotalRecordCount = query.EnableTotalRecordCount, TopParentIds = new[] { topFolder.Id.ToString("N") }, - Fields = options.Fields + DtoOptions = options }; if (!string.IsNullOrWhiteSpace(query.SeriesTimerId)) @@ -940,7 +940,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv EnableTotalRecordCount = query.EnableTotalRecordCount, SortBy = new[] { ItemSortBy.StartDate }, TopParentIds = new[] { topFolder.Id.ToString("N") }, - Fields = options.Fields + DtoOptions = options }; if (query.Limit.HasValue) @@ -1566,7 +1566,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv IncludeItemTypes = includeItemTypes.ToArray(), ExcludeItemTypes = excludeItemTypes.ToArray(), Genres = genres.ToArray(), - Fields = dtoOptions.Fields + DtoOptions = dtoOptions }); } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 1e3ec22fd..1656d8304 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1857,11 +1857,14 @@ namespace MediaBrowser.Server.Implementations.Persistence } index++; - if (!reader.IsDBNull(index)) + if (query.DtoOptions.EnableImages) { - DeserializeImages(reader.GetString(index), item); + if (!reader.IsDBNull(index)) + { + DeserializeImages(reader.GetString(index), item); + } + index++; } - index++; if (query.HasField(ItemFields.ProductionLocations)) { @@ -2259,6 +2262,11 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (!query.DtoOptions.EnableImages) + { + list.Remove("Images"); + } + if (EnableJoinUserData(query)) { list.Add("UserDataDb.UserData.UserId"); diff --git a/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs index d2a544477..73e2686d2 100644 --- a/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs +++ b/MediaBrowser.Server.Mono/Native/BaseMonoApp.cs @@ -277,10 +277,5 @@ namespace MediaBrowser.Server.Mono.Native { } - - public bool PortsRequireAuthorization(string applicationPath) - { - return false; - } } } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 39f4d26de..0553f8581 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -966,19 +966,7 @@ namespace MediaBrowser.Server.Startup.Common /// protected override void FindParts() { - var isAuthorized = ServerConfigurationManager.Configuration.IsPortAuthorized; - if (isAuthorized) - { - try - { - isAuthorized = !NativeApp.PortsRequireAuthorization(ConfigurationManager.CommonApplicationPaths.ApplicationPath); - } - catch - { - - } - } - if (!isAuthorized) + if (!ServerConfigurationManager.Configuration.IsPortAuthorized) { RegisterServerWithAdministratorAccess(); ServerConfigurationManager.Configuration.IsPortAuthorized = true; diff --git a/MediaBrowser.Server.Startup.Common/INativeApp.cs b/MediaBrowser.Server.Startup.Common/INativeApp.cs index bf8314d13..c56bb9b4b 100644 --- a/MediaBrowser.Server.Startup.Common/INativeApp.cs +++ b/MediaBrowser.Server.Startup.Common/INativeApp.cs @@ -24,8 +24,6 @@ namespace MediaBrowser.Server.Startup.Common /// The temporary directory. void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory); - bool PortsRequireAuthorization(string applicationPath); - /// /// Gets the environment. /// diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/Native/WindowsApp.cs index 1e50ac85e..7ebede40c 100644 --- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs +++ b/MediaBrowser.ServerApplication/Native/WindowsApp.cs @@ -204,16 +204,6 @@ namespace MediaBrowser.ServerApplication.Native LoopUtil.Run(appName); } - private bool Confirm() - { - if (MainStartup._splash == null) - { - return false; - } - - return MessageBox.Show(MainStartup._splash, "Emby has detected that a rule has been added to Windows Firewall that may prevent your other devices from accessing Emby Server. Click OK to remove this rule, or cancel to proceed anyway.", "Windows Firewall", MessageBoxButtons.OKCancel) == DialogResult.OK; - } - public bool PortsRequireAuthorization(string applicationPath) { var appNameSrch = Path.GetFileName(applicationPath); @@ -242,7 +232,6 @@ namespace MediaBrowser.ServerApplication.Native if (data.IndexOf("Block", StringComparison.OrdinalIgnoreCase) != -1) { _logger.Info("Found potential windows firewall rule blocking Emby Server: " + data); - return Confirm(); } //var parts = data.Split('\n');