diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs
index d47a7e2d6..07e64c98d 100644
--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs
+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs
@@ -78,6 +78,14 @@ namespace MediaBrowser.Api.LiveTv
/// The fields.
[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; }
+
+ [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")]
@@ -582,7 +590,8 @@ namespace MediaBrowser.Api.LiveTv
IsFavorite = request.IsFavorite,
IsLiked = request.IsLiked,
IsDisliked = request.IsDisliked,
- EnableFavoriteSorting = request.EnableFavoriteSorting
+ EnableFavoriteSorting = request.EnableFavoriteSorting,
+ AddCurrentProgram = request.AddCurrentProgram
}, GetDtoOptions(request), CancellationToken.None).ConfigureAwait(false);
diff --git a/MediaBrowser.Model/LiveTv/LiveTvChannelQuery.cs b/MediaBrowser.Model/LiveTv/LiveTvChannelQuery.cs
index 900537b7a..3a6ad0444 100644
--- a/MediaBrowser.Model/LiveTv/LiveTvChannelQuery.cs
+++ b/MediaBrowser.Model/LiveTv/LiveTvChannelQuery.cs
@@ -53,5 +53,11 @@ namespace MediaBrowser.Model.LiveTv
///
/// The limit.
public int? Limit { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether [add current program].
+ ///
+ /// true if [add current program]; otherwise, false.
+ public bool AddCurrentProgram { get; set; }
}
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index 653adb716..9cd4a2334 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -251,13 +251,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var now = DateTime.UtcNow;
- var programs = _libraryManager.QueryItems(new InternalItemsQuery
+ var programs = query.AddCurrentProgram ? _libraryManager.QueryItems(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
MaxStartDate = now,
- MinEndDate = now
+ MinEndDate = now,
+ ChannelIds = internalResult.Items.Select(i => i.Id.ToString("N")).ToArray()
- }).Items.Cast().OrderBy(i => i.StartDate).ToList();
+ }).Items.Cast().OrderBy(i => i.StartDate).ToList() : new List();
foreach (var channel in internalResult.Items)
{
@@ -776,7 +777,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
IsMovie = query.IsMovie,
IsSports = query.IsSports,
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);
@@ -802,29 +807,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
- IEnumerable programs = _libraryManager.QueryItems(internalQuery).Items.Cast();
+ var queryResult = _libraryManager.QueryItems(internalQuery);
- programs = _libraryManager.Sort(programs, user, query.SortBy, query.SortOrder ?? SortOrder.Ascending)
- .Cast();
-
- var programList = programs.ToList();
- IEnumerable 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);
- })
+ var returnArray = queryResult.Items
+ .Select(i => _dtoService.GetBaseItemDto(i, options, user))
.ToArray();
await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false);
@@ -832,7 +818,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var result = new QueryResult
{
Items = returnArray,
- TotalRecordCount = programList.Count
+ TotalRecordCount = queryResult.TotalRecordCount
};
return result;
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
index 4bbbf5a4d..cab21bc3a 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
@@ -108,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
public async Task> 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()
{
@@ -398,7 +398,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
{
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));
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
index 3ec45c4de..f6a04f303 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs
@@ -712,6 +712,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText;
+ cmd.CommandText += GetOrderByText(query);
+
if (query.Limit.HasValue)
{
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;
+ _logger.Debug(cmd.CommandText);
+
var list = new List();
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 GetItemIdsList(InternalItemsQuery query)
{
if (query == null)
@@ -768,6 +794,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText;
+ cmd.CommandText += GetOrderByText(query);
+
if (query.Limit.HasValue)
{
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
@@ -816,6 +844,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
cmd.CommandText += whereText;
+ cmd.CommandText += GetOrderByText(query);
+
if (query.Limit.HasValue)
{
cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
@@ -985,7 +1015,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
string.Empty :
" 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,
query.StartIndex.Value.ToString(CultureInfo.InvariantCulture)));
}