add more live tv buttons

This commit is contained in:
Luke Pulverenti 2015-08-24 23:13:04 -04:00
parent 41fc1f87f5
commit 8046a51418
5 changed files with 64 additions and 31 deletions

View File

@ -78,6 +78,14 @@ namespace MediaBrowser.Api.LiveTv
/// <value>The fields.</value> /// <value>The fields.</value>
[ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
public string Fields { get; set; } public string Fields { get; set; }
[ApiMember(Name = "AddCurrentProgram", Description = "Optional. Adds current program info to each channel", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public bool AddCurrentProgram { get; set; }
public GetChannels()
{
AddCurrentProgram = true;
}
} }
[Route("/LiveTv/Channels/{Id}", "GET", Summary = "Gets a live tv channel")] [Route("/LiveTv/Channels/{Id}", "GET", Summary = "Gets a live tv channel")]
@ -582,7 +590,8 @@ namespace MediaBrowser.Api.LiveTv
IsFavorite = request.IsFavorite, IsFavorite = request.IsFavorite,
IsLiked = request.IsLiked, IsLiked = request.IsLiked,
IsDisliked = request.IsDisliked, IsDisliked = request.IsDisliked,
EnableFavoriteSorting = request.EnableFavoriteSorting EnableFavoriteSorting = request.EnableFavoriteSorting,
AddCurrentProgram = request.AddCurrentProgram
}, GetDtoOptions(request), CancellationToken.None).ConfigureAwait(false); }, GetDtoOptions(request), CancellationToken.None).ConfigureAwait(false);

View File

@ -53,5 +53,11 @@ namespace MediaBrowser.Model.LiveTv
/// </summary> /// </summary>
/// <value>The limit.</value> /// <value>The limit.</value>
public int? Limit { get; set; } public int? Limit { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [add current program].
/// </summary>
/// <value><c>true</c> if [add current program]; otherwise, <c>false</c>.</value>
public bool AddCurrentProgram { get; set; }
} }
} }

View File

@ -251,13 +251,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var programs = _libraryManager.QueryItems(new InternalItemsQuery var programs = query.AddCurrentProgram ? _libraryManager.QueryItems(new InternalItemsQuery
{ {
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name }, IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
MaxStartDate = now, MaxStartDate = now,
MinEndDate = now MinEndDate = now,
ChannelIds = internalResult.Items.Select(i => i.Id.ToString("N")).ToArray()
}).Items.Cast<LiveTvProgram>().OrderBy(i => i.StartDate).ToList(); }).Items.Cast<LiveTvProgram>().OrderBy(i => i.StartDate).ToList() : new List<LiveTvProgram>();
foreach (var channel in internalResult.Items) foreach (var channel in internalResult.Items)
{ {
@ -776,7 +777,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
IsMovie = query.IsMovie, IsMovie = query.IsMovie,
IsSports = query.IsSports, IsSports = query.IsSports,
IsKids = query.IsKids, IsKids = query.IsKids,
Genres = query.Genres Genres = query.Genres,
StartIndex = query.StartIndex,
Limit = query.Limit,
SortBy = query.SortBy,
SortOrder = query.SortOrder ?? SortOrder.Ascending
}; };
var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId);
@ -802,29 +807,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv
} }
} }
IEnumerable<LiveTvProgram> programs = _libraryManager.QueryItems(internalQuery).Items.Cast<LiveTvProgram>(); var queryResult = _libraryManager.QueryItems(internalQuery);
programs = _libraryManager.Sort(programs, user, query.SortBy, query.SortOrder ?? SortOrder.Ascending) var returnArray = queryResult.Items
.Cast<LiveTvProgram>(); .Select(i => _dtoService.GetBaseItemDto(i, options, user))
var programList = programs.ToList();
IEnumerable<LiveTvProgram> returnPrograms = programList;
if (query.StartIndex.HasValue)
{
returnPrograms = returnPrograms.Skip(query.StartIndex.Value);
}
if (query.Limit.HasValue)
{
returnPrograms = returnPrograms.Take(query.Limit.Value);
}
var returnArray = returnPrograms
.Select(i =>
{
return _dtoService.GetBaseItemDto(i, options, user);
})
.ToArray(); .ToArray();
await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false);
@ -832,7 +818,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var result = new QueryResult<BaseItemDto> var result = new QueryResult<BaseItemDto>
{ {
Items = returnArray, Items = returnArray,
TotalRecordCount = programList.Count TotalRecordCount = queryResult.TotalRecordCount
}; };
return result; return result;

View File

@ -108,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
public async Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken) public async Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken)
{ {
string model = await GetModelInfo(info, cancellationToken).ConfigureAwait(false); var model = await GetModelInfo(info, cancellationToken).ConfigureAwait(false);
using (var stream = await _httpClient.Get(new HttpRequestOptions() using (var stream = await _httpClient.Get(new HttpRequestOptions()
{ {
@ -398,7 +398,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
{ {
var info = await GetTunerInfos(tuner, cancellationToken).ConfigureAwait(false); var info = await GetTunerInfos(tuner, cancellationToken).ConfigureAwait(false);
return info.Any(i => i.Status == LiveTvTunerStatus.Available); return info.Any(i => i.Status == LiveTvTunerStatus.Available || string.Equals(i.ChannelId, channelId, StringComparison.OrdinalIgnoreCase));
} }
} }
} }

View File

@ -712,6 +712,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText; cmd.CommandText += whereText;
cmd.CommandText += GetOrderByText(query);
if (query.Limit.HasValue) if (query.Limit.HasValue)
{ {
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
@ -719,6 +721,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging; cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging;
_logger.Debug(cmd.CommandText);
var list = new List<BaseItem>(); var list = new List<BaseItem>();
var count = 0; var count = 0;
@ -747,6 +751,28 @@ namespace MediaBrowser.Server.Implementations.Persistence
} }
} }
private string GetOrderByText(InternalItemsQuery query)
{
if (query.SortBy == null || query.SortBy.Length == 0)
{
return string.Empty;
}
var sortOrder = query.SortOrder == SortOrder.Descending ? "DESC" : "ASC";
return " ORDER BY " + string.Join(",", query.SortBy.Select(i => MapOrderByField(i) + " " + sortOrder).ToArray());
}
private string MapOrderByField(string name)
{
if (string.Equals(name, "sortname", StringComparison.OrdinalIgnoreCase))
{
return "name";
}
return name;
}
public List<Guid> GetItemIdsList(InternalItemsQuery query) public List<Guid> GetItemIdsList(InternalItemsQuery query)
{ {
if (query == null) if (query == null)
@ -768,6 +794,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText; cmd.CommandText += whereText;
cmd.CommandText += GetOrderByText(query);
if (query.Limit.HasValue) if (query.Limit.HasValue)
{ {
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
@ -816,6 +844,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText; cmd.CommandText += whereText;
cmd.CommandText += GetOrderByText(query);
if (query.Limit.HasValue) if (query.Limit.HasValue)
{ {
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
@ -985,7 +1015,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
string.Empty : string.Empty :
" where " + string.Join(" AND ", whereClauses.ToArray()); " where " + string.Join(" AND ", whereClauses.ToArray());
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM TypedBaseItems {0} ORDER BY DateCreated DESC LIMIT {1})", var orderBy = GetOrderByText(query);
whereClauses.Add(string.Format("guid NOT IN (SELECT guid FROM TypedBaseItems {0}" + orderBy + " LIMIT {1})",
pagingWhereText, pagingWhereText,
query.StartIndex.Value.ToString(CultureInfo.InvariantCulture))); query.StartIndex.Value.ToString(CultureInfo.InvariantCulture)));
} }