ソースを参照

Merge pull request #1572 from MediaBrowser/dev

Dev
Luke 9 年 前
コミット
b37500dca0

+ 26 - 124
MediaBrowser.Api/Reports/ReportsService.cs

@@ -260,7 +260,8 @@ namespace MediaBrowser.Api.Reports
                 MinCommunityRating = request.MinCommunityRating,
                 MinCommunityRating = request.MinCommunityRating,
                 MinCriticRating = request.MinCriticRating,
                 MinCriticRating = request.MinCriticRating,
                 ParentIndexNumber = request.ParentIndexNumber,
                 ParentIndexNumber = request.ParentIndexNumber,
-                AiredDuringSeason = request.AiredDuringSeason
+                AiredDuringSeason = request.AiredDuringSeason,
+                AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater
             };
             };
 
 
             if (!string.IsNullOrWhiteSpace(request.Ids))
             if (!string.IsNullOrWhiteSpace(request.Ids))
@@ -337,152 +338,53 @@ namespace MediaBrowser.Api.Reports
                 query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
                 query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
             }
             }
 
 
-            if (request.HasQueryLimit == false)
+            // Min official rating
+            if (!string.IsNullOrEmpty(request.MinOfficialRating))
             {
             {
-                query.StartIndex = null;
-                query.Limit = null;
+                query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
             }
             }
 
 
-            return query;
-        }
-
-        private bool ApplyAdditionalFilters(BaseReportRequest request, BaseItem i, User user, ILibraryManager libraryManager)
-        {
-            // Artists
-            if (!string.IsNullOrEmpty(request.ArtistIds))
+            // Max official rating
+            if (!string.IsNullOrEmpty(request.MaxOfficialRating))
             {
             {
-                var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
-
-                var audio = i as IHasArtist;
-
-                if (!(audio != null && artistIds.Any(id =>
-                {
-                    var artistItem = libraryManager.GetItemById(id);
-                    return artistItem != null && audio.HasAnyArtist(artistItem.Name);
-                })))
-                {
-                    return false;
-                }
+                query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
             }
             }
 
 
             // Artists
             // Artists
             if (!string.IsNullOrEmpty(request.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;
-                }
+                query.ArtistNames = request.Artists.Split('|');
             }
             }
 
 
             // Albums
             // Albums
             if (!string.IsNullOrEmpty(request.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;
+                query.AlbumNames = request.Albums.Split('|');
             }
             }
 
 
-            // Min index number
-            if (request.MinIndexNumber.HasValue)
+            if (request.HasQueryLimit == false)
             {
             {
-                if (!(i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value))
-                {
-                    return false;
-                }
+                query.StartIndex = null;
+                query.Limit = null;
             }
             }
 
 
-            // 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;
-                        }
-                    }
-                }
-            }
+            return query;
+        }
 
 
-            // Max official rating
-            if (!string.IsNullOrEmpty(request.MaxOfficialRating))
+        private bool ApplyAdditionalFilters(BaseReportRequest request, BaseItem i, User user, ILibraryManager libraryManager)
+        {
+            // Artists
+            if (!string.IsNullOrEmpty(request.ArtistIds))
             {
             {
-                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;
-                        }
-                    }
-                }
-            }
+                var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
 
 
-            if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
-            {
-                var ok = new[] { i }.OfType<IHasAlbumArtist>()
-                    .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
+                var audio = i as IHasArtist;
 
 
-                if (!ok)
+                if (!(audio != null && artistIds.Any(id =>
+                {
+                    var artistItem = libraryManager.GetItemById(id);
+                    return artistItem != null && audio.HasAnyArtist(artistItem.Name);
+                })))
                 {
                 {
                     return false;
                     return false;
                 }
                 }

+ 26 - 115
MediaBrowser.Api/UserLibrary/ItemsService.cs

@@ -233,7 +233,8 @@ namespace MediaBrowser.Api.UserLibrary
                 MinCriticRating = request.MinCriticRating,
                 MinCriticRating = request.MinCriticRating,
                 ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId),
                 ParentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId),
                 ParentIndexNumber = request.ParentIndexNumber,
                 ParentIndexNumber = request.ParentIndexNumber,
-                AiredDuringSeason = request.AiredDuringSeason
+                AiredDuringSeason = request.AiredDuringSeason,
+                AlbumArtistStartsWithOrGreater = request.AlbumArtistStartsWithOrGreater
             };
             };
 
 
             if (!string.IsNullOrWhiteSpace(request.Ids))
             if (!string.IsNullOrWhiteSpace(request.Ids))
@@ -309,138 +310,48 @@ namespace MediaBrowser.Api.UserLibrary
             {
             {
                 query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
                 query.LocationTypes = request.LocationTypes.Split(',').Select(d => (LocationType)Enum.Parse(typeof(LocationType), d, true)).ToArray();
             }
             }
