diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2ac06cda8..b529e9134 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -134,11 +134,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress progress) { - var timers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false); + var seriesTimers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false); List channels = null; - foreach (var timer in timers) + foreach (var timer in seriesTimers) { List epgData; @@ -157,6 +157,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } await UpdateTimersForSeriesTimer(epgData, timer).ConfigureAwait(false); } + + var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false); + + foreach (var timer in timers.ToList()) + { + if (DateTime.UtcNow > timer.EndDate && !_activeRecordings.ContainsKey(timer.Id)) + { + _timerProvider.Delete(timer); + } + } } private List _channelCache = null; @@ -684,7 +694,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV TimerId = timer.Id, ShowId = info.ShowId }; - _recordingProvider.Add(recording); + _recordingProvider.AddOrUpdate(recording); } try @@ -709,7 +719,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV recording.Path = recordPath; recording.Status = RecordingStatus.InProgress; recording.DateLastUpdated = DateTime.UtcNow; - _recordingProvider.Update(recording); + _recordingProvider.AddOrUpdate(recording); _logger.Info("Beginning recording."); @@ -757,7 +767,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } recording.DateLastUpdated = DateTime.UtcNow; - _recordingProvider.Update(recording); + _recordingProvider.AddOrUpdate(recording); if (recording.Status == RecordingStatus.Completed) { @@ -828,12 +838,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV private async Task UpdateTimersForSeriesTimer(List epgData, SeriesTimerInfo seriesTimer) { + var newTimers = GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll()).ToList(); + var registration = await GetRegistrationInfo("seriesrecordings").ConfigureAwait(false); if (registration.IsValid) { - var newTimers = GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll()).ToList(); - foreach (var timer in newTimers) { _timerProvider.AddOrUpdate(timer); diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs index d89c1c0cb..f46daa6d5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV private void UpdateList(List newList) { var file = _dataPath + ".json"; - _fileSystem.CreateDirectory(Path.GetDirectoryName(file)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(file)); lock (_fileDataLock) { @@ -112,6 +112,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV UpdateList(list); } + public void AddOrUpdate(T item) + { + var list = GetAll().ToList(); + + if (!list.Any(i => EqualityComparer(i, item))) + { + Add(item); + } + else + { + Update(item); + } + } + public virtual void Delete(T item) { var list = GetAll().Where(i => !EqualityComparer(i, item)).ToList(); diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs index 94ad5e5ce..80bb671fa 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs @@ -76,20 +76,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV AddTimer(item); } - public void AddOrUpdate(TimerInfo item) - { - var list = GetAll().ToList(); - - if (!list.Any(i => EqualityComparer(i, item))) - { - Add(item); - } - else - { - Update(item); - } - } - private void AddTimer(TimerInfo item) { var startDate = RecordingHelper.GetStartTime(item); @@ -108,7 +94,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV public void StartTimer(TimerInfo item, TimeSpan length) { StopTimer(item); - + var timer = new Timer(TimerCallback, item.Id, length, TimeSpan.Zero); if (!_timers.TryAdd(item.Id, timer))