diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-06-28 00:49:40 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-06-28 00:49:40 -0400 |
| commit | 8fe7315afab90470833b11db36d426959262ccfb (patch) | |
| tree | 36bfe8cf3430fabe2da3d06a866725fa7c3fc800 /MediaBrowser.Server.Implementations/LiveTv | |
| parent | 56d7f729a0ee17ece472ccbcff10a7ea5374b5ad (diff) | |
| parent | 7ae83e3c45e9318774e896bc588b35aa33295c32 (diff) | |
Merge branch 'beta' of https://github.com/MediaBrowser/Emby into beta
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv')
4 files changed, 74 insertions, 49 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2d2d18524..8f56554f1 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -979,67 +979,57 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV var recordPath = GetRecordingPath(timer, info); var recordingStatus = RecordingStatus.New; + var isResourceOpen = false; + SemaphoreSlim semaphore = null; try { var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false); + isResourceOpen = true; + semaphore = result.Item3; var mediaStreamInfo = result.Item1; - var isResourceOpen = true; - // Unfortunately due to the semaphore we have to have a nested try/finally - try - { - // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg - //await Task.Delay(3000, cancellationToken).ConfigureAwait(false); - - var recorder = await GetRecorder().ConfigureAwait(false); + // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg + //await Task.Delay(3000, cancellationToken).ConfigureAwait(false); - recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath); - recordPath = EnsureFileUnique(recordPath, timer.Id); + var recorder = await GetRecorder().ConfigureAwait(false); - _libraryMonitor.ReportFileSystemChangeBeginning(recordPath); - _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath)); - activeRecordingInfo.Path = recordPath; + recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath); + recordPath = EnsureFileUnique(recordPath, timer.Id); - var duration = recordingEndDate - DateTime.UtcNow; + _libraryMonitor.ReportFileSystemChangeBeginning(recordPath); + _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath)); + activeRecordingInfo.Path = recordPath; - _logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture)); + var duration = recordingEndDate - DateTime.UtcNow; - _logger.Info("Writing file to path: " + recordPath); - _logger.Info("Opening recording stream from tuner provider"); + _logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture)); - Action onStarted = () => - { - timer.Status = RecordingStatus.InProgress; - _timerProvider.AddOrUpdate(timer, false); - - result.Item3.Release(); - isResourceOpen = false; - }; + _logger.Info("Writing file to path: " + recordPath); + _logger.Info("Opening recording stream from tuner provider"); - var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration); + Action onStarted = () => + { + timer.Status = RecordingStatus.InProgress; + _timerProvider.AddOrUpdate(timer, false); - // If it supports supplying duration via url - if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase)) - { - mediaStreamInfo.Path = pathWithDuration; - mediaStreamInfo.RunTimeTicks = duration.Ticks; - } + result.Item3.Release(); + isResourceOpen = false; + }; - await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken).ConfigureAwait(false); + var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration); - recordingStatus = RecordingStatus.Completed; - _logger.Info("Recording completed: {0}", recordPath); - } - finally + // If it supports supplying duration via url + if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase)) { - if (isResourceOpen) - { - result.Item3.Release(); - } - - _libraryMonitor.ReportFileSystemChangeComplete(recordPath, true); + 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); } catch (OperationCanceledException) { @@ -1053,6 +1043,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } finally { + if (isResourceOpen && semaphore != null) + { + semaphore.Release(); + } + + _libraryMonitor.ReportFileSystemChangeComplete(recordPath, true); + ActiveRecordingInfo removed; _activeRecordings.TryRemove(timer.Id, out removed); } @@ -1060,10 +1057,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV if (recordingStatus == RecordingStatus.Completed) { timer.Status = RecordingStatus.Completed; - _timerProvider.AddOrUpdate(timer, false); + _timerProvider.Delete(timer); OnSuccessfulRecording(info.IsSeries, recordPath); - _timerProvider.Delete(timer); } else if (DateTime.UtcNow < timer.EndDate) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index cad300fac..21879f6f4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs @@ -62,7 +62,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } finally { - File.Delete(tempfile); + try + { + File.Delete(tempfile); + } + catch (Exception ex) + { + _logger.ErrorException("Error deleting recording temp file", ex); + } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 14e4e1093..4d24431e6 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; +using Emby.XmlTv.Entities; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -109,12 +110,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings return results.Select(p => new ProgramInfo() { ChannelId = p.ChannelId, - EndDate = p.EndDate, + EndDate = GetDate(p.EndDate), EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeTitle = p.Episode == null ? null : p.Episode.Title, Genres = p.Categories, Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date, - StartDate = p.StartDate, + StartDate = GetDate(p.StartDate), Name = p.Title, Overview = p.Description, ShortOverview = p.Description, @@ -135,6 +136,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings }); } + private DateTime GetDate(DateTime date) + { + if (date.Kind != DateTimeKind.Utc) + { + date = DateTime.SpecifyKind(date, DateTimeKind.Utc); + } + return date; + } + public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken) { // Add the channel image url diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 95ed2aac1..8d361e6a0 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -656,7 +656,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv item.Audio = info.Audio; item.ChannelId = channel.Id.ToString("N"); item.CommunityRating = item.CommunityRating ?? info.CommunityRating; - item.EndDate = info.EndDate; + item.EpisodeTitle = info.EpisodeTitle; item.ExternalId = info.Id; item.Genres = info.Genres; @@ -673,7 +673,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv item.OfficialRating = item.OfficialRating ?? info.OfficialRating; item.Overview = item.Overview ?? info.Overview; item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks; + + if (item.StartDate != info.StartDate) + { + forceUpdate = true; + } item.StartDate = info.StartDate; + + if (item.EndDate != info.EndDate) + { + forceUpdate = true; + } + item.EndDate = info.EndDate; + item.HomePageUrl = info.HomePageUrl; item.ProductionYear = info.ProductionYear; |
