Skip to content

Commit

Permalink
Merge pull request #2362 from MediaBrowser/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
LukePulverenti authored Dec 21, 2016
2 parents 23dbf0e + 6b7aecd commit 30e1702
Show file tree
Hide file tree
Showing 40 changed files with 297 additions and 208 deletions.
119 changes: 91 additions & 28 deletions Emby.Dlna/ContentDirectory/ControlHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Xml;
Expand Down Expand Up @@ -464,6 +465,16 @@ private Task<QueryResult<BaseItem>> GetChildrenSorted(BaseItem item, User user,

private async Task<QueryResult<ServerItem>> GetUserItems(BaseItem item, StubType? stubType, User user, SortCriteria sort, int? startIndex, int? limit)
{
if (item is MusicGenre)
{
return GetMusicGenreItems(item, null, user, sort, startIndex, limit);
}

if (item is MusicArtist)
{
return GetMusicArtistItems(item, null, user, sort, startIndex, limit);
}

if (stubType.HasValue)
{
if (stubType.Value == StubType.People)
Expand All @@ -476,7 +487,7 @@ private async Task<QueryResult<ServerItem>> GetUserItems(BaseItem item, StubType

var result = new QueryResult<ServerItem>
{
Items = items.Select(i => new ServerItem { Item = i, StubType = StubType.Folder }).ToArray(),
Items = items.Select(i => new ServerItem(i)).ToArray(),
TotalRecordCount = items.Length
};

Expand All @@ -494,41 +505,88 @@ private async Task<QueryResult<ServerItem>> GetUserItems(BaseItem item, StubType

var folder = (Folder)item;

var sortOrders = new List<string>();
if (!folder.IsPreSorted)
{
sortOrders.Add(ItemSortBy.SortName);
}

var queryResult = await folder.GetItems(new InternalItemsQuery
var query = new InternalItemsQuery
{
Limit = limit,
StartIndex = startIndex,
SortBy = sortOrders.ToArray(),
SortOrder = sort.SortOrder,
User = user,
IsMissing = false,
PresetViews = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Music },
ExcludeItemTypes = new[] { typeof(Game).Name, typeof(Book).Name },
PresetViews = new[] {CollectionType.Movies, CollectionType.TvShows, CollectionType.Music},
ExcludeItemTypes = new[] {typeof (Game).Name, typeof (Book).Name},
IsPlaceHolder = false
};

SetSorting(query, sort, folder.IsPreSorted);

var queryResult = await folder.GetItems(query).ConfigureAwait(false);

return ToResult(queryResult);
}

private QueryResult<ServerItem> GetMusicArtistItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit)
{
var query = new InternalItemsQuery(user)
{
Recursive = true,
ParentId = parentId,
ArtistIds = new[] { item.Id.ToString("N") },
IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
Limit = limit,
StartIndex = startIndex
};

SetSorting(query, sort, false);

var result = _libraryManager.GetItemsResult(query);

}).ConfigureAwait(false);
return ToResult(result);
}

private QueryResult<ServerItem> GetMusicGenreItems(BaseItem item, Guid? parentId, User user, SortCriteria sort, int? startIndex, int? limit)
{
var query = new InternalItemsQuery(user)
{
Recursive = true,
ParentId = parentId,
GenreIds = new[] {item.Id.ToString("N")},
IncludeItemTypes = new[] {typeof (MusicAlbum).Name},
Limit = limit,
StartIndex = startIndex
};

var serverItems = queryResult
SetSorting(query, sort, false);

var result = _libraryManager.GetItemsResult(query);

return ToResult(result);
}

private QueryResult<ServerItem> ToResult(QueryResult<BaseItem> result)
{
var serverItems = result
.Items
.Select(i => new ServerItem
{
Item = i
})
.Select(i => new ServerItem(i))
.ToArray();

return new QueryResult<ServerItem>
{
TotalRecordCount = queryResult.TotalRecordCount,
TotalRecordCount = result.TotalRecordCount,
Items = serverItems
};
}

private void SetSorting(InternalItemsQuery query, SortCriteria sort, bool isPreSorted)
{
var sortOrders = new List<string>();
if (!isPreSorted)
{
sortOrders.Add(ItemSortBy.SortName);
}

query.SortBy = sortOrders.ToArray();
query.SortOrder = sort.SortOrder;
}

private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int? startIndex, int? limit)
{
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
Expand All @@ -541,11 +599,7 @@ private QueryResult<ServerItem> GetItemsFromPerson(Person person, User user, int

});

var serverItems = itemsResult.Items.Select(i => new ServerItem
{
Item = i,
StubType = null
})
var serverItems = itemsResult.Items.Select(i => new ServerItem(i))
.ToArray();

