diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-02-08 13:27:08 -0500 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2016-02-08 13:27:08 -0500 |
| commit | 063fd568323ed94dd220610b5bd8b0b6ac4d9835 (patch) | |
| tree | e8fbbc43a25af2f982034fe279bc22ddf8e6d8c6 /MediaBrowser.Server.Implementations/LiveTv | |
| parent | 00ff642f1955b082649ef7a31f925ccae4661fa8 (diff) | |
| parent | e94467d34b6b753cdb5420e33904bffa41da8053 (diff) | |
Merge pull request #1436 from MediaBrowser/dev
Merge from dev
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv')
| -rw-r--r-- | MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 28 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs | 80 |
2 files changed, 65 insertions, 43 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index ee1614104..408d58244 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -171,7 +171,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV { epgData = GetEpgDataForChannel(timer.ChannelId); } - await UpdateTimersForSeriesTimer(epgData, timer, false).ConfigureAwait(false); + await UpdateTimersForSeriesTimer(epgData, timer, true).ConfigureAwait(false); } var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false); @@ -664,12 +664,22 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV throw new ArgumentNullException("timer"); } + ProgramInfo info = null; + if (string.IsNullOrWhiteSpace(timer.ProgramId)) { - throw new InvalidOperationException("timer.ProgramId is null. Cannot record."); + _logger.Info("Timer {0} has null programId", timer.Id); + } + else + { + info = GetProgramInfoFromCache(timer.ChannelId, timer.ProgramId); } - var info = GetProgramInfoFromCache(timer.ChannelId, timer.ProgramId); + if (info == null) + { + _logger.Info("Unable to find program with Id {0}. Will search using start date", timer.ProgramId); + info = GetProgramInfoFromCache(timer.ChannelId, timer.StartDate); + } if (info == null) { @@ -775,14 +785,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV using (var response = await _httpClient.SendAsync(httpRequestOptions, "GET").ConfigureAwait(false)) { _logger.Info("Opened recording stream from tuner provider"); - + using (var output = _fileSystem.GetFileStream(recordPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { result.Item2.Release(); isResourceOpen = false; _logger.Info("Copying recording stream to file stream"); - + await response.Content.CopyToAsync(output, StreamDefaults.DefaultCopyToBufferSize, linkedToken).ConfigureAwait(false); } } @@ -867,6 +877,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV return epgData.FirstOrDefault(p => string.Equals(p.Id, programId, StringComparison.OrdinalIgnoreCase)); } + private ProgramInfo GetProgramInfoFromCache(string channelId, DateTime startDateUtc) + { + var epgData = GetEpgDataForChannel(channelId); + var startDateTicks = startDateUtc.Ticks; + // Find the first program that starts within 3 minutes + return epgData.FirstOrDefault(p => Math.Abs(startDateTicks - p.StartDate.Ticks) <= TimeSpan.FromMinutes(3).Ticks); + } + private string RecordingPath { get diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index ddbbb030d..f87d4f43f 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -46,53 +46,59 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts protected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { - var url = info.Url; - var urlHash = url.GetMD5().ToString("N"); + var urlHash = info.Url.GetMD5().ToString("N"); - string line; // Read the file and display it line by line. - using (var file = new StreamReader(await GetListingsStream(info, cancellationToken).ConfigureAwait(false))) + using (var reader = new StreamReader(await GetListingsStream(info, cancellationToken).ConfigureAwait(false))) { - var channels = new List<M3UChannel>(); + return GetChannels(reader, urlHash); + } + } + + private List<M3UChannel> GetChannels(StreamReader reader, string urlHash) + { + var channels = new List<M3UChannel>(); - string channnelName = null; - string channelNumber = null; + string channnelName = null; + string channelNumber = null; + string line; - while ((line = file.ReadLine()) != null) + while ((line = reader.ReadLine()) != null) + { + line = line.Trim(); + if (string.IsNullOrWhiteSpace(line)) { - line = line.Trim(); - if (string.IsNullOrWhiteSpace(line)) - { - continue; - } + continue; + } - if (line.StartsWith("#EXTM3U", StringComparison.OrdinalIgnoreCase)) - { - continue; - } + if (line.StartsWith("#EXTM3U", StringComparison.OrdinalIgnoreCase)) + { + continue; + } - if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase)) - { - var parts = line.Split(new[] { ':' }, 2).Last().Split(new[] { ',' }, 2); - channelNumber = parts[0]; - channnelName = parts[1]; - } - else if (!string.IsNullOrWhiteSpace(channelNumber)) + if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase)) + { + line = line.Substring(8); + Logger.Info("Found m3u channel: {0}", line); + var parts = line.Split(new[] { ',' }, 2); + channelNumber = parts[0]; + channnelName = parts[1]; + } + else if (!string.IsNullOrWhiteSpace(channelNumber)) + { + channels.Add(new M3UChannel { - channels.Add(new M3UChannel - { - Name = channnelName, - Number = channelNumber, - Id = ChannelIdPrefix + urlHash + channelNumber, - Path = line - }); - - channelNumber = null; - channnelName = null; - } + Name = channnelName, + Number = channelNumber, + Id = ChannelIdPrefix + urlHash + line.GetMD5().ToString("N"), + Path = line + }); + + channelNumber = null; + channnelName = null; } - return channels; } + return channels; } public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken) @@ -159,8 +165,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts return null; } - //channelId = channelId.Substring(prefix.Length); - var channels = await GetChannels(info, true, cancellationToken).ConfigureAwait(false); var m3uchannels = channels.Cast<M3UChannel>(); var channel = m3uchannels.FirstOrDefault(c => string.Equals(c.Id, channelId, StringComparison.OrdinalIgnoreCase)); |
