update search

This commit is contained in:
Luke Pulverenti 2016-06-27 18:53:42 -04:00
parent 35e83dc73d
commit c1e83beeac
2 changed files with 55 additions and 52 deletions

View File

@ -979,67 +979,57 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
var recordPath = GetRecordingPath(timer, info); var recordPath = GetRecordingPath(timer, info);
var recordingStatus = RecordingStatus.New; var recordingStatus = RecordingStatus.New;
var isResourceOpen = false;
SemaphoreSlim semaphore = null;
try try
{ {
var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false); var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false);
isResourceOpen = true;
semaphore = result.Item3;
var mediaStreamInfo = result.Item1; var mediaStreamInfo = result.Item1;
var isResourceOpen = true;
// Unfortunately due to the semaphore we have to have a nested try/finally // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg
try //await Task.Delay(3000, cancellationToken).ConfigureAwait(false);
var recorder = await GetRecorder().ConfigureAwait(false);
recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath);
recordPath = EnsureFileUnique(recordPath, timer.Id);
_libraryMonitor.ReportFileSystemChangeBeginning(recordPath);
_fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath));
activeRecordingInfo.Path = recordPath;
var duration = recordingEndDate - DateTime.UtcNow;
_logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture));
_logger.Info("Writing file to path: " + recordPath);
_logger.Info("Opening recording stream from tuner provider");
Action onStarted = () =>
{ {
// HDHR doesn't seem to release the tuner right away after first probing with ffmpeg timer.Status = RecordingStatus.InProgress;
//await Task.Delay(3000, cancellationToken).ConfigureAwait(false); _timerProvider.AddOrUpdate(timer, false);
var recorder = await GetRecorder().ConfigureAwait(false); result.Item3.Release();
isResourceOpen = false;
};
recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath); var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration);
recordPath = EnsureFileUnique(recordPath, timer.Id);
_libraryMonitor.ReportFileSystemChangeBeginning(recordPath); // If it supports supplying duration via url
_fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath)); if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase))
activeRecordingInfo.Path = recordPath;
var duration = recordingEndDate - DateTime.UtcNow;
_logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture));
_logger.Info("Writing file to path: " + recordPath);
_logger.Info("Opening recording stream from tuner provider");
Action onStarted = () =>
{
timer.Status = RecordingStatus.InProgress;
_timerProvider.AddOrUpdate(timer, false);
result.Item3.Release();
isResourceOpen = false;
};
var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration);
// If it supports supplying duration via url
if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase))
{
mediaStreamInfo.Path = pathWithDuration;
mediaStreamInfo.RunTimeTicks = duration.Ticks;
}
await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken).ConfigureAwait(false);
recordingStatus = RecordingStatus.Completed;
_logger.Info("Recording completed: {0}", recordPath);
}
finally
{ {
if (isResourceOpen) mediaStreamInfo.Path = pathWithDuration;
{ mediaStreamInfo.RunTimeTicks = duration.Ticks;
result.Item3.Release();
}
_libraryMonitor.ReportFileSystemChangeComplete(recordPath, true);
} }
await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken).ConfigureAwait(false);
recordingStatus = RecordingStatus.Completed;
_logger.Info("Recording completed: {0}", recordPath);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {
@ -1053,6 +1043,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
} }
finally finally
{ {
if (isResourceOpen && semaphore != null)
{
semaphore.Release();
}
_libraryMonitor.ReportFileSystemChangeComplete(recordPath, true);
ActiveRecordingInfo removed; ActiveRecordingInfo removed;
_activeRecordings.TryRemove(timer.Id, out removed); _activeRecordings.TryRemove(timer.Id, out removed);
} }
@ -1060,10 +1057,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
if (recordingStatus == RecordingStatus.Completed) if (recordingStatus == RecordingStatus.Completed)
{ {
timer.Status = RecordingStatus.Completed; timer.Status = RecordingStatus.Completed;
_timerProvider.AddOrUpdate(timer, false); _timerProvider.Delete(timer);
OnSuccessfulRecording(info.IsSeries, recordPath); OnSuccessfulRecording(info.IsSeries, recordPath);
_timerProvider.Delete(timer);
} }
else if (DateTime.UtcNow < timer.EndDate) else if (DateTime.UtcNow < timer.EndDate)
{ {

View File

@ -62,7 +62,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
} }
finally finally
{ {
File.Delete(tempfile); try
{
File.Delete(tempfile);
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting recording temp file", ex);
}
} }
} }