return new QueryResult<ServerItem>
Expand All @@ -566,7 +620,7 @@ private ServerItem GetItemFromObjectId(string id, User user)
{
return DidlBuilder.IsIdRoot(id)

? new ServerItem { Item = user.RootFolder }
? new ServerItem(user.RootFolder)
: ParseItemId(id, user);
}

Expand Down Expand Up @@ -601,23 +655,32 @@ private ServerItem ParseItemId(string id, User user)
{
var item = _libraryManager.GetItemById(itemId);

return new ServerItem
return new ServerItem(item)
{
Item = item,
StubType = stubType
};
}

Logger.Error("Error parsing item Id: {0}. Returning user root folder.", id);

return new ServerItem { Item = user.RootFolder };
return new ServerItem(user.RootFolder);
}
}

internal class ServerItem
{
public BaseItem Item { get; set; }
public StubType? StubType { get; set; }

public ServerItem(BaseItem item)
{
Item = item;

if (item is IItemByName && !(item is Folder))
{
StubType = Dlna.ContentDirectory.StubType.Folder;
}
}
}

public enum StubType
Expand Down
27 changes: 6 additions & 21 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3855,16 +3855,18 @@ private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statem
}
}

if (query.ArtistNames.Length > 0)
if (query.ArtistIds.Length > 0)
{
var clauses = new List<string>();
var index = 0;
foreach (var artist in query.ArtistNames)
foreach (var artistId in query.ArtistIds)
{
clauses.Add("@ArtistName" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type <= 1)");
var paramName = "@ArtistIds" + index;

clauses.Add("(select CleanName from TypedBaseItems where guid=" + paramName + ") in (select CleanValue from itemvalues where ItemId=Guid and Type<=1)");
if (statement != null)
{
statement.TryBind("@ArtistName" + index, GetCleanValue(artist));
statement.TryBind(paramName, artistId.ToGuidParamValue());
}
index++;
}
Expand Down Expand Up @@ -3963,23 +3965,6 @@ private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statem
whereClauses.Add(clause);
}

if (query.Studios.Length > 0)
{
var clauses = new List<string>();
var index = 0;
foreach (var item in query.Studios)
{
clauses.Add("@Studio" + index + " in (select CleanValue from itemvalues where ItemId=Guid and Type=3)");
if (statement != null)
{
statement.TryBind("@Studio" + index, GetCleanValue(item));
}
index++;
}
var clause = "(" + string.Join(" OR ", clauses.ToArray()) + ")";
whereClauses.Add(clause);
}

if (query.Keywords.Length > 0)
{
var clauses = new List<string>();
Expand Down
23 changes: 13 additions & 10 deletions Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProg
{
epgData = GetEpgDataForChannel(timer.ChannelId);
}
await UpdateTimersForSeriesTimer(epgData, timer, true).ConfigureAwait(false);
await UpdateTimersForSeriesTimer(epgData, timer, false, true).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task<string> CreateSeriesTimer(SeriesTimerInfo info, CancellationTo
}

_seriesTimerProvider.Add(info);
await UpdateTimersForSeriesTimer(epgData, info, false).ConfigureAwait(false);
await UpdateTimersForSeriesTimer(epgData, info, true, false).ConfigureAwait(false);

return info.Id;
}
Expand Down Expand Up @@ -614,7 +614,7 @@ public async Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken
epgData = GetEpgDataForChannel(instance.ChannelId);
}

await UpdateTimersForSeriesTimer(epgData, instance, true).ConfigureAwait(false);
await UpdateTimersForSeriesTimer(epgData, instance, true, true).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -2159,7 +2159,7 @@ private void SearchForDuplicateShowIds(List<TimerInfo> timers)
}
}

private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesTimerInfo seriesTimer, bool deleteInvalidTimers)
private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesTimerInfo seriesTimer, bool updateTimerSettings, bool deleteInvalidTimers)
{
var allTimers = GetTimersForSeries(seriesTimer, epgData)
.ToList();
Expand Down Expand Up @@ -2204,12 +2204,15 @@ private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesT
enabledTimersForSeries.Add(existingTimer);
}

existingTimer.KeepUntil = seriesTimer.KeepUntil;
existingTimer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired;
existingTimer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired;
existingTimer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds;
existingTimer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds;
existingTimer.Priority = seriesTimer.Priority;
if (updateTimerSettings)
{
existingTimer.KeepUntil = seriesTimer.KeepUntil;
existingTimer.IsPostPaddingRequired = seriesTimer.IsPostPaddingRequired;
existingTimer.IsPrePaddingRequired = seriesTimer.IsPrePaddingRequired;
existingTimer.PostPaddingSeconds = seriesTimer.PostPaddingSeconds;
existingTimer.PrePaddingSeconds = seriesTimer.PrePaddingSeconds;
existingTimer.Priority = seriesTimer.Priority;
}

