From a641059c571d9596baa814a01a85546e3a4b5b50 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 25 Nov 2013 15:39:23 -0500 Subject: [PATCH] display programs on channel page --- MediaBrowser.Api/LibraryService.cs | 14 ++-- MediaBrowser.Api/LiveTv/LiveTvService.cs | 53 +++---------- .../LiveTv/ILiveTvManager.cs | 5 +- .../LiveTv/ILiveTvService.cs | 20 +++-- MediaBrowser.Controller/LiveTv/ProgramInfo.cs | 49 ++++++++++++ .../LiveTv/RecordingInfo.cs | 4 +- .../MediaBrowser.Controller.csproj | 2 + .../MediaBrowser.Model.Portable.csproj | 14 ++-- .../MediaBrowser.Model.net35.csproj | 14 ++-- MediaBrowser.Model/ApiClient/IApiClient.cs | 2 +- MediaBrowser.Model/LiveTv/ChannelInfoDto.cs | 6 -- .../{ProgramInfo.cs => ProgramInfoDto.cs} | 30 ++++--- MediaBrowser.Model/LiveTv/RecordingInfoDto.cs | 78 ++++++++++++++++++ MediaBrowser.Model/LiveTv/RecordingQuery.cs | 6 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 6 +- .../{ItemReviewsResult.cs => QueryResult.cs} | 20 ++--- .../LiveTv/LiveTvManager.cs | 79 +++++++++++++------ .../LiveTv/RefreshChannelsScheduledTask.cs | 2 +- MediaBrowser.WebDashboard/ApiClient.js | 11 +++ MediaBrowser.WebDashboard/packages.config | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 23 files changed, 283 insertions(+), 144 deletions(-) create mode 100644 MediaBrowser.Controller/LiveTv/ProgramInfo.cs rename {MediaBrowser.Model => MediaBrowser.Controller}/LiveTv/RecordingInfo.cs (97%) rename MediaBrowser.Model/LiveTv/{ProgramInfo.cs => ProgramInfoDto.cs} (69%) create mode 100644 MediaBrowser.Model/LiveTv/RecordingInfoDto.cs rename MediaBrowser.Model/Querying/{ItemReviewsResult.cs => QueryResult.cs} (53%) diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index 3863ef2094..55ee454d2e 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Api /// [Route("/Items/{Id}/CriticReviews", "GET")] [Api(Description = "Gets critic reviews for an item")] - public class GetCriticReviews : IReturn + public class GetCriticReviews : IReturn> { /// /// Gets or sets the id. @@ -509,16 +509,16 @@ namespace MediaBrowser.Api /// /// The request. /// Task{ItemReviewsResult}. - private ItemReviewsResult GetCriticReviews(GetCriticReviews request) + private QueryResult GetCriticReviews(GetCriticReviews request) { var reviews = _itemRepo.GetCriticReviews(new Guid(request.Id)); var reviewsArray = reviews.ToArray(); - var result = new ItemReviewsResult - { - TotalRecordCount = reviewsArray.Length - }; + var result = new QueryResult + { + TotalRecordCount = reviewsArray.Length + }; if (request.StartIndex.HasValue) { @@ -529,7 +529,7 @@ namespace MediaBrowser.Api reviewsArray = reviewsArray.Take(request.Limit.Value).ToArray(); } - result.ItemReviews = reviewsArray; + result.Items = reviewsArray; return result; } diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index b10d8d481e..5cd23a738f 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -1,11 +1,10 @@ -using System; -using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.Querying; using ServiceStack.ServiceHost; +using System; using System.Collections.Generic; using System.Linq; -using System.Threading; -using System.Threading.Tasks; namespace MediaBrowser.Api.LiveTv { @@ -19,7 +18,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Channels", "GET")] [Api(Description = "Gets available live tv channels.")] - public class GetChannels : IReturn> + public class GetChannels : IReturn> { [ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ServiceName { get; set; } @@ -43,22 +42,14 @@ namespace MediaBrowser.Api.LiveTv public string Id { get; set; } } - [Route("/LiveTv/Recordings", "GET")] - [Api(Description = "Gets available live tv recordings.")] - public class GetRecordings : IReturn> - { - [ApiMember(Name = "ServiceName", Description = "Optional filter by service.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string ServiceName { get; set; } - } - [Route("/LiveTv/Programs", "GET")] [Api(Description = "Gets available live tv epgs..")] - public class GetPrograms : IReturn> + public class GetPrograms : IReturn> { - [ApiMember(Name = "ServiceName", Description = "Live tv service name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + [ApiMember(Name = "ServiceName", Description = "Live tv service name", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ServiceName { get; set; } - [ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + [ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ChannelIds { get; set; } } @@ -108,10 +99,9 @@ namespace MediaBrowser.Api.LiveTv ServiceName = request.ServiceName, UserId = request.UserId - }) - .Select(_liveTvManager.GetChannelInfoDto); + }); - return ToOptimizedResult(result.ToList()); + return ToOptimizedResult(result); } public object Get(GetChannel request) @@ -121,29 +111,6 @@ namespace MediaBrowser.Api.LiveTv return ToOptimizedResult(_liveTvManager.GetChannelInfoDto(result)); } - public object Get(GetRecordings request) - { - var result = GetRecordingsAsync(request).Result; - - return ToOptimizedResult(result.ToList()); - } - - private async Task> GetRecordingsAsync(GetRecordings request) - { - var services = GetServices(request.ServiceName); - - var query = new RecordingQuery - { - - }; - - var tasks = services.Select(i => i.GetRecordingsAsync(query, CancellationToken.None)); - - var recordings = await Task.WhenAll(tasks).ConfigureAwait(false); - - return recordings.SelectMany(i => i); - } - public object Get(GetPrograms request) { var result = _liveTvManager.GetPrograms(new ProgramQuery @@ -152,7 +119,7 @@ namespace MediaBrowser.Api.LiveTv ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray() }); - return ToOptimizedResult(result.ToList()); + return ToOptimizedResult(result); } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 339367c170..e7b5d733b9 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -1,4 +1,5 @@ using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.Querying; using System.Collections.Generic; namespace MediaBrowser.Controller.LiveTv @@ -25,7 +26,7 @@ namespace MediaBrowser.Controller.LiveTv /// /// The query. /// IEnumerable{Channel}. - IEnumerable GetChannels(ChannelQuery query); + QueryResult GetChannels(ChannelQuery query); /// /// Gets the channel information dto. @@ -46,6 +47,6 @@ namespace MediaBrowser.Controller.LiveTv /// /// The query. /// IEnumerable{ProgramInfo}. - IEnumerable GetPrograms(ProgramQuery query); + QueryResult GetPrograms(ProgramQuery query); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 53cb514b52..4e4f8dcc78 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Net; -using MediaBrowser.Model.LiveTv; using System; using System.Collections.Generic; using System.Threading; @@ -33,6 +32,14 @@ namespace MediaBrowser.Controller.LiveTv /// Task. Task CancelRecordingAsync(string recordingId, CancellationToken cancellationToken); + /// + /// Deletes the recording asynchronous. + /// + /// The recording identifier. + /// The cancellation token. + /// Task. + Task DeleteRecordingAsync(string recordingId, CancellationToken cancellationToken); + /// /// Schedules the recording asynchronous. /// @@ -42,8 +49,8 @@ namespace MediaBrowser.Controller.LiveTv /// The duration. /// The cancellation token. /// Task. - Task ScheduleRecordingAsync(string name,string channelId, DateTime startTime, TimeSpan duration, CancellationToken cancellationToken); - + Task ScheduleRecordingAsync(string name, string channelId, DateTime startTime, TimeSpan duration, CancellationToken cancellationToken); + /// /// Gets the channel image asynchronous. /// @@ -55,17 +62,16 @@ namespace MediaBrowser.Controller.LiveTv /// /// Gets the recordings asynchronous. /// - /// The query. /// The cancellation token. /// Task{IEnumerable{RecordingInfo}}. - Task> GetRecordingsAsync(RecordingQuery query, CancellationToken cancellationToken); + Task> GetRecordingsAsync(CancellationToken cancellationToken); /// - /// Gets the channel guide. + /// Gets the programs asynchronous. /// /// The channel identifier. /// The cancellation token. /// Task{IEnumerable{ProgramInfo}}. - Task> GetChannelGuideAsync(string channelId, CancellationToken cancellationToken); + Task> GetProgramsAsync(string channelId, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs new file mode 100644 index 0000000000..8314b91705 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; + +namespace MediaBrowser.Controller.LiveTv +{ + public class ProgramInfo + { + /// + /// Id of the program. + /// + public string Id { get; set; } + + /// + /// Gets or sets the channel identifier. + /// + /// The channel identifier. + public string ChannelId { get; set; } + + /// + /// Name of the program + /// + public string Name { get; set; } + + /// + /// Description of the progam. + /// + public string Description { get; set; } + + /// + /// The start date of the program, in UTC. + /// + public DateTime StartDate { get; set; } + + /// + /// The end date of the program, in UTC. + /// + public DateTime EndDate { get; set; } + + /// + /// Genre of the program. + /// + public List Genres { get; set; } + + public ProgramInfo() + { + Genres = new List(); + } + } +} diff --git a/MediaBrowser.Model/LiveTv/RecordingInfo.cs b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs similarity index 97% rename from MediaBrowser.Model/LiveTv/RecordingInfo.cs rename to MediaBrowser.Controller/LiveTv/RecordingInfo.cs index 55a30a4b38..f35b6d5c63 100644 --- a/MediaBrowser.Model/LiveTv/RecordingInfo.cs +++ b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace MediaBrowser.Model.LiveTv +namespace MediaBrowser.Controller.LiveTv { public class RecordingInfo { @@ -75,4 +75,4 @@ namespace MediaBrowser.Model.LiveTv /// public List DayMask { get; set; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index ea227349ea..ed63bc1647 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -108,6 +108,8 @@ + + diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 2850d09edc..e7003219a4 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -236,14 +236,14 @@ LiveTv\LiveTvServiceInfo.cs - - LiveTv\ProgramInfo.cs + + LiveTv\ProgramInfoDto.cs LiveTv\ProgramQuery.cs - - LiveTv\RecordingInfo.cs + + LiveTv\RecordingInfoDto.cs LiveTv\RecordingQuery.cs @@ -329,9 +329,6 @@ Querying\ItemQuery.cs - - Querying\ItemReviewsResult.cs - Querying\ItemsByNameQuery.cs @@ -347,6 +344,9 @@ Querying\PersonsQuery.cs + + Querying\QueryResult.cs + Querying\SessionQuery.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index be62681840..f0d23c959b 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -223,14 +223,14 @@ LiveTv\LiveTvServiceInfo.cs - - LiveTv\ProgramInfo.cs + + LiveTv\ProgramInfoDto.cs LiveTv\ProgramQuery.cs - - LiveTv\RecordingInfo.cs + + LiveTv\RecordingInfoDto.cs LiveTv\RecordingQuery.cs @@ -316,9 +316,6 @@ Querying\ItemQuery.cs - - Querying\ItemReviewsResult.cs - Querying\ItemsByNameQuery.cs @@ -334,6 +331,9 @@ Querying\PersonsQuery.cs + + Querying\QueryResult.cs + Querying\SessionQuery.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 7817a26cd3..ad82966048 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -83,7 +83,7 @@ namespace MediaBrowser.Model.ApiClient /// The start index. /// The limit. /// Task{ItemReviewsResult}. - Task GetCriticReviews(string itemId, CancellationToken cancellationToken, int? startIndex = null, int? limit = null); + Task> GetCriticReviews(string itemId, CancellationToken cancellationToken, int? startIndex = null, int? limit = null); /// /// Gets the theme songs async. diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs index fe242b66cd..c8d351bd05 100644 --- a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs @@ -18,12 +18,6 @@ namespace MediaBrowser.Model.LiveTv /// /// The identifier. public string Id { get; set; } - - /// - /// Gets or sets the channel identifier. - /// - /// The channel identifier. - public string ChannelId { get; set; } /// /// Gets or sets the logo image tag. diff --git a/MediaBrowser.Model/LiveTv/ProgramInfo.cs b/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs similarity index 69% rename from MediaBrowser.Model/LiveTv/ProgramInfo.cs rename to MediaBrowser.Model/LiveTv/ProgramInfoDto.cs index 75ec5df705..15387d5204 100644 --- a/MediaBrowser.Model/LiveTv/ProgramInfo.cs +++ b/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs @@ -1,14 +1,21 @@ using System; +using System.Collections.Generic; namespace MediaBrowser.Model.LiveTv { - public class ProgramInfo + public class ProgramInfoDto { /// /// Id of the program. /// public string Id { get; set; } + /// + /// Gets or sets the external identifier. + /// + /// The external identifier. + public string ExternalId { get; set; } + /// /// Gets or sets the channel identifier. /// @@ -16,17 +23,17 @@ namespace MediaBrowser.Model.LiveTv public string ChannelId { get; set; } /// - /// Gets or sets the name of the service. + /// Gets or sets the recording identifier. /// - /// The name of the service. - public string ServiceName { get; set; } + /// The recording identifier. + public string RecordingId { get; set; } /// - /// Gets or sets the external channel identifier. + /// Gets or sets the name of the service. /// - /// The external channel identifier. - public string ExternalChannelId { get; set; } - + /// The name of the service. + public string ServiceName { get; set; } + /// /// Name of the program /// @@ -50,6 +57,11 @@ namespace MediaBrowser.Model.LiveTv /// /// Genre of the program. /// - public string Genre { get; set; } + public List Genres { get; set; } + + public ProgramInfoDto() + { + Genres = new List(); + } } } \ No newline at end of file diff --git a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs new file mode 100644 index 0000000000..b24af04a03 --- /dev/null +++ b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; + +namespace MediaBrowser.Model.LiveTv +{ + public class RecordingInfoDto + { + /// + /// Id of the recording. + /// + public string Id { get; set; } + + /// + /// ChannelId of the recording. + /// + public string ChannelId { get; set; } + + /// + /// ChannelName of the recording. + /// + public string ChannelName { get; set; } + + /// + /// Name of the recording. + /// + public string Name { get; set; } + + /// + /// Description of the recording. + /// + public string Description { get; set; } + + /// + /// The start date of the recording, in UTC. + /// + public DateTime StartDate { get; set; } + + /// + /// The end date of the recording, in UTC. + /// + public DateTime EndDate { get; set; } + + /// + /// Status of the recording. + /// + public string Status { get; set; } //TODO: Enum for status?? Difference NextPvr,Argus,... + + /// + /// Quality of the Recording. + /// + public string Quality { get; set; } // TODO: Enum for quality?? Difference NextPvr,Argus,... + + /// + /// Recurring recording? + /// + public bool Recurring { get; set; } + + /// + /// Parent recurring. + /// + public string RecurringParent { get; set; } + + /// + /// Start date for the recurring, in UTC. + /// + public DateTime RecurrringStartDate { get; set; } + + /// + /// End date for the recurring, in UTC + /// + public DateTime RecurringEndDate { get; set; } + + /// + /// When do we need the recording? + /// + public List DayMask { get; set; } + } +} \ No newline at end of file diff --git a/MediaBrowser.Model/LiveTv/RecordingQuery.cs b/MediaBrowser.Model/LiveTv/RecordingQuery.cs index e7a91f4d55..8d9866b5ec 100644 --- a/MediaBrowser.Model/LiveTv/RecordingQuery.cs +++ b/MediaBrowser.Model/LiveTv/RecordingQuery.cs @@ -5,10 +5,6 @@ /// public class RecordingQuery { - /// - /// Gets or sets a value indicating whether this instance has recorded. - /// - /// null if [has recorded] contains no value, true if [has recorded]; otherwise, false. - public bool? HasRecorded { get; set; } + public string ChannelId { get; set; } } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 05b4e9b7a0..1e94c6b5fb 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -62,7 +62,7 @@ - + @@ -80,7 +80,7 @@ - + @@ -93,10 +93,10 @@ - + diff --git a/MediaBrowser.Model/Querying/ItemReviewsResult.cs b/MediaBrowser.Model/Querying/QueryResult.cs similarity index 53% rename from MediaBrowser.Model/Querying/ItemReviewsResult.cs rename to MediaBrowser.Model/Querying/QueryResult.cs index 6a29827a91..1ecc1de6c4 100644 --- a/MediaBrowser.Model/Querying/ItemReviewsResult.cs +++ b/MediaBrowser.Model/Querying/QueryResult.cs @@ -1,17 +1,13 @@ -using MediaBrowser.Model.Entities; - + namespace MediaBrowser.Model.Querying { - /// - /// Class ItemReviewsResult - /// - public class ItemReviewsResult + public class QueryResult { /// - /// Gets or sets the item reviews. + /// Gets or sets the items. /// - /// The item reviews. - public ItemReview[] ItemReviews { get; set; } + /// The items. + public T[] Items { get; set; } /// /// The total number of records available @@ -22,9 +18,9 @@ namespace MediaBrowser.Model.Querying /// /// Initializes a new instance of the class. /// - public ItemReviewsResult() + public QueryResult() { - ItemReviews = new ItemReview[] { }; + Items = new T[] { }; } - } + } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 825c7d8ef8..fe58f292ca 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -13,6 +13,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Querying; namespace MediaBrowser.Server.Implementations.LiveTv { @@ -27,12 +28,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly IItemRepository _itemRepo; private readonly IImageProcessor _imageProcessor; - private List _channels = new List(); - - private Dictionary> _guide = new Dictionary>(); - private readonly List _services = new List(); + private List _channels = new List(); + private List _programs = new List(); + public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor) { _appPaths = appPaths; @@ -72,7 +72,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv Name = info.Name, ServiceName = info.ServiceName, ChannelType = info.ChannelType, - ChannelId = info.ChannelId, Number = info.ChannelNumber, PrimaryImageTag = GetLogoImageTag(info), Type = info.GetType().Name, @@ -107,9 +106,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv return null; } - public IEnumerable GetChannels(ChannelQuery query) + public QueryResult GetChannels(ChannelQuery query) { - return _channels.OrderBy(i => + var channels = _channels.OrderBy(i => { double number = 0; @@ -120,7 +119,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv return number; - }).ThenBy(i => i.Name); + }).ThenBy(i => i.Name) + .Select(GetChannelInfoDto) + .ToArray(); + + return new QueryResult + { + Items = channels, + TotalRecordCount = channels.Length + }; } public Channel GetChannel(string id) @@ -135,16 +142,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv // Avoid implicitly captured closure var currentCancellationToken = cancellationToken; - var tasks = _services.Select(i => i.GetChannelsAsync(currentCancellationToken)); + var channelTasks = _services.Select(i => i.GetChannelsAsync(currentCancellationToken)); progress.Report(10); - var results = await Task.WhenAll(tasks).ConfigureAwait(false); + var results = await Task.WhenAll(channelTasks).ConfigureAwait(false); var allChannels = results.SelectMany(i => i).ToList(); var list = new List(); - var guide = new Dictionary>(); + var programs = new List(); var numComplete = 0; @@ -156,18 +163,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(channelInfo); - var programs = await service.GetChannelGuideAsync(channelInfo.Id, cancellationToken).ConfigureAwait(false); - var programList = programs.ToList(); + var channelPrograms = await service.GetProgramsAsync(channelInfo.Id, cancellationToken).ConfigureAwait(false); - foreach (var program in programList) - { - program.ExternalChannelId = channelInfo.Id; - program.ChannelId = item.Id.ToString("N"); - program.ServiceName = service.Name; - } + programs.AddRange(channelPrograms.Select(program => GetProgramInfoDto(program, item))); list.Add(item); - guide[item.Id] = programList; } catch (OperationCanceledException) { @@ -185,10 +185,29 @@ namespace MediaBrowser.Server.Implementations.LiveTv progress.Report(90 * percent + 10); } - _guide = guide; + _programs = programs; _channels = list; } + private ProgramInfoDto GetProgramInfoDto(ProgramInfo program, Channel channel) + { + var id = channel.ServiceName + channel.ChannelId + program.Id; + id = id.GetMD5().ToString("N"); + + return new ProgramInfoDto + { + ChannelId = channel.Id.ToString("N"), + Description = program.Description, + EndDate = program.EndDate, + Genres = program.Genres, + ExternalId = program.Id, + Id = id, + Name = program.Name, + ServiceName = channel.ServiceName, + StartDate = program.StartDate + }; + } + private async Task GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken) { var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.ServiceName), _fileSystem.GetValidFilename(channelInfo.Name)); @@ -241,9 +260,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv return item; } - public IEnumerable GetPrograms(ProgramQuery query) + public QueryResult GetPrograms(ProgramQuery query) { - var programs = _guide.Values.SelectMany(i => i); + IEnumerable programs = _programs + .OrderBy(i => i.StartDate) + .ThenBy(i => i.EndDate); if (!string.IsNullOrEmpty(query.ServiceName)) { @@ -255,9 +276,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv var guids = query.ChannelIdList.Select(i => new Guid(i)).ToList(); programs = programs.Where(i => guids.Contains(new Guid(i.ChannelId))); - } - - return programs; + } + + var returnArray = programs.ToArray(); + + return new QueryResult + { + Items = returnArray, + TotalRecordCount = returnArray.Length + }; } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs b/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs index 64bf5cdd3f..c3803d9bbc 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs @@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv new SystemEventTrigger{ SystemEvent = SystemEvent.WakeFromSleep}, - new IntervalTrigger{ Interval = TimeSpan.FromHours(4)} + new IntervalTrigger{ Interval = TimeSpan.FromHours(2)} }; } } diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index f2c0987236..e63eb4d2b1 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -415,6 +415,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; + self.getLiveTvPrograms = function (options) { + + var url = self.getUrl("/LiveTv/Programs", options || {}); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + self.getLiveTvRecordings = function (options) { var url = self.getUrl("/LiveTv/Recordings", options || {}); diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index 75cba28646..ab57a48b15 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index ea21fc39b4..5a32ce2dd7 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.247 + 3.0.248 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 1f2d32b5f1..e363cf621e 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.247 + 3.0.248 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 809cad71a2..83861329ba 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.247 + 3.0.248 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +