aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs2
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs71
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs22
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs7
4 files changed, 77 insertions, 25 deletions
diff --git a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs
index 42871866d..864131eef 100644
--- a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs
+++ b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs
@@ -58,7 +58,7 @@ namespace MediaBrowser.Common.ScheduledTasks
{
if (isApplicationStartup)
{
- triggerDate = DateTime.UtcNow.AddMinutes(2);
+ triggerDate = DateTime.UtcNow.AddMinutes(1);
}
else
{
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
index 4e0d6e8d4..b89d8a8d1 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
@@ -364,8 +364,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
return Task.FromResult((IEnumerable<SeriesTimerInfo>)_seriesTimerProvider.GetAll());
}
+ public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress<double> progress)
+ {
+ var timers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
+
+ List<ChannelInfo> channels = null;
+
+ foreach (var timer in timers)
+ {
+ List<ProgramInfo> epgData;
+
+ if (timer.RecordAnyChannel)
+ {
+ if (channels == null)
+ {
+ channels = (await GetChannelsAsync(true, CancellationToken.None).ConfigureAwait(false)).ToList();
+ }
+ var channelIds = channels.Select(i => i.Id).ToList();
+ epgData = GetEpgDataForChannels(channelIds);
+ }
+ else
+ {
+ epgData = GetEpgDataForChannel(timer.ChannelId);
+ }
+ await UpdateTimersForSeriesTimer(epgData, timer).ConfigureAwait(false);
+ }
+ }
+
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{
+ try
+ {
+ return await GetProgramsAsyncInternal(channelId, startDateUtc, endDateUtc, cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error getting programs", ex);
+ return GetEpgDataForChannel(channelId).Where(i => i.StartDate <= endDateUtc && i.EndDate >= startDateUtc);
+ }
+ }
+
+ private async Task<IEnumerable<ProgramInfo>> GetProgramsAsyncInternal(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
+ {
var channels = await GetChannelsAsync(true, cancellationToken).ConfigureAwait(false);
var channel = channels.First(i => string.Equals(i.Id, channelId, StringComparison.OrdinalIgnoreCase));
@@ -373,6 +413,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channel.Number, startDateUtc, endDateUtc, cancellationToken)
.ConfigureAwait(false);
+
var list = programs.ToList();
// Replace the value that came from the provider with a normalized value
@@ -483,7 +524,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
var timer = e.Argument;
_logger.Info("Recording timer fired.");
-
+
try
{
var cancellationTokenSource = new CancellationTokenSource();
@@ -500,14 +541,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
catch (Exception ex)
{
_logger.ErrorException("Error recording stream", ex);
-
- if (DateTime.UtcNow < timer.EndDate)
- {
- const int retryIntervalSeconds = 60;
- _logger.Info("Retrying recording in {0} seconds.", retryIntervalSeconds);
-
- _timerProvider.StartTimer(timer, TimeSpan.FromSeconds(retryIntervalSeconds));
- }
}
}
@@ -626,15 +659,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
_logger.ErrorException("Error recording", ex);
recording.Status = RecordingStatus.Error;
}
+ finally
+ {
+ CancellationTokenSource removed;
+ _activeRecordings.TryRemove(timer.Id, out removed);
+ }
recording.DateLastUpdated = DateTime.UtcNow;
_recordingProvider.Update(recording);
- _timerProvider.Delete(timer);
- _logger.Info("Recording was a success");
if (recording.Status == RecordingStatus.Completed)
{
OnSuccessfulRecording(recording);
+ _timerProvider.Delete(timer);
+ }
+ else if (DateTime.UtcNow < timer.EndDate)
+ {
+ const int retryIntervalSeconds = 60;
+ _logger.Info("Retrying recording in {0} seconds.", retryIntervalSeconds);
+
+ _timerProvider.StartTimer(timer, TimeSpan.FromSeconds(retryIntervalSeconds));
+ }
+ else
+ {
+ _timerProvider.Delete(timer);
+ _recordingProvider.Delete(recording);
}
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
index d53c08150..2efa91137 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
@@ -216,20 +216,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
// Helper.logger.Info("Modifyin channel " + channel.Number);
if (_channelPair.ContainsKey(channel.Number))
{
- string channelName;
if (_channelPair[channel.Number].logo != null)
{
channel.ImageUrl = _channelPair[channel.Number].logo.URL;
channel.HasImage = true;
}
- if (_channelPair[channel.Number].affiliate != null)
- {
- channelName = _channelPair[channel.Number].affiliate;
- }
- else
- {
- channelName = _channelPair[channel.Number].name;
- }
+ string channelName = _channelPair[channel.Number].name;
channel.Name = channelName;
}
else
@@ -245,8 +237,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
ScheduleDirect.ProgramDetails details)
{
//_logger.Debug("Show type is: " + (details.showType ?? "No ShowType"));
- DateTime startAt = DateTime.ParseExact(programInfo.airDateTime, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'",
- CultureInfo.InvariantCulture);
+ DateTime startAt = GetDate(programInfo.airDateTime);
DateTime endAt = startAt.AddSeconds(programInfo.duration);
ProgramAudio audioType = ProgramAudio.Stereo;
@@ -369,6 +360,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
return info;
}
+ private DateTime GetDate(string value)
+ {
+ return DateTime.ParseExact(value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'",
+ CultureInfo.InvariantCulture);
+ }
+
private string GetProgramLogo(string apiUrl, ScheduleDirect.ShowImages images)
{
string url = "";
@@ -408,7 +405,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
{
imageIdString += "\"" + i.Substring(0, 10) + "\",";
}
- ;
});
imageIdString = imageIdString.TrimEnd(',') + "]";
@@ -979,4 +975,4 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
}
}
-}
+} \ No newline at end of file
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index d73b144b8..7a26bf87c 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -1082,6 +1082,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
await CleanDatabaseInternal(newChannelIdList, new[] { typeof(LiveTvChannel).Name }, progress, cancellationToken).ConfigureAwait(false);
await CleanDatabaseInternal(newProgramIdList, new[] { typeof(LiveTvProgram).Name }, progress, cancellationToken).ConfigureAwait(false);
+ var coreService = _services.OfType<EmbyTV.EmbyTV>().FirstOrDefault();
+
+ if (coreService != null)
+ {
+ await coreService.RefreshSeriesTimers(cancellationToken, new Progress<double>()).ConfigureAwait(false);
+ }
+
// Load these now which will prefetch metadata
var dtoOptions = new DtoOptions();
dtoOptions.Fields.Remove(ItemFields.SyncInfo);