aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/LiveTv
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-07-28 23:42:03 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-07-28 23:42:03 -0400
commit4d7f98361894e9de90ab964c3496fb7f613c28e2 (patch)
treef25d0e5beee3222aa1348451873281b8f34aa4a4 /MediaBrowser.Server.Implementations/LiveTv
parenta83d6322e1da3de8abe76290927445577366409a (diff)
update recording scheduler
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv')
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs40
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs16
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs9
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs16
4 files changed, 65 insertions, 16 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
index 0ed87bbff3..3374a3cc9c 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
@@ -33,8 +33,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private readonly LiveTvManager _liveTvManager;
+ public static EmbyTV Current;
+
public EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IConfigurationManager config, ILiveTvManager liveTvManager)
{
+ Current = this;
+
_appHpst = appHost;
_logger = logger;
_httpClient = httpClient;
@@ -48,6 +52,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
_timerProvider.TimerFired += _timerProvider_TimerFired;
}
+ public void Start()
+ {
+ _timerProvider.RestartTimers();
+ }
+
public event EventHandler DataSourceChanged;
public event EventHandler<RecordingStatusChangedEventArgs> RecordingStatusChanged;
@@ -147,7 +156,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
public Task CancelSeriesTimerAsync(string timerId, CancellationToken cancellationToken)
{
- var remove = _seriesTimerProvider.GetAll().SingleOrDefault(r => r.Id == timerId);
+ var remove = _seriesTimerProvider.GetAll().FirstOrDefault(r => string.Equals(r.Id, timerId, StringComparison.OrdinalIgnoreCase));
if (remove != null)
{
_seriesTimerProvider.Delete(remove);
@@ -157,7 +166,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private void CancelTimerInternal(string timerId)
{
- var remove = _timerProvider.GetAll().SingleOrDefault(r => r.Id == timerId);
+ var remove = _timerProvider.GetAll().FirstOrDefault(r => string.Equals(r.Id, timerId, StringComparison.OrdinalIgnoreCase));
if (remove != null)
{
_timerProvider.Delete(remove);
@@ -176,11 +185,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
return Task.FromResult(true);
}
- public Task DeleteRecordingAsync(string recordingId, CancellationToken cancellationToken)
+ public async Task DeleteRecordingAsync(string recordingId, CancellationToken cancellationToken)
{
var remove = _recordingProvider.GetAll().FirstOrDefault(i => string.Equals(i.Id, recordingId, StringComparison.OrdinalIgnoreCase));
if (remove != null)
{
+ if (!string.IsNullOrWhiteSpace(remove.TimerId))
+ {
+ var enableDelay = _activeRecordings.ContainsKey(remove.TimerId);
+
+ CancelTimerInternal(remove.TimerId);
+
+ if (enableDelay)
+ {
+ // A hack yes, but need to make sure the file is closed before attempting to delete it
+ await Task.Delay(3000).ConfigureAwait(false);
+ }
+ }
+
try
{
File.Delete(remove.Path);
@@ -195,7 +217,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
}
_recordingProvider.Delete(remove);
}
- return Task.FromResult(true);
}
public Task CreateTimerAsync(TimerInfo info, CancellationToken cancellationToken)
@@ -293,6 +314,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
if (list.Count > 0)
{
+ SaveEpgDataForChannel(channelId, list);
+
return list;
}
}
@@ -430,7 +453,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
}
var mediaStreamInfo = await GetChannelStream(timer.ChannelId, null, CancellationToken.None);
- var duration = (timer.EndDate - RecordingHelper.GetStartTime(timer)).TotalSeconds + timer.PrePaddingSeconds;
+ var duration = (timer.EndDate - DateTime.UtcNow).TotalSeconds + timer.PostPaddingSeconds;
HttpRequestOptions httpRequestOptions = new HttpRequestOptions()
{
@@ -451,14 +474,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
recordPath = Path.Combine(recordPath, RecordingHelper.GetRecordingName(timer, info));
Directory.CreateDirectory(Path.GetDirectoryName(recordPath));
- var recording = _recordingProvider.GetAll().FirstOrDefault(x => string.Equals(x.Id, info.Id, StringComparison.OrdinalIgnoreCase));
+ var recording = _recordingProvider.GetAll().FirstOrDefault(x => string.Equals(x.ProgramId, info.Id, StringComparison.OrdinalIgnoreCase));
if (recording == null)
{
recording = new RecordingInfo()
{
ChannelId = info.ChannelId,
- Id = info.Id,
+ Id = Guid.NewGuid().ToString("N"),
StartDate = info.StartDate,
EndDate = info.EndDate,
Genres = info.Genres ?? null,
@@ -480,7 +503,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
OriginalAirDate = info.OriginalAirDate,
Status = RecordingStatus.Scheduled,
Overview = info.Overview,
- SeriesTimerId = info.Id.Substring(0, 10)
+ SeriesTimerId = info.Id.Substring(0, 10),
+ TimerId = timer.Id
};
_recordingProvider.Add(recording);
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs
new file mode 100644
index 0000000000..713cb9cd30
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs
@@ -0,0 +1,16 @@
+using MediaBrowser.Controller.Plugins;
+
+namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
+{
+ public class EntryPoint : IServerEntryPoint
+ {
+ public void Run()
+ {
+ EmbyTV.Current.Start();
+ }
+
+ public void Dispose()
+ {
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs
index 0aa1cb2445..db89680d2d 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs
@@ -1,11 +1,10 @@
-using System.Text;
-using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.LiveTv;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
@@ -49,10 +48,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
public static DateTime GetStartTime(TimerInfo timer)
{
- if (timer.StartDate.AddSeconds(-timer.PrePaddingSeconds + 1) < DateTime.UtcNow)
- {
- return DateTime.UtcNow.AddSeconds(1);
- }
return timer.StartDate.AddSeconds(-timer.PrePaddingSeconds);
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs
index 323197aa5c..0c8d2ca2ba 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/TimerManager.cs
@@ -24,6 +24,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
public void RestartTimers()
{
StopTimers();
+
+ foreach (var item in GetAll().ToList())
+ {
+ AddTimer(item);
+ }
}
public void StopTimers()
@@ -90,7 +95,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private void AddTimer(TimerInfo item)
{
- var timespan = RecordingHelper.GetStartTime(item) - DateTime.UtcNow;
+ var startDate = RecordingHelper.GetStartTime(item);
+ var now = DateTime.UtcNow;
+
+ if (startDate < now)
+ {
+ EventHelper.FireEventIfNotNull(TimerFired, this, new GenericEventArgs<TimerInfo> { Argument = item }, Logger);
+ return;
+ }
+
+ var timespan = startDate - now;
var timer = new Timer(TimerCallback, item.Id, timespan, TimeSpan.Zero);