From 9ec1376e5fba1f42042197c9086bdb8cef14231a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 11 Oct 2015 12:12:53 -0400 Subject: [PATCH] recording fixes --- .../LiveTv/ILiveTvManager.cs | 3 +- MediaBrowser.Model/Querying/ItemFields.cs | 5 +++ .../Dto/DtoService.cs | 2 +- .../LiveTv/Listings/SchedulesDirect.cs | 24 ++++++++----- .../LiveTv/LiveTvManager.cs | 35 +++++++++++-------- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 1458c1bc2e..241b01405a 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -338,8 +338,9 @@ namespace MediaBrowser.Controller.LiveTv /// /// The item. /// The dto. + /// if set to true [add channel information]. /// The user. - void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, User user = null); + void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, bool addChannelInfo, User user = null); /// /// Saves the tuner host. /// diff --git a/MediaBrowser.Model/Querying/ItemFields.cs b/MediaBrowser.Model/Querying/ItemFields.cs index 0362b7aedd..eea561f72b 100644 --- a/MediaBrowser.Model/Querying/ItemFields.cs +++ b/MediaBrowser.Model/Querying/ItemFields.cs @@ -35,6 +35,11 @@ /// CanDownload, + /// + /// The channel information + /// + ChannelInfo, + /// /// The chapters /// diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 4c54a43625..a880914a3e 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -398,7 +398,7 @@ namespace MediaBrowser.Server.Implementations.Dto else if (item is LiveTvProgram) { - _livetvManager().AddInfoToProgramDto(item, dto, user); + _livetvManager().AddInfoToProgramDto(item, dto, fields.Contains(ItemFields.ChannelInfo), user); } return dto; diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 083b6e48a2..65b920c90a 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -82,7 +82,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings UserAgent = UserAgent, CancellationToken = cancellationToken, // The data can be large so give it some extra time - TimeoutMs = 60000 + TimeoutMs = 60000, + LogErrorResponseBody = true }; httpOptions.RequestHeaders["token"] = token; @@ -123,7 +124,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { Url = ApiUrl + "/programs", UserAgent = UserAgent, - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; httpOptions.RequestHeaders["token"] = token; @@ -213,7 +215,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { Url = ApiUrl + "/lineups/" + info.ListingsId, UserAgent = UserAgent, - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; httpOptions.RequestHeaders["token"] = token; @@ -451,7 +454,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings Url = ApiUrl + "/metadata/programs", UserAgent = UserAgent, CancellationToken = cancellationToken, - RequestContent = imageIdString + RequestContent = imageIdString, + LogErrorResponseBody = true }; List images; using (var innerResponse2 = await _httpClient.Post(httpOptions)) @@ -478,7 +482,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { Url = ApiUrl + "/headends?country=" + country + "&postalcode=" + location, UserAgent = UserAgent, - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; options.RequestHeaders["token"] = token; @@ -595,7 +600,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings Url = ApiUrl + "/token", UserAgent = UserAgent, RequestContent = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}", - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; //_logger.Info("Obtaining token from Schedules Direct from addres: " + httpOptions.Url + " with body " + // httpOptions.RequestContent); @@ -633,7 +639,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { Url = ApiUrl + "/lineups/" + info.ListingsId, UserAgent = UserAgent, - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; httpOptions.RequestHeaders["token"] = token; @@ -673,7 +680,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { Url = ApiUrl + "/lineups", UserAgent = UserAgent, - CancellationToken = cancellationToken + CancellationToken = cancellationToken, + LogErrorResponseBody = true }; options.RequestHeaders["token"] = token; diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index a11400a648..40e837ed7c 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -734,15 +734,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv recording.IsSports = info.IsSports; recording.SeriesTimerId = info.SeriesTimerId; recording.StartDate = info.StartDate; + + var statusChanged = info.Status != recording.Status; + recording.Status = info.Status; recording.ServiceName = serviceName; - var originalPath = item.Path; + var pathChanged = false; if (!string.IsNullOrEmpty(info.Path)) { - item.Path = info.Path; + pathChanged = !string.Equals(item.Path, info.Path); var fileInfo = _fileSystem.GetFileInfo(info.Path); recording.DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo); @@ -750,16 +753,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv } else if (!string.IsNullOrEmpty(info.Url)) { + pathChanged = !string.Equals(item.Path, info.Url); item.Path = info.Url; } - var pathChanged = !string.Equals(originalPath, item.Path); - if (isNew) { await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); } - else if (pathChanged || info.DateLastUpdated > recording.DateLastSaved || info.Status != recording.Status) + else if (pathChanged || info.DateLastUpdated > recording.DateLastSaved || statusChanged) { await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); } @@ -1388,25 +1390,25 @@ namespace MediaBrowser.Server.Implementations.LiveTv }; } - public void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, User user = null) + public void AddInfoToProgramDto(BaseItem item, BaseItemDto dto, bool addChannelInfo, User user = null) { var program = (LiveTvProgram)item; var service = GetService(program); - var channel = GetInternalChannel(program.ChannelId); - dto.Id = _tvDtoService.GetInternalProgramId(service.Name, program.ExternalId).ToString("N"); dto.StartDate = program.StartDate; - dto.IsRepeat = program.IsRepeat; dto.EpisodeTitle = program.EpisodeTitle; - dto.ChannelType = program.ChannelType; dto.Audio = program.Audio; if (program.IsHD.HasValue && program.IsHD.Value) { dto.IsHD = program.IsHD; } + if (program.IsRepeat) + { + dto.IsRepeat = program.IsRepeat; + } if (program.IsMovie) { dto.IsMovie = program.IsMovie; @@ -1436,13 +1438,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.IsPremiere = program.IsPremiere; } - if (channel != null) + if (addChannelInfo) { - dto.ChannelName = channel.Name; + var channel = GetInternalChannel(program.ChannelId); - if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) + if (channel != null) { - dto.ChannelPrimaryImageTag = _tvDtoService.GetImageTag(channel); + dto.ChannelName = channel.Name; + + if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) + { + dto.ChannelPrimaryImageTag = _tvDtoService.GetImageTag(channel); + } } } }