-
-            return query;
-        }
-
-        private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, ILibraryManager libraryManager)
-        {
-            // Artists
-            if (!string.IsNullOrEmpty(request.ArtistIds))
+            
+            // Min official rating
+            if (!string.IsNullOrEmpty(request.MinOfficialRating))
             {
             {
-                var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
-
-                var audio = i as IHasArtist;
+                query.MinParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
+            }
 
 
-                if (!(audio != null && artistIds.Any(id =>
-                {
-                    var artistItem = libraryManager.GetItemById(id);
-                    return artistItem != null && audio.HasAnyArtist(artistItem.Name);
-                })))
-                {
-                    return false;
-                }
+            // Max official rating
+            if (!string.IsNullOrEmpty(request.MaxOfficialRating))
+            {
+                query.MaxParentalRating = _localization.GetRatingLevel(request.MinOfficialRating);
             }
             }
 
 
             // Artists
             // Artists
             if (!string.IsNullOrEmpty(request.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;
-                }
+                query.ArtistNames = request.Artists.Split('|');
             }
             }
 
 
             // Albums
             // Albums
             if (!string.IsNullOrEmpty(request.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;
+                query.AlbumNames = request.Albums.Split('|');
             }
             }
 
 
-            // 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;
-                        }
-                    }
-                }
-            }
+            return query;
+        }
 
 
-            // Max official rating
-            if (!string.IsNullOrEmpty(request.MaxOfficialRating))
+        private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, ILibraryManager libraryManager)
+        {
+            // Artists
+            if (!string.IsNullOrEmpty(request.ArtistIds))
             {
             {
-                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;
-                        }
-                    }
-                }
-            }
+                var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
 
 
-            if (!string.IsNullOrEmpty(request.AlbumArtistStartsWithOrGreater))
-            {
-                var ok = new[] { i }.OfType<IHasAlbumArtist>()
-                    .Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
+                var audio = i as IHasArtist;
 
 
-                if (!ok)
+                if (!(audio != null && artistIds.Any(id =>
+                {
+                    var artistItem = libraryManager.GetItemById(id);
+                    return artistItem != null && audio.HasAnyArtist(artistItem.Name);
+                })))
                 {
                 {
                     return false;
                     return false;
                 }
                 }

+ 11 - 0
MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs

@@ -170,6 +170,17 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
             QueueScheduledTask<T>(new TaskExecutionOptions());
             QueueScheduledTask<T>(new TaskExecutionOptions());
         }
         }
 
 
+        public void QueueIfNotRunning<T>()
+            where T : IScheduledTask
+        {
+            var task = ScheduledTasks.First(t => t.ScheduledTask.GetType() == typeof(T));
+
+            if (task.State != TaskState.Running)
+            {
+                QueueScheduledTask<T>(new TaskExecutionOptions());
+            }
+        }
+
         public void Execute<T>()
         public void Execute<T>()
             where T : IScheduledTask
             where T : IScheduledTask
         {
         {

+ 3 - 0
MediaBrowser.Common/ScheduledTasks/ITaskManager.cs

@@ -50,6 +50,9 @@ namespace MediaBrowser.Common.ScheduledTasks
         void QueueScheduledTask<T>()
         void QueueScheduledTask<T>()
             where T : IScheduledTask;
             where T : IScheduledTask;
 
 
+        void QueueIfNotRunning<T>()
+            where T : IScheduledTask;
+        
         /// <summary>
         /// <summary>
         /// Queues the scheduled task.
         /// Queues the scheduled task.
         /// </summary>
         /// </summary>

+ 18 - 19
MediaBrowser.Controller/Entities/Folder.cs

@@ -979,12 +979,6 @@ namespace MediaBrowser.Controller.Entities
                 return true;
                 return true;
             }
             }
 
 
-            if (query.HasOverview.HasValue)
-            {
-                Logger.Debug("Query requires post-filtering due to HasOverview");
-                return true;
-            }
-
             if (query.HasImdbId.HasValue)
             if (query.HasImdbId.HasValue)
             {
             {
                 Logger.Debug("Query requires post-filtering due to HasImdbId");
                 Logger.Debug("Query requires post-filtering due to HasImdbId");
@@ -1078,13 +1072,6 @@ namespace MediaBrowser.Controller.Entities
                 return true;
                 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
             // Apply person filter
             if (query.ItemIdsFromPersonFilters != null)
             if (query.ItemIdsFromPersonFilters != null)
             {
             {
@@ -1104,12 +1091,6 @@ namespace MediaBrowser.Controller.Entities
                 return true;
                 return true;
             }
             }
 
 
-            if (query.MinIndexNumber.HasValue)
-            {
-                Logger.Debug("Query requires post-filtering due to MinIndexNumber");
-                return true;
-            }
-
             if (query.OfficialRatings.Length > 0)
             if (query.OfficialRatings.Length > 0)
             {
             {
                 Logger.Debug("Query requires post-filtering due to OfficialRatings");
                 Logger.Debug("Query requires post-filtering due to OfficialRatings");
@@ -1188,6 +1169,24 @@ namespace MediaBrowser.Controller.Entities
                 return true;
                 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;
             return false;
         }
         }
 
 

+ 8 - 0
MediaBrowser.Controller/Entities/InternalItemsQuery.cs

@@ -105,6 +105,7 @@ namespace MediaBrowser.Controller.Entities
 
 
         internal List<Guid> ItemIdsFromPersonFilters { get; set; }
         internal List<Guid> ItemIdsFromPersonFilters { get; set; }
         public int? ParentIndexNumber { get; set; }
         public int? ParentIndexNumber { get; set; }
+        public int? MinParentalRating { get; set; }
         public int? MaxParentalRating { get; set; }
         public int? MaxParentalRating { get; set; }
 
 
         public bool? IsCurrentSchema { get; set; }
         public bool? IsCurrentSchema { get; set; }
@@ -125,9 +126,16 @@ namespace MediaBrowser.Controller.Entities
 
 
         public DayOfWeek[] AirDays { get; set; }
         public DayOfWeek[] AirDays { get; set; }
         public SeriesStatus[] SeriesStatuses { get; set; }
         public SeriesStatus[] SeriesStatuses { get; set; }
+        public string AlbumArtistStartsWithOrGreater { get; set; }
+
+        public string[] AlbumNames { get; set; }
+        public string[] ArtistNames { get; set; }
         
         
         public InternalItemsQuery()
         public InternalItemsQuery()
         {
         {
+            AlbumNames = new string[] { };
+            ArtistNames = new string[] { };
+            
             BlockUnratedItems = new UnratedItem[] { };
             BlockUnratedItems = new UnratedItem[] { };
             Tags = new string[] { };
             Tags = new string[] { };
             OfficialRatings = new string[] { };
             OfficialRatings = new string[] { };

+ 63 - 0
MediaBrowser.Controller/Entities/UserViewBuilder.cs

@@ -1199,6 +1199,11 @@ namespace MediaBrowser.Controller.Entities
                 return false;
                 return false;
             }
             }
 
 
+            if (query.ExcludeLocationTypes.Length > 0 && query.ExcludeLocationTypes.Contains(item.LocationType))
+            {
+                return false;
+            }
+
             if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder)
             if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder)
             {
             {
                 return false;
                 return false;
@@ -1752,6 +1757,64 @@ namespace MediaBrowser.Controller.Entities
                 }
                 }
             }
             }
 
 
+            if (!string.IsNullOrEmpty(query.AlbumArtistStartsWithOrGreater))
+            {
+                var ok = new[] { item }.OfType<IHasAlbumArtist>()
+                    .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;
             return true;
         }
         }
 
 

+ 18 - 0
MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs

@@ -2062,6 +2062,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 whereClauses.Add(clause);
                 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)
             if (query.MaxParentalRating.HasValue)
             {
             {
                 whereClauses.Add("InheritedParentalRatingValue<=@MaxParentalRating");
                 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.HasValue)
             {
             {
                 if (query.HasDeadParentId.Value)
                 if (query.HasDeadParentId.Value)

+ 4 - 0
MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs

@@ -641,6 +641,8 @@ namespace MediaBrowser.Server.Implementations.Sync
                         ReadInputAtNativeFramerate = !syncOptions.EnableFullSpeedTranscoding
                         ReadInputAtNativeFramerate = !syncOptions.EnableFullSpeedTranscoding
 
 
                     }, innerProgress, cancellationToken);
                     }, innerProgress, cancellationToken);
+
+                    _syncManager.OnConversionComplete(jobItem, job);
                 }
                 }
                 catch (OperationCanceledException)
                 catch (OperationCanceledException)
                 {
                 {
@@ -825,6 +827,8 @@ namespace MediaBrowser.Server.Implementations.Sync
                         CpuCoreLimit = syncOptions.TranscodingCpuCoreLimit
                         CpuCoreLimit = syncOptions.TranscodingCpuCoreLimit
 
 
                     }, innerProgress, cancellationToken);
                     }, innerProgress, cancellationToken);
+
+                    _syncManager.OnConversionComplete(jobItem, job);
                 }
                 }
                 catch (OperationCanceledException)
                 catch (OperationCanceledException)
                 {
                 {

+ 11 - 0
MediaBrowser.Server.Implementations/Sync/SyncManager.cs

@@ -1325,5 +1325,16 @@ namespace MediaBrowser.Server.Implementations.Sync
 
 
             return list;
             return list;
         }
         }
+
+        protected internal void OnConversionComplete(SyncJobItem item, SyncJob job)
+        {
+            var syncProvider = GetSyncProvider(item, job);
+            if (syncProvider is AppSyncProvider)
+            {
+                return;
+            }
+
+            _taskManager.QueueIfNotRunning<ServerSyncScheduledTask>();
+        }
     }
     }
 }
 }