existingTimer.SeriesTimerId = seriesTimer.Id;
_timerProvider.Update(existingTimer);
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/LiveTv/LiveTvManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ public async Task<QueryResult<BaseItem>> GetInternalRecordings(RecordingQuery qu
return new QueryResult<BaseItem>();
}

if (_services.Count == 1 && !(query.IsInProgress ?? false))
if (_services.Count == 1 && !(query.IsInProgress ?? false) && (!query.IsLibraryItem.HasValue || query.IsLibraryItem.Value))
{
return GetEmbyRecordings(query, new DtoOptions(), user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public async Task Run()
{
Task.Run(() =>
{
var task = _taskManager.ScheduledTasks.Select(i => i.ScheduledTask)
.First(i => string.Equals(i.Key, "RefreshLibrary", StringComparison.OrdinalIgnoreCase));

_taskManager.QueueScheduledTask(task);
_taskManager.QueueScheduledTask(_taskManager.ScheduledTasks.Select(i => i.ScheduledTask)
.First(i => string.Equals(i.Key, "RefreshLibrary", StringComparison.OrdinalIgnoreCase)));
_taskManager.QueueScheduledTask(_taskManager.ScheduledTasks.Select(i => i.ScheduledTask)
.First(i => string.Equals(i.Key, "RefreshGuide", StringComparison.OrdinalIgnoreCase)));
});

var list = _config.Configuration.Migrations.ToList();
Expand Down
4 changes: 3 additions & 1 deletion MediaBrowser.Api/LiveTv/LiveTvService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public class GetRecordings : IReturn<QueryResult<BaseItemDto>>, IHasDtoOptions
public bool? IsKids { get; set; }
public bool? IsSports { get; set; }
public bool? IsNews { get; set; }
public bool? IsLibraryItem { get; set; }

public GetRecordings()
{
Expand Down Expand Up @@ -1057,7 +1058,8 @@ public async Task<object> Get(GetRecordings request)
IsNews = request.IsNews,
IsSeries = request.IsSeries,
IsKids = request.IsKids,
IsSports = request.IsSports
IsSports = request.IsSports,
IsLibraryItem = request.IsLibraryItem

}, options, CancellationToken.None).ConfigureAwait(false);

Expand Down
4 changes: 2 additions & 2 deletions MediaBrowser.Api/Playback/BaseStreamingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ protected string GetGraphicalSubtitleParam(StreamState state, string outputVideo

if (state.VideoStream != null && state.VideoStream.Width.HasValue && state.VideoStream.Height.HasValue)
{
videoSizeParam = string.Format(",scale={0}:{1}", state.VideoStream.Width.Value.ToString(UsCulture), state.VideoStream.Height.Value.ToString(UsCulture));
videoSizeParam = string.Format("scale={0}:{1}", state.VideoStream.Width.Value.ToString(UsCulture), state.VideoStream.Height.Value.ToString(UsCulture));
}

var mapPrefix = state.SubtitleStream.IsExternal ?
Expand All @@ -829,7 +829,7 @@ protected string GetGraphicalSubtitleParam(StreamState state, string outputVideo
? 0
: state.SubtitleStream.Index;

return string.Format(" -filter_complex \"[{0}:{1}]format=yuva444p{4},lut=u=128:v=128:y=gammaval(.3)[sub] ; [0:{2}] [sub] overlay{3}\"",
return string.Format(" -filter_complex \"[{0}:{1}]{4}[sub] ; [0:{2}] [sub] overlay{3}\"",
mapPrefix.ToString(UsCulture),
subtitleStreamIndex.ToString(UsCulture),
state.VideoStream.Index.ToString(UsCulture),
Expand Down
16 changes: 0 additions & 16 deletions MediaBrowser.Api/Reports/ReportsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user)
OfficialRatings = request.GetOfficialRatings(),
Genres = request.GetGenres(),
GenreIds = request.GetGenreIds(),
Studios = request.GetStudios(),
StudioIds = request.GetStudioIds(),
Person = request.Person,
PersonIds = request.GetPersonIds(),
Expand Down Expand Up @@ -314,21 +313,6 @@ private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user)
query.MaxParentalRating = _localization.GetRatingLevel(request.MaxOfficialRating);
}

// Artists
if (!string.IsNullOrEmpty(request.ArtistIds))
{
var artistIds = request.ArtistIds.Split(new[] { '|', ',' });

var artistItems = artistIds.Select(_libraryManager.GetItemById).Where(i => i != null).ToList();
query.ArtistNames = artistItems.Select(i => i.Name).ToArray();
}

// Artists
if (!string.IsNullOrEmpty(request.Artists))
{
query.ArtistNames = request.Artists.Split('|');
}

// Albums
if (!string.IsNullOrEmpty(request.Albums))
{
Expand Down
Loading

0 comments on commit 30e1702

Please sign in to comment.