From ffad9c27e4844eeab235f88cb45739370d22a83a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 13 Dec 2016 13:23:03 -0500 Subject: [PATCH] automatically adjust timer schedules to program changes --- Emby.Server.Core/ApplicationHost.cs | 1 + .../Emby.Server.Implementations.csproj | 1 + .../LiveTv/EmbyTV/EmbyTV.cs | 22 ++++++++++++++++++- .../LiveTv/EmbyTV/RecordingHelper.cs | 6 +++++ .../LiveTv/LiveTvManager.cs | 1 + .../Configuration/ServerConfiguration.cs | 2 ++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index a6d2d32c0b..3b3313169d 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -489,6 +489,7 @@ namespace Emby.Server.Core { var migrations = new List { + new LibraryScanMigration(ServerConfigurationManager, TaskManager) }; foreach (var task in migrations) diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 92e83f05b3..df0301fc35 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -181,6 +181,7 @@ + diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index f5bef058d2..84a255c7a9 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -328,15 +328,35 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } await UpdateTimersForSeriesTimer(epgData, timer, true).ConfigureAwait(false); } + } + public async Task RefreshTimers(CancellationToken cancellationToken, IProgress progress) + { var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false); - foreach (var timer in timers.ToList()) + foreach (var timer in timers) { if (DateTime.UtcNow > timer.EndDate && !_activeRecordings.ContainsKey(timer.Id)) { OnTimerOutOfDate(timer); + continue; + } + + if (string.IsNullOrWhiteSpace(timer.ProgramId) || string.IsNullOrWhiteSpace(timer.ChannelId)) + { + continue; + } + + var epg = GetEpgDataForChannel(timer.ChannelId); + var program = epg.FirstOrDefault(i => string.Equals(i.Id, timer.ProgramId, StringComparison.OrdinalIgnoreCase)); + if (program == null) + { + OnTimerOutOfDate(timer); + continue; } + + RecordingHelper.CopyProgramInfoToTimerInfo(program, timer); + _timerProvider.Update(timer); } } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs index 881aaaf0d6..a5b19ff524 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs @@ -41,6 +41,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public static void CopyProgramInfoToTimerInfo(ProgramInfo programInfo, TimerInfo timerInfo) { + timerInfo.Name = programInfo.Name; + timerInfo.StartDate = programInfo.StartDate; + timerInfo.EndDate = programInfo.EndDate; + timerInfo.ChannelId = programInfo.ChannelId; + timerInfo.SeasonNumber = programInfo.SeasonNumber; timerInfo.EpisodeNumber = programInfo.EpisodeNumber; timerInfo.IsMovie = programInfo.IsMovie; @@ -54,6 +59,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV timerInfo.HomePageUrl = programInfo.HomePageUrl; timerInfo.CommunityRating = programInfo.CommunityRating; + timerInfo.Overview = programInfo.Overview; timerInfo.ShortOverview = programInfo.ShortOverview; timerInfo.OfficialRating = programInfo.OfficialRating; timerInfo.IsRepeat = programInfo.IsRepeat; diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index faf9687f40..5e12fc9b98 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1231,6 +1231,7 @@ namespace Emby.Server.Implementations.LiveTv if (coreService != null) { await coreService.RefreshSeriesTimers(cancellationToken, new Progress()).ConfigureAwait(false); + await coreService.RefreshTimers(cancellationToken, new Progress()).ConfigureAwait(false); } // Load these now which will prefetch metadata diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index f5c4bba508..493fe1bd24 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -201,6 +201,7 @@ namespace MediaBrowser.Model.Configuration public bool DisplayCollectionsView { get; set; } public string[] LocalNetworkAddresses { get; set; } public string[] CodecsUsed { get; set; } + public string[] Migrations { get; set; } public bool EnableChannelView { get; set; } public bool EnableExternalContentInSuggestions { get; set; } public bool EnableSimpleArtistDetection { get; set; } @@ -213,6 +214,7 @@ namespace MediaBrowser.Model.Configuration { LocalNetworkAddresses = new string[] { }; CodecsUsed = new string[] { }; + Migrations = new string[] { }; ImageExtractionTimeoutMs = 0; EnableLocalizedGuids = true;