diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs index 4ff3dcf26a..15bdf4be62 100644 --- a/MediaBrowser.Api/Reports/ReportsService.cs +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -260,7 +260,8 @@ namespace MediaBrowser.Api.Reports MinCommunityRating = request.MinCommunityRating, MinCriticRating = request.MinCriticRating, ParentIndexNumber = request.ParentIndexNumber, - AiredDuringSeason = request.AiredDuringSeason + AiredDuringSeason = request.AiredDuringSeason, + AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater }; if (!string.IsNullOrWhiteSpace(request.Ids)) @@ -337,6 +338,30 @@ namespace MediaBrowser.Api.Reports query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); } + // Min official rating + if (!string.IsNullOrEmpty(request.MinOfficialRating)) + { + query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Max official rating + if (!string.IsNullOrEmpty(request.MaxOfficialRating)) + { + query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Artists + if (!string.IsNullOrEmpty(request.Artists)) + { + query.ArtistNames = request.Artists.Split('|'); + } + + // Albums + if (!string.IsNullOrEmpty(request.Albums)) + { + query.AlbumNames = request.Albums.Split('|'); + } + if (request.HasQueryLimit == false) { query.StartIndex = null; @@ -365,129 +390,6 @@ namespace MediaBrowser.Api.Reports } } - // Artists - if (!string.IsNullOrEmpty(request.Artists)) - { - var artists = request.Artists.Split('|'); - - var audio = i as IHasArtist; - - if (!(audio != null && artists.Any(audio.HasAnyArtist))) - { - return false; - } - } - - // Albums - if (!string.IsNullOrEmpty(request.Albums)) - { - var albums = request.Albums.Split('|'); - - var audio = i as Audio; - - if (audio != null) - { - if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var album = i as MusicAlbum; - - if (album != null) - { - if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var musicVideo = i as MusicVideo; - - if (musicVideo != null) - { - if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - return false; - } - - // Min index number - if (request.MinIndexNumber.HasValue) - { - if (!(i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value)) - { - return false; - } - } - - // Min official rating - if (!string.IsNullOrEmpty(request.MinOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MinOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value)) - { - return false; - } - } - } - } - - // Max official rating - if (!string.IsNullOrEmpty(request.MaxOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MaxOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value)) - { - return false; - } - } - } - } - - if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater)) - { - var ok = new[] { i }.OfType() - .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1); - - if (!ok) - { - return false; - } - } - return true; } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index c54f259733..566b1dfd5c 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -233,7 +233,8 @@ namespace MediaBrowser.Api.UserLibrary MinCriticRating = request.MinCriticRating, ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId), ParentIndexNumber = request.ParentIndexNumber, - AiredDuringSeason = request.AiredDuringSeason + AiredDuringSeason = request.AiredDuringSeason, + AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater }; if (!string.IsNullOrWhiteSpace(request.Ids)) @@ -309,6 +310,30 @@ namespace MediaBrowser.Api.UserLibrary { query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray(); } + + // Min official rating + if (!string.IsNullOrEmpty(request.MinOfficialRating)) + { + query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Max official rating + if (!string.IsNullOrEmpty(request.MaxOfficialRating)) + { + query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating); + } + + // Artists + if (!string.IsNullOrEmpty(request.Artists)) + { + query.ArtistNames = request.Artists.Split('|'); + } + + // Albums + if (!string.IsNullOrEmpty(request.Albums)) + { + query.AlbumNames = request.Albums.Split('|'); + } return query; } @@ -332,120 +357,6 @@ namespace MediaBrowser.Api.UserLibrary } } - // Artists - if (!string.IsNullOrEmpty(request.Artists)) - { - var artists = request.Artists.Split('|'); - - var audio = i as IHasArtist; - - if (!(audio != null && artists.Any(audio.HasAnyArtist))) - { - return false; - } - } - - // Albums - if (!string.IsNullOrEmpty(request.Albums)) - { - var albums = request.Albums.Split('|'); - - var audio = i as Audio; - - if (audio != null) - { - if (!albums.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var album = i as MusicAlbum; - - if (album != null) - { - if (!albums.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - var musicVideo = i as MusicVideo; - - if (musicVideo != null) - { - if (!albums.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - } - - return false; - } - - // Min official rating - if (!string.IsNullOrEmpty(request.MinOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MinOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value >= level.Value)) - { - return false; - } - } - } - } - - // Max official rating - if (!string.IsNullOrEmpty(request.MaxOfficialRating)) - { - var level = _localization.GetRatingLevel(request.MaxOfficialRating); - - if (level.HasValue) - { - var rating = i.CustomRating; - - if (string.IsNullOrEmpty(rating)) - { - rating = i.OfficialRating; - } - - if (!string.IsNullOrEmpty(rating)) - { - var itemLevel = _localization.GetRatingLevel(rating); - - if (!(!itemLevel.HasValue || itemLevel.Value <= level.Value)) - { - return false; - } - } - } - } - - if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater)) - { - var ok = new[] { i }.OfType() - .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1); - - if (!ok) - { - return false; - } - } - return true; } } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index b5566650ca..f3316646bb 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -170,6 +170,17 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks QueueScheduledTask(new TaskExecutionOptions()); } + public void QueueIfNotRunning() + where T : IScheduledTask + { + var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T)); + + if (task.State != TaskState.Running) + { + QueueScheduledTask(new TaskExecutionOptions()); + } + } + public void Execute() where T : IScheduledTask { diff --git a/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs b/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs index c1dc304f65..f1809c4516 100644 --- a/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs +++ b/MediaBrowser.Common/ScheduledTasks/ITaskManager.cs @@ -50,6 +50,9 @@ namespace MediaBrowser.Common.ScheduledTasks void QueueScheduledTask() where T : IScheduledTask; + void QueueIfNotRunning() + where T : IScheduledTask; + /// /// Queues the scheduled task. /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index dc0a8d0aa3..fa96ba4e51 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -979,12 +979,6 @@ namespace MediaBrowser.Controller.Entities return true; } - if (query.HasOverview.HasValue) - { - Logger.Debug("Query requires post-filtering due to HasOverview"); - return true; - } - if (query.HasImdbId.HasValue) { Logger.Debug("Query requires post-filtering due to HasImdbId"); @@ -1078,13 +1072,6 @@ namespace MediaBrowser.Controller.Entities return true; } - // Apply official rating filter - if (query.OfficialRatings.Length > 0) - { - Logger.Debug("Query requires post-filtering due to OfficialRatings"); - return true; - } - // Apply person filter if (query.ItemIdsFromPersonFilters != null) { @@ -1104,12 +1091,6 @@ namespace MediaBrowser.Controller.Entities return true; } - if (query.MinIndexNumber.HasValue) - { - Logger.Debug("Query requires post-filtering due to MinIndexNumber"); - return true; - } - if (query.OfficialRatings.Length > 0) { Logger.Debug("Query requires post-filtering due to OfficialRatings"); @@ -1188,6 +1169,24 @@ namespace MediaBrowser.Controller.Entities return true; } + if (!string.IsNullOrWhiteSpace(query.AlbumArtistStartsWithOrGreater)) + { + Logger.Debug("Query requires post-filtering due to AlbumArtistStartsWithOrGreater"); + return true; + } + + if (query.AlbumNames.Length > 0) + { + Logger.Debug("Query requires post-filtering due to AlbumNames"); + return true; + } + + if (query.ArtistNames.Length > 0) + { + Logger.Debug("Query requires post-filtering due to ArtistNames"); + return true; + } + return false; } diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 2f98ac70df..b568aec180 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -105,6 +105,7 @@ namespace MediaBrowser.Controller.Entities internal List ItemIdsFromPersonFilters { get; set; } public int? ParentIndexNumber { get; set; } + public int? MinParentalRating { get; set; } public int? MaxParentalRating { get; set; } public bool? IsCurrentSchema { get; set; } @@ -125,9 +126,16 @@ namespace MediaBrowser.Controller.Entities public DayOfWeek[] AirDays { get; set; } public SeriesStatus[] SeriesStatuses { get; set; } + public string AlbumArtistStartsWithOrGreater { get; set; } + + public string[] AlbumNames { get; set; } + public string[] ArtistNames { get; set; } public InternalItemsQuery() { + AlbumNames = new string[] { }; + ArtistNames = new string[] { }; + BlockUnratedItems = new UnratedItem[] { }; Tags = new string[] { }; OfficialRatings = new string[] { }; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 645e6e37d2..a74859a469 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1199,6 +1199,11 @@ namespace MediaBrowser.Controller.Entities return false; } + if (query.ExcludeLocationTypes.Length > 0 && query.ExcludeLocationTypes.Contains(item.LocationType)) + { + return false; + } + if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder) { return false; @@ -1752,6 +1757,64 @@ namespace MediaBrowser.Controller.Entities } } + if (!string.IsNullOrEmpty(query.AlbumArtistStartsWithOrGreater)) + { + var ok = new[] { item }.OfType() + .Any(p => string.Compare(query.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1); + + if (!ok) + { + return false; + } + } + + // Artists + if (query.ArtistNames.Length > 0) + { + var audio = item as IHasArtist; + + if (!(audio != null && query.ArtistNames.Any(audio.HasAnyArtist))) + { + return false; + } + } + + // Albums + if (query.AlbumNames.Length > 0) + { + var audio = item as Audio.Audio; + + if (audio != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, audio.Album, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + var album = item as MusicAlbum; + + if (album != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, album.Name, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + var musicVideo = item as MusicVideo; + + if (musicVideo != null) + { + if (!query.AlbumNames.Any(a => string.Equals(a, musicVideo.Album, StringComparison.OrdinalIgnoreCase))) + { + return false; + } + } + + return false; + } + return true; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e17b7d953e..a6e92171f8 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -2062,6 +2062,12 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add(clause); } + if (query.MinParentalRating.HasValue) + { + whereClauses.Add("InheritedParentalRatingValue<=@MinParentalRating"); + cmd.Parameters.Add(cmd, "@MinParentalRating", DbType.Int32).Value = query.MinParentalRating.Value; + } + if (query.MaxParentalRating.HasValue) { whereClauses.Add("InheritedParentalRatingValue<=@MaxParentalRating"); @@ -2080,6 +2086,18 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + if (query.HasOverview.HasValue) + { + if (query.HasOverview.Value) + { + whereClauses.Add("(Overview not null AND Overview<>'')"); + } + else + { + whereClauses.Add("(Overview is null OR Overview='')"); + } + } + if (query.HasDeadParentId.HasValue) { if (query.HasDeadParentId.Value) diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index 7086735c09..f553c8ea82 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -641,6 +641,8 @@ namespace MediaBrowser.Server.Implementations.Sync ReadInputAtNativeFramerate = !syncOptions.EnableFullSpeedTranscoding }, innerProgress, cancellationToken); + + _syncManager.OnConversionComplete(jobItem, job); } catch (OperationCanceledException) { @@ -825,6 +827,8 @@ namespace MediaBrowser.Server.Implementations.Sync CpuCoreLimit = syncOptions.TranscodingCpuCoreLimit }, innerProgress, cancellationToken); + + _syncManager.OnConversionComplete(jobItem, job); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index e22f86b117..fbbc6082ae 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -1325,5 +1325,16 @@ namespace MediaBrowser.Server.Implementations.Sync return list; } + + protected internal void OnConversionComplete(SyncJobItem item, SyncJob job) + { + var syncProvider = GetSyncProvider(item, job); + if (syncProvider is AppSyncProvider) + { + return; + } + + _taskManager.QueueIfNotRunning(); + } } }