From ef8a1ccecbacab4ef535bb3e74bcb285a9f583fd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 31 May 2015 15:12:58 -0400 Subject: [PATCH] normalize program object --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 6 +- .../LiveTv/ILiveTvManager.cs | 14 +- .../MediaBrowser.Model.Portable.csproj | 3 - .../MediaBrowser.Model.net35.csproj | 3 - MediaBrowser.Model/ApiClient/IApiClient.cs | 14 +- MediaBrowser.Model/Dto/BaseItemDto.cs | 6 + MediaBrowser.Model/LiveTv/ChannelInfoDto.cs | 2 +- MediaBrowser.Model/LiveTv/ProgramInfoDto.cs | 250 ------------------ MediaBrowser.Model/LiveTv/TimerInfoDto.cs | 6 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 1 - .../Dto/DtoService.cs | 5 + .../LiveTv/LiveTvDtoService.cs | 82 +----- .../LiveTv/LiveTvManager.cs | 89 ++++--- 13 files changed, 97 insertions(+), 384 deletions(-) delete mode 100644 MediaBrowser.Model/LiveTv/ProgramInfoDto.cs diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 86d8b9f99..c474642d5 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -161,7 +161,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Programs", "GET,POST", Summary = "Gets available live tv epgs..")] [Authenticated] - public class GetPrograms : IReturn> + public class GetPrograms : IReturn> { [ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")] public string ChannelIds { get; set; } @@ -208,7 +208,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Programs/Recommended", "GET", Summary = "Gets available live tv epgs..")] [Authenticated] - public class GetRecommendedPrograms : IReturn> + public class GetRecommendedPrograms : IReturn> { [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")] public string UserId { get; set; } @@ -231,7 +231,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Programs/{Id}", "GET", Summary = "Gets a live tv program")] [Authenticated] - public class GetProgram : IReturn + public class GetProgram : IReturn { [ApiMember(Name = "Id", Description = "Program Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index e84fe902d..3aa1f66ef 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// The user. /// Task{ProgramInfoDto}. - Task GetProgram(string id, CancellationToken cancellationToken, User user = null); + Task GetProgram(string id, CancellationToken cancellationToken, User user = null); /// /// Gets the programs. @@ -178,7 +178,7 @@ namespace MediaBrowser.Controller.LiveTv /// The query. /// The cancellation token. /// IEnumerable{ProgramInfo}. - Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken); + Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken); /// /// Updates the timer. @@ -240,7 +240,7 @@ namespace MediaBrowser.Controller.LiveTv /// The query. /// The cancellation token. /// Task{QueryResult{ProgramInfoDto}}. - Task> GetRecommendedPrograms(RecommendedProgramQuery query, + Task> GetRecommendedPrograms(RecommendedProgramQuery query, CancellationToken cancellationToken); /// @@ -329,5 +329,13 @@ namespace MediaBrowser.Controller.LiveTv /// The dto. /// The user. void AddInfoToRecordingDto(BaseItem item, BaseItemDto dto, User user = null); + + /// + /// Adds the information to program dto. + /// + /// The item. + /// The dto. + /// The user. + void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, User user = null); } } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index a63b0a7c6..de9360e40 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -743,9 +743,6 @@ LiveTv\ProgramAudio.cs - - LiveTv\ProgramInfoDto.cs - LiveTv\ProgramQuery.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 036064238..ec7c3be5c 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -699,9 +699,6 @@ LiveTv\ProgramAudio.cs - - LiveTv\ProgramInfoDto.cs - LiveTv\ProgramQuery.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 71ac0b14e..e52e7535b 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -929,14 +929,6 @@ namespace MediaBrowser.Model.ApiClient /// System.String. string GetImageUrl(ChannelInfoDto item, ImageOptions options); - /// - /// Gets the image URL. - /// - /// The item. - /// The options. - /// System.String. - string GetImageUrl(ProgramInfoDto item, ImageOptions options); - /// /// Gets the subtitle URL. /// @@ -1111,7 +1103,7 @@ namespace MediaBrowser.Model.ApiClient /// The query. /// The cancellation token. /// Task{QueryResult{ProgramInfoDto}}. - Task> GetLiveTvProgramsAsync(ProgramQuery query, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetLiveTvProgramsAsync(ProgramQuery query, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the live tv program asynchronous. @@ -1120,7 +1112,7 @@ namespace MediaBrowser.Model.ApiClient /// The user identifier. /// The cancellation token. /// Task{ProgramInfoDto}. - Task GetLiveTvProgramAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); + Task GetLiveTvProgramAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the recommended live tv programs asynchronous. @@ -1128,7 +1120,7 @@ namespace MediaBrowser.Model.ApiClient /// The query. /// The cancellation token. /// Task{QueryResult{ProgramInfoDto}}. - Task> GetRecommendedLiveTvProgramsAsync(RecommendedProgramQuery query, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetRecommendedLiveTvProgramsAsync(RecommendedProgramQuery query, CancellationToken cancellationToken = default(CancellationToken)); /// /// Creates the live tv timer asynchronous. diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 0f6ce4334..fb157e9ae 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -1175,5 +1175,11 @@ namespace MediaBrowser.Model.Dto /// true if this instance is premiere; otherwise, false. public bool? IsPremiere { get; set; } + /// + /// Gets or sets the timer identifier. + /// + /// The timer identifier. + public string TimerId { get; set; } + } } diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs index 667ad4f14..fd901f29e 100644 --- a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs @@ -97,7 +97,7 @@ namespace MediaBrowser.Model.LiveTv /// Gets or sets the now playing program. /// /// The now playing program. - public ProgramInfoDto CurrentProgram { get; set; } + public BaseItemDto CurrentProgram { get; set; } /// /// Gets or sets the primary image aspect ratio, after image enhancements. diff --git a/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs b/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs deleted file mode 100644 index 06136459f..000000000 --- a/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs +++ /dev/null @@ -1,250 +0,0 @@ -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; -using MediaBrowser.Model.Library; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.Serialization; - -namespace MediaBrowser.Model.LiveTv -{ - [DebuggerDisplay("Name = {Name}, StartTime = {StartDate}, EndTime = {EndDate}")] - public class ProgramInfoDto : IHasPropertyChangedEvent, IItemDto, IHasServerId - { - /// - /// Id of the program. - /// - public string Id { get; set; } - - /// - /// Gets or sets the primary image aspect ratio. - /// - /// The primary image aspect ratio. - public double? PrimaryImageAspectRatio { get; set; } - - /// - /// Gets or sets the server identifier. - /// - /// The server identifier. - public string ServerId { get; set; } - - /// - /// Gets or sets the original primary image aspect ratio. - /// - /// The original primary image aspect ratio. - public double? OriginalPrimaryImageAspectRatio { get; set; } - - /// - /// Gets or sets the type of the media. - /// - /// The type of the media. - public string MediaType { get; set; } - - /// - /// Gets or sets the timer identifier. - /// - /// The timer identifier. - public string TimerId { get; set; } - - /// - /// Gets or sets the series timer identifier. - /// - /// The series timer identifier. - public string SeriesTimerId { get; set; } - - /// - /// Gets or sets the external identifier. - /// - /// The external identifier. - public string ExternalId { get; set; } - - /// - /// Gets or sets the channel identifier. - /// - /// The channel identifier. - public string ChannelId { get; set; } - - /// - /// Gets or sets the channel primary image tag. - /// - /// The channel primary image tag. - public string ChannelPrimaryImageTag { get; set; } - - /// - /// Gets or sets the play access. - /// - /// The play access. - public PlayAccess PlayAccess { get; set; } - - /// - /// Gets or sets the name of the channel. - /// - /// The name of the channel. - public string ChannelName { get; set; } - - /// - /// Gets or sets the community rating. - /// - /// The community rating. - public float? CommunityRating { get; set; } - - /// - /// Gets or sets the official rating. - /// - /// The official rating. - public string OfficialRating { get; set; } - - /// - /// Gets or sets the production year. - /// - /// The production year. - public int? ProductionYear { get; set; } - - /// - /// Gets or sets the name of the service. - /// - /// The name of the service. - public string ServiceName { get; set; } - - /// - /// Name of the program - /// - public string Name { get; set; } - - /// - /// Overview of the recording. - /// - public string Overview { 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; } - - /// - /// Gets or sets a value indicating whether this instance is hd. - /// - /// true if this instance is hd; otherwise, false. - public bool? IsHD { get; set; } - - /// - /// Gets or sets the audio. - /// - /// The audio. - public ProgramAudio? Audio { get; set; } - - /// - /// Gets or sets the original air date. - /// - /// The original air date. - public DateTime? OriginalAirDate { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is repeat. - /// - /// true if this instance is repeat; otherwise, false. - public bool IsRepeat { get; set; } - - /// - /// Gets or sets the episode title. - /// - /// The episode title. - public string EpisodeTitle { get; set; } - - /// - /// Gets or sets the image tags. - /// - /// The image tags. - public Dictionary ImageTags { get; set; } - - /// - /// Gets or sets the user data. - /// - /// The user data. - public UserItemDataDto UserData { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is movie. - /// - /// true if this instance is movie; otherwise, false. - public bool IsMovie { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is sports. - /// - /// true if this instance is sports; otherwise, false. - public bool IsSports { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is series. - /// - /// true if this instance is series; otherwise, false. - public bool IsSeries { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is live. - /// - /// true if this instance is live; otherwise, false. - public bool IsLive { get; set; } - - /// - /// Gets or sets the type. - /// - /// The type. - public string Type { get; set; } - - /// - /// Gets or sets the run time ticks. - /// - /// The run time ticks. - public long? RunTimeTicks { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is news. - /// - /// true if this instance is news; otherwise, false. - public bool IsNews { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is kids. - /// - /// true if this instance is kids; otherwise, false. - public bool IsKids { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is premiere. - /// - /// true if this instance is premiere; otherwise, false. - public bool IsPremiere { get; set; } - - /// - /// Gets a value indicating whether this instance has primary image. - /// - /// true if this instance has primary image; otherwise, false. - [IgnoreDataMember] - public bool HasPrimaryImage - { - get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); } - } - - public ProgramInfoDto() - { - Genres = new List(); - ImageTags = new Dictionary(); - } - - public event PropertyChangedEventHandler PropertyChanged; - } -} \ No newline at end of file diff --git a/MediaBrowser.Model/LiveTv/TimerInfoDto.cs b/MediaBrowser.Model/LiveTv/TimerInfoDto.cs index 16cac945f..c33535a3d 100644 --- a/MediaBrowser.Model/LiveTv/TimerInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/TimerInfoDto.cs @@ -1,4 +1,6 @@ -namespace MediaBrowser.Model.LiveTv +using MediaBrowser.Model.Dto; + +namespace MediaBrowser.Model.LiveTv { public class TimerInfoDto : BaseTimerInfoDto { @@ -30,7 +32,7 @@ /// Gets or sets the program information. /// /// The program information. - public ProgramInfoDto ProgramInfo { get; set; } + public BaseItemDto ProgramInfo { get; set; } } } diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index c567c1f6a..d134cb2e3 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -259,7 +259,6 @@ - diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index cf56fc9ce..5853b5b75 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -357,6 +357,11 @@ namespace MediaBrowser.Server.Implementations.Dto _livetvManager().AddInfoToRecordingDto(item, dto, user); } + else if (item is LiveTvProgram) + { + _livetvManager().AddInfoToProgramDto(item, dto, user); + } + return dto; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index 939d057cb..f24fe0019 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -68,7 +68,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (program != null) { - dto.ProgramInfo = GetProgramInfoDto(program, channel); + dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions()); dto.ProgramInfo.TimerId = dto.Id; dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId; @@ -238,77 +238,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (currentProgram != null) { - dto.CurrentProgram = GetProgramInfoDto(currentProgram, info, user); - } - - return dto; - } - - public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, LiveTvChannel channel, User user = null) - { - var dto = new ProgramInfoDto - { - Id = GetInternalProgramId(item.ServiceName, item.ExternalId).ToString("N"), - ChannelId = GetInternalChannelId(item.ServiceName, item.ExternalChannelId).ToString("N"), - Overview = item.Overview, - Genres = item.Genres, - ExternalId = item.ExternalId, - Name = item.Name, - ServiceName = item.ServiceName, - StartDate = item.StartDate, - OfficialRating = item.OfficialRating, - IsHD = item.IsHD, - OriginalAirDate = item.OriginalAirDate, - Audio = item.Audio, - CommunityRating = GetClientCommunityRating(item.CommunityRating), - IsRepeat = item.IsRepeat, - EpisodeTitle = item.EpisodeTitle, - IsMovie = item.IsMovie, - IsSeries = item.IsSeries, - IsSports = item.IsSports, - IsLive = item.IsLive, - IsNews = item.IsNews, - IsKids = item.IsKids, - IsPremiere = item.IsPremiere, - Type = "Program", - MediaType = item.MediaType, - ServerId = _appHost.SystemId, - ProductionYear = item.ProductionYear - }; - - if (item.EndDate.HasValue) - { - dto.EndDate = item.EndDate.Value; - - dto.RunTimeTicks = (item.EndDate.Value - item.StartDate).Ticks; - } - - if (channel != null) - { - dto.ChannelName = channel.Name; - - if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) - { - dto.ChannelPrimaryImageTag = GetImageTag(channel); - } - } - - var imageTag = GetImageTag(item); - - if (imageTag != null) - { - dto.ImageTags[ImageType.Primary] = imageTag; - _dtoService.AttachPrimaryImageAspectRatio(dto, item, new List - { - ItemFields.PrimaryImageAspectRatio - }); - } - - if (user != null) - { - dto.UserData = _userDataManager.GetUserDataDto(item, user); - - dto.PlayAccess = item.GetPlayAccess(user); + dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, new DtoOptions(), user); } return dto; @@ -365,7 +295,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return name.ToLower().GetMBId(typeof(ILiveTvRecording)); } - public async Task GetTimerInfo(TimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken) + public async Task GetTimerInfo(TimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken) { var info = new TimerInfo { @@ -405,7 +335,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId)) { - var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false); + var program = liveTv.GetInternalProgram(dto.ProgramId); if (program != null) { @@ -426,7 +356,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return info; } - public async Task GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken) + public async Task GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken) { var info = new SeriesTimerInfo { @@ -468,7 +398,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId)) { - var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false); + var program = liveTv.GetInternalProgram(dto.ProgramId); if (program != null) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 52c96bca6..dbae6d03e 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -284,7 +284,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return _libraryManager.GetItemById(id) as LiveTvChannel; } - private LiveTvProgram GetInternalProgram(string id) + internal LiveTvProgram GetInternalProgram(string id) { var guid = new Guid(id); @@ -732,20 +732,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv return GetInternalChannel(internalProgramChannelId); } - public async Task GetProgram(string id, CancellationToken cancellationToken, User user = null) + public async Task GetProgram(string id, CancellationToken cancellationToken, User user = null) { var program = GetInternalProgram(id); - var channel = GetChannel(program); - - var dto = _tvDtoService.GetProgramInfoDto(program, channel, user); + var dto = _dtoService.GetBaseItemDto(program, new DtoOptions(), user); await AddRecordingInfo(new[] { dto }, cancellationToken).ConfigureAwait(false); return dto; } - public async Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken) + public async Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken) { IEnumerable programs = GetPrograms(); @@ -839,19 +837,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv } var returnArray = returnPrograms - .Select(i => - { - var channel = GetChannel(i); - - return _tvDtoService.GetProgramInfoDto(i, channel, user); - }) + .Select(i => _dtoService.GetBaseItemDto(i, new DtoOptions(), user)) .ToArray(); RefreshIfNeeded(programList); await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); - var result = new QueryResult + var result = new QueryResult { Items = returnArray, TotalRecordCount = programList.Count @@ -924,24 +917,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv return result; } - public async Task> GetRecommendedPrograms(RecommendedProgramQuery query, CancellationToken cancellationToken) + public async Task> GetRecommendedPrograms(RecommendedProgramQuery query, CancellationToken cancellationToken) { var internalResult = await GetRecommendedProgramsInternal(query, cancellationToken).ConfigureAwait(false); var user = _userManager.GetUserById(query.UserId); var returnArray = internalResult.Items - .Select(i => - { - var channel = GetChannel(i); - - return _tvDtoService.GetProgramInfoDto(i, channel, user); - }) + .Select(i => _dtoService.GetBaseItemDto(i, new DtoOptions(), user)) .ToArray(); await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); - var result = new QueryResult + var result = new QueryResult { Items = returnArray, TotalRecordCount = internalResult.TotalRecordCount @@ -1020,37 +1008,40 @@ namespace MediaBrowser.Server.Implementations.LiveTv }).Sum(); } - private async Task AddRecordingInfo(IEnumerable programs, CancellationToken cancellationToken) + private async Task AddRecordingInfo(IEnumerable programs, CancellationToken cancellationToken) { var timers = new Dictionary>(); foreach (var program in programs) { + var internalProgram = GetInternalProgram(program.Id); + List timerList; - if (!timers.TryGetValue(program.ServiceName, out timerList)) + if (!timers.TryGetValue(internalProgram.ServiceName, out timerList)) { try { - var tempTimers = await GetService(program.ServiceName).GetTimersAsync(cancellationToken).ConfigureAwait(false); - timers[program.ServiceName] = timerList = tempTimers.ToList(); + var tempTimers = await GetService(internalProgram.ServiceName).GetTimersAsync(cancellationToken).ConfigureAwait(false); + timers[internalProgram.ServiceName] = timerList = tempTimers.ToList(); } catch (Exception ex) { _logger.ErrorException("Error getting timer infos", ex); - timers[program.ServiceName] = timerList = new List(); + timers[internalProgram.ServiceName] = timerList = new List(); } } - var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, program.ExternalId, StringComparison.OrdinalIgnoreCase)); + + var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, internalProgram.ExternalId, StringComparison.OrdinalIgnoreCase)); if (timer != null) { - program.TimerId = _tvDtoService.GetInternalTimerId(program.ServiceName, timer.Id) + program.TimerId = _tvDtoService.GetInternalTimerId(internalProgram.ServiceName, timer.Id) .ToString("N"); if (!string.IsNullOrEmpty(timer.SeriesTimerId)) { - program.SeriesTimerId = _tvDtoService.GetInternalSeriesTimerId(program.ServiceName, timer.SeriesTimerId) + program.SeriesTimerId = _tvDtoService.GetInternalSeriesTimerId(internalProgram.ServiceName, timer.SeriesTimerId) .ToString("N"); } } @@ -1362,6 +1353,43 @@ namespace MediaBrowser.Server.Implementations.LiveTv }; } + public void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, User user = null) + { + var program = (LiveTvProgram)item; + var service = GetService(program); + + var channel = string.IsNullOrEmpty(program.ExternalChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, program.ExternalChannelId)); + + dto.Id = _tvDtoService.GetInternalProgramId(service.Name, program.ExternalId).ToString("N"); + + dto.ChannelId = _tvDtoService.GetInternalChannelId(service.Name, program.ExternalChannelId).ToString("N"); + + dto.StartDate = program.StartDate; + dto.IsRepeat = program.IsRepeat; + dto.EpisodeTitle = program.EpisodeTitle; + dto.ChannelType = program.ChannelType; + dto.Audio = program.Audio; + dto.IsHD = program.IsHD; + dto.IsMovie = program.IsMovie; + dto.IsSeries = program.IsSeries; + dto.IsSports = program.IsSports; + dto.IsLive = program.IsLive; + dto.IsNews = program.IsNews; + dto.IsKids = program.IsKids; + dto.IsPremiere = program.IsPremiere; + dto.OriginalAirDate = program.OriginalAirDate; + + if (channel != null) + { + dto.ChannelName = channel.Name; + + if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) + { + dto.ChannelPrimaryImageTag = _tvDtoService.GetImageTag(channel); + } + } + } + public void AddInfoToRecordingDto(BaseItem item, BaseItemDto dto, User user = null) { var recording = (ILiveTvRecording)item; @@ -1392,7 +1420,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.IsNews = info.IsNews; dto.IsKids = info.IsKids; dto.IsPremiere = info.IsPremiere; - dto.RunTimeTicks = (info.EndDate - info.StartDate).Ticks; dto.OriginalAirDate = info.OriginalAirDate; dto.CanDelete = user == null @@ -1751,7 +1778,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv info.Name = program.Name; info.Overview = program.Overview; info.ProgramId = programDto.Id; - info.ExternalProgramId = programDto.ExternalId; + info.ExternalProgramId = program.ExternalId; if (program.EndDate.HasValue) {