Merge pull request #1572 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-03-21 12:53:52 -04:00
commit b37500dca0
10 changed files with 188 additions and 258 deletions

View File

@ -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<IHasAlbumArtist>()
.Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
if (!ok)
{
return false;
}
}
return true;
}

View File

@ -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))
@ -310,6 +311,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<IHasAlbumArtist>()
.Any(p => string.Compare(request.AlbumArtistStartsWithOrGreater, p.AlbumArtists.FirstOrDefault(), StringComparison.CurrentCultureIgnoreCase) < 1);
if (!ok)
{
return false;
}
}
return true;
}
}

View File

@ -170,6 +170,17 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
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>()
where T : IScheduledTask
{

View File

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

View File

@ -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;
}

View File

@ -105,6 +105,7 @@ namespace MediaBrowser.Controller.Entities
internal List<Guid> 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[] { };

View File

@ -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<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;
}

View File

@ -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)

View File

@ -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)
{

View File

@ -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<ServerSyncScheduledTask>();
}
}
}