From e376c31436c72fa870a2c1991ff48d3543069ce0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 15 Aug 2015 17:58:52 -0400 Subject: [PATCH] fix subs not starting initially --- .../LiveTv/EmbyTV/EmbyTV.cs | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index cf294997b..6e5749250 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -238,20 +238,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV return Task.FromResult(0); } - public Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) + public async Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) { info.Id = Guid.NewGuid().ToString("N"); - UpdateTimersForSeriesTimer(info); + await UpdateTimersForSeriesTimer(info).ConfigureAwait(false); _seriesTimerProvider.Add(info); - return Task.FromResult(true); } - public Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) + public async Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) { _seriesTimerProvider.Update(info); - UpdateTimersForSeriesTimer(info); - return Task.FromResult(true); + await UpdateTimersForSeriesTimer(info).ConfigureAwait(false); } public Task UpdateTimerAsync(TimerInfo info, CancellationToken cancellationToken) @@ -594,12 +592,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV return _config.GetConfiguration("livetv"); } - private void UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer) + private async Task UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer) { List epgData; if (seriesTimer.RecordAnyChannel) { - epgData = GetEpgDataForAllChannels(); + var channels = await GetChannelsAsync(CancellationToken.None).ConfigureAwait(false); + var channelIds = channels.Select(i => i.Id).ToList(); + epgData = GetEpgDataForChannels(channelIds); } else { @@ -656,9 +656,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV allPrograms = allPrograms.Where(epg => string.Equals(epg.ChannelId, seriesTimer.ChannelId, StringComparison.OrdinalIgnoreCase)); } - allPrograms = allPrograms.Where(epg => seriesTimer.Days.Contains(epg.StartDate.DayOfWeek)); + allPrograms = allPrograms.Where(i => seriesTimer.Days.Contains(i.StartDate.DayOfWeek)); - return allPrograms.Where(epg => string.Equals(epg.SeriesId, seriesTimer.SeriesId, StringComparison.OrdinalIgnoreCase)); + return allPrograms.Where(i => string.Equals(i.SeriesId, seriesTimer.SeriesId, StringComparison.OrdinalIgnoreCase)); } private string GetChannelEpgCachePath(string channelId) @@ -690,16 +690,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV return new List(); } } - private List GetEpgDataForAllChannels() + private List GetEpgDataForChannels(List channelIds) { - List channelEpg = new List(); - DirectoryInfo dir = new DirectoryInfo(Path.Combine(DataPath, "epg")); - List channels = dir.GetFiles("*").Where(i => string.Equals(i.Extension, ".json", StringComparison.OrdinalIgnoreCase)).Select(f => f.Name).ToList(); - foreach (var channel in channels) - { - channelEpg.AddRange(GetEpgDataForChannel(channel)); - } - return channelEpg; + return channelIds.SelectMany(GetEpgDataForChannel).ToList(); } public void Dispose()