diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-02-24 15:21:11 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-24 15:21:11 -0500 |
| commit | cd6b7f3bdc5bcbc6c68131cc40b71b68ac1b73a6 (patch) | |
| tree | 48b8f6d94e3f762a486aa1c4fa6937cf23c18dee /Emby.Server.Implementations/LiveTv | |
| parent | c07e774ca9c0f234ec6899e17fc70301d1990290 (diff) | |
| parent | 66a844e6399f1d79be8e10ea098ba6768e0d123b (diff) | |
Merge pull request #2489 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Server.Implementations/LiveTv')
13 files changed, 142 insertions, 93 deletions
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index bbb060203..926d82f94 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -474,17 +474,30 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public ChannelInfo GetEpgChannelFromTunerChannel(List<NameValuePair> mappings, ChannelInfo tunerChannel, List<ChannelInfo> epgChannels) { - var tunerChannelId = string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId) - ? tunerChannel.Id - : tunerChannel.TunerChannelId; + if (!string.IsNullOrWhiteSpace(tunerChannel.Id)) + { + var mappedTunerChannelId = GetMappedChannel(tunerChannel.Id, mappings); + + if (string.IsNullOrWhiteSpace(mappedTunerChannelId)) + { + mappedTunerChannelId = tunerChannel.Id; + } + + var channel = epgChannels.FirstOrDefault(i => string.Equals(mappedTunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase)); + + if (channel != null) + { + return channel; + } + } - if (!string.IsNullOrWhiteSpace(tunerChannelId)) + if (!string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId)) { - var mappedTunerChannelId = GetMappedChannel(tunerChannelId, mappings); + var mappedTunerChannelId = GetMappedChannel(tunerChannel.TunerChannelId, mappings); if (string.IsNullOrWhiteSpace(mappedTunerChannelId)) { - mappedTunerChannelId = tunerChannelId; + mappedTunerChannelId = tunerChannel.TunerChannelId; } var channel = epgChannels.FirstOrDefault(i => string.Equals(mappedTunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase)); @@ -635,6 +648,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV existingTimer.Status == RecordingStatus.Completed) { existingTimer.Status = RecordingStatus.New; + existingTimer.IsManual = true; _timerProvider.Update(existingTimer); return Task.FromResult(existingTimer.Id); } @@ -663,6 +677,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV RecordingHelper.CopyProgramInfoToTimerInfo(programInfo, timer); } + timer.IsManual = true; _timerProvider.Add(timer); return Task.FromResult(timer.Id); } @@ -758,6 +773,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV existingTimer.PostPaddingSeconds = updatedTimer.PostPaddingSeconds; existingTimer.IsPostPaddingRequired = updatedTimer.IsPostPaddingRequired; existingTimer.IsPrePaddingRequired = updatedTimer.IsPrePaddingRequired; + + _timerProvider.Update(existingTimer); } return Task.FromResult(true); @@ -986,6 +1003,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV foreach (var program in programs) { program.ChannelId = channelId; + + if (provider.Item2.EnableNewProgramIds) + { + program.Id += "_" + channelId; + } } if (programs.Count > 0) @@ -1172,7 +1194,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV }; var isAudio = false; - await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, false, cancellationToken).ConfigureAwait(false); + await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, cancellationToken).ConfigureAwait(false); return new List<MediaSourceInfo> { @@ -2198,6 +2220,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private bool ShouldCancelTimerForSeriesTimer(SeriesTimerInfo seriesTimer, TimerInfo timer) { + if (timer.IsManual) + { + return false; + } + if (!seriesTimer.RecordAnyTime) { if (Math.Abs(seriesTimer.StartDate.TimeOfDay.Ticks - timer.StartDate.TimeOfDay.Ticks) >= TimeSpan.FromMinutes(5).Ticks) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index 9a8282250..7460a9f06 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs @@ -65,6 +65,15 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } } + private bool CopySubtitles + { + get + { + return false; + //return string.Equals(OutputFormat, "mkv", StringComparison.OrdinalIgnoreCase); + } + } + public string GetOutputPath(MediaSourceInfo mediaSource, string targetFile) { return Path.ChangeExtension(targetFile, "." + OutputFormat); @@ -154,9 +163,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV var durationParam = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks); var inputModifiers = "-fflags +genpts -async 1 -vsync -1"; - var mapArgs = string.Equals(OutputFormat, "mkv", StringComparison.OrdinalIgnoreCase) ? "-map 0" : "-sn"; - mapArgs = "-sn"; - var commandLineArgs = "-i \"{0}\"{4} " + mapArgs + " {2} -map_metadata -1 -threads 0 {3} -y \"{1}\""; + var mapArgs = "-map 0 -ignore_unknown"; + var commandLineArgs = "-i \"{0}\"{5} " + mapArgs + " {2} -map_metadata -1 -threads 0 {3}{4} -y \"{1}\""; long startTimeTicks = 0; //if (mediaSource.DateLiveStreamOpened.HasValue) @@ -184,7 +192,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV (analyzeDurationSeconds * 1000000).ToString(CultureInfo.InvariantCulture); inputModifiers += analyzeDuration; - commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), durationParam); + var subtitleArgs = CopySubtitles ? " -codec:s copy" : " -sn"; + + commandLineArgs = string.Format(commandLineArgs, inputTempFile, targetFile, videoArgs, GetAudioArgs(mediaSource), subtitleArgs, durationParam); return inputModifiers + " " + commandLineArgs; } @@ -197,7 +207,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV // do not copy aac because many players have difficulty with aac_latm if (_liveTvOptions.EnableOriginalAudioWithEncodedRecordings && !string.Equals(inputAudioCodec, "aac", StringComparison.OrdinalIgnoreCase)) { - return "-codec:a:0 copy"; + return "-codec:a copy"; } var audioChannels = 2; @@ -206,7 +216,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { audioChannels = audioStream.Channels ?? audioChannels; } - return "-codec:a:0 aac -strict experimental -ab 320000"; + return "-codec:a aac -strict experimental -ab 320000"; } private bool EncodeVideo(MediaSourceInfo mediaSource) @@ -261,7 +271,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { _logger.Info("Calling recording process.WaitForExit for {0}", _targetPath); - if (_process.WaitForExit(5000)) + if (_process.WaitForExit(10000)) { return; } diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 0d7a26553..f76735030 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -81,12 +81,6 @@ namespace Emby.Server.Implementations.LiveTv.Listings return programsInfo; } - if (string.IsNullOrWhiteSpace(info.ListingsId)) - { - _logger.Warn("ListingsId is null, returning empty program list"); - return programsInfo; - } - var dates = GetScheduleRequestDates(startDateUtc, endDateUtc); string stationID = channelId; @@ -156,7 +150,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings programDetails.Where(p => p.hasImageArtwork).Select(p => p.programID) .ToList(); - var images = await GetImageForPrograms(info, programIdsWithImages, cancellationToken); + var images = await GetImageForPrograms(info, programIdsWithImages, cancellationToken).ConfigureAwait(false); var schedules = dailySchedules.SelectMany(d => d.programs); foreach (ScheduleDirect.Program schedule in schedules) diff --git a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index d7803f9e3..c22bb1171 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.IO.Compression; using System.Linq; using System.Net; using System.Text; @@ -26,13 +27,15 @@ namespace Emby.Server.Implementations.LiveTv.Listings private readonly IHttpClient _httpClient; private readonly ILogger _logger; private readonly IFileSystem _fileSystem; + private readonly IZipClient _zipClient; - public XmlTvListingsProvider(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IFileSystem fileSystem) + public XmlTvListingsProvider(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IFileSystem fileSystem, IZipClient zipClient) { _config = config; _httpClient = httpClient; _logger = logger; _fileSystem = fileSystem; + _zipClient = zipClient; } public string Name @@ -63,7 +66,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings var cacheFile = Path.Combine(_config.ApplicationPaths.CachePath, "xmltv", cacheFilename); if (_fileSystem.FileExists(cacheFile)) { - return cacheFile; + return UnzipIfNeeded(path, cacheFile); } _logger.Info("Downloading xmltv listings from {0}", path); @@ -103,7 +106,30 @@ namespace Emby.Server.Implementations.LiveTv.Listings } _logger.Debug("Returning xmltv path {0}", cacheFile); - return cacheFile; + return UnzipIfNeeded(path, cacheFile); + } + + private string UnzipIfNeeded(string originalUrl, string file) + { + //var ext = Path.GetExtension(originalUrl); + + //if (string.Equals(ext, ".gz", StringComparison.OrdinalIgnoreCase)) + //{ + // using (var stream = _fileSystem.OpenRead(file)) + // { + // var tempFolder = Path.Combine(_config.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString()); + // _fileSystem.CreateDirectory(tempFolder); + + // _zipClient.ExtractAllFromZip(stream, tempFolder, true); + + // return _fileSystem.GetFiles(tempFolder, true) + // .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) + // .Select(i => i.FullName) + // .FirstOrDefault(); + // } + //} + + return file; } public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) @@ -122,6 +148,8 @@ namespace Emby.Server.Implementations.LiveTv.Listings } } + _logger.Debug("Getting xmltv programs for channel {0}", channelId); + var path = await GetXml(info.Path, cancellationToken).ConfigureAwait(false); var reader = new XmlTvReader(path, GetLanguage()); @@ -140,7 +168,6 @@ namespace Emby.Server.Implementations.LiveTv.Listings EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeTitle = episodeTitle, Genres = p.Categories, - Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date, StartDate = GetDate(p.StartDate), Name = p.Title, Overview = p.Description, @@ -180,6 +207,9 @@ namespace Emby.Server.Implementations.LiveTv.Listings programInfo.ShowId = uniqueString.GetMD5().ToString("N"); } + // Construct an id from the channel and start date + programInfo.Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate); + if (programInfo.IsMovie) { programInfo.IsSeries = false; diff --git a/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs b/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs index 2ee6869f6..e2f973699 100644 --- a/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs +++ b/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs @@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.LiveTv _logger = logger; } - public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, bool assumeInterlaced, CancellationToken cancellationToken) + public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, CancellationToken cancellationToken) { var originalRuntime = mediaSource.RunTimeTicks; @@ -96,17 +96,6 @@ namespace Emby.Server.Implementations.LiveTv videoStream.IsAVC = null; } - if (assumeInterlaced) - { - foreach (var mediaStream in mediaSource.MediaStreams) - { - if (mediaStream.Type == MediaStreamType.Video) - { - mediaStream.IsInterlaced = true; - } - } - } - // Try to estimate this mediaSource.InferTotalBitrate(true); } diff --git a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs index e73378dde..43b055098 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -278,6 +278,13 @@ namespace Emby.Server.Implementations.LiveTv { var program = _libraryManager.GetItemList(new InternalItemsQuery { + IncludeItemTypes = new string[] { typeof(Series).Name }, + Name = seriesName, + Limit = 1, + ImageTypes = new ImageType[] { ImageType.Primary } + + }).FirstOrDefault() ?? _libraryManager.GetItemList(new InternalItemsQuery + { IncludeItemTypes = new string[] { typeof(LiveTvProgram).Name }, ExternalSeriesId = programSeriesId, Limit = 1, diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index e30280967..654777b3c 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -598,15 +598,15 @@ namespace Emby.Server.Implementations.LiveTv item.ParentId = channel.Id; //item.ChannelType = channelType; - if (!string.Equals(item.ServiceName, serviceName, StringComparison.Ordinal)) - { - forceUpdate = true; - } item.ServiceName = serviceName; item.Audio = info.Audio; item.ChannelId = channel.Id.ToString("N"); item.CommunityRating = item.CommunityRating ?? info.CommunityRating; + if ((item.CommunityRating ?? 0).Equals(0)) + { + item.CommunityRating = null; + } item.EpisodeTitle = info.EpisodeTitle; item.ExternalId = info.Id; @@ -1307,7 +1307,7 @@ namespace Emby.Server.Implementations.LiveTv var isKids = false; var iSSeries = false; - var channelPrograms = await service.GetProgramsAsync(GetItemExternalId(currentChannel), start, end, cancellationToken).ConfigureAwait(false); + var channelPrograms = (await service.GetProgramsAsync(GetItemExternalId(currentChannel), start, end, cancellationToken).ConfigureAwait(false)).ToList(); var existingPrograms = _libraryManager.GetItemList(new InternalItemsQuery { @@ -1405,7 +1405,7 @@ namespace Emby.Server.Implementations.LiveTv double percent = numComplete; percent /= allChannelsList.Count; - progress.Report(80 * percent + 10); + progress.Report(85 * percent + 15); } progress.Report(100); @@ -1477,12 +1477,7 @@ namespace Emby.Server.Implementations.LiveTv private DateTime _lastRecordingRefreshTime; private async Task RefreshRecordings(CancellationToken cancellationToken) { - const int cacheMinutes = 3; - - if ((DateTime.UtcNow - _lastRecordingRefreshTime).TotalMinutes < cacheMinutes) - { - return; - } + const int cacheMinutes = 2; await _refreshRecordingsLock.WaitAsync(cancellationToken).ConfigureAwait(false); @@ -1885,7 +1880,7 @@ namespace Emby.Server.Implementations.LiveTv : _tvDtoService.GetInternalTimerId(service.Name, info.TimerId).ToString("N"); dto.StartDate = info.StartDate; - dto.RecordingStatus = info.Status; + dto.Status = info.Status.ToString(); dto.IsRepeat = info.IsRepeat; dto.EpisodeTitle = info.EpisodeTitle; dto.IsMovie = info.IsMovie; @@ -2866,6 +2861,7 @@ namespace Emby.Server.Implementations.LiveTv { info.Id = Guid.NewGuid().ToString("N"); config.ListingProviders.Add(info); + info.EnableNewProgramIds = true; } else { @@ -2930,7 +2926,7 @@ namespace Emby.Server.Implementations.LiveTv var result = new TunerChannelMapping { Name = tunerChannel.Name, - Id = tunerChannel.TunerChannelId + Id = tunerChannel.Id }; if (!string.IsNullOrWhiteSpace(tunerChannel.Number)) @@ -2938,11 +2934,6 @@ namespace Emby.Server.Implementations.LiveTv result.Name = tunerChannel.Number + " " + result.Name; } - if (string.IsNullOrWhiteSpace(result.Id)) - { - result.Id = tunerChannel.Id; - } - var providerChannel = EmbyTV.EmbyTV.Current.GetEpgChannelFromTunerChannel(mappings, tunerChannel, epgChannels); if (providerChannel != null) diff --git a/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs b/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs index e25e28484..747e0fdd3 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs @@ -126,14 +126,12 @@ namespace Emby.Server.Implementations.LiveTv var keys = openToken.Split(new[] { StreamIdDelimeter }, 3); var mediaSourceId = keys.Length >= 3 ? keys[2] : null; IDirectStreamProvider directStreamProvider = null; - var assumeInterlaced = false; if (string.Equals(keys[0], typeof(LiveTvChannel).Name, StringComparison.OrdinalIgnoreCase)) { var info = await _liveTvManager.GetChannelStream(keys[1], mediaSourceId, cancellationToken).ConfigureAwait(false); stream = info.Item1; directStreamProvider = info.Item2; - assumeInterlaced = info.Item3; } else { @@ -148,7 +146,7 @@ namespace Emby.Server.Implementations.LiveTv } else { - await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, assumeInterlaced, cancellationToken).ConfigureAwait(false); + await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, cancellationToken).ConfigureAwait(false); } } catch (Exception ex) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index 5fae3f666..5ac3812b0 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -35,10 +35,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts MediaEncoder = mediaEncoder; } - protected abstract Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); + protected abstract Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); public abstract string Type { get; } - public async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo tuner, bool enableCache, CancellationToken cancellationToken) + public async Task<List<ChannelInfo>> GetChannels(TunerHostInfo tuner, bool enableCache, CancellationToken cancellationToken) { ChannelCache cache = null; var key = tuner.Id; @@ -73,7 +73,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts .ToList(); } - public async Task<IEnumerable<ChannelInfo>> GetChannels(bool enableCache, CancellationToken cancellationToken) + public async Task<List<ChannelInfo>> GetChannels(bool enableCache, CancellationToken cancellationToken) { var list = new List<ChannelInfo>(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index 1c7c0828c..2e70e1ac1 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -9,17 +9,14 @@ using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.IO; using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.IO; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Net; @@ -66,7 +63,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return id; } - private async Task<IEnumerable<Channels>> GetLineup(TunerHostInfo info, CancellationToken cancellationToken) + private async Task<List<Channels>> GetLineup(TunerHostInfo info, CancellationToken cancellationToken) { var options = new HttpRequestOptions { @@ -74,7 +71,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun CancellationToken = cancellationToken, BufferContent = false }; - using (var stream = await _httpClient.Get(options)) + using (var stream = await _httpClient.Get(options).ConfigureAwait(false)) { var lineup = JsonSerializer.DeserializeFromStream<List<Channels>>(stream) ?? new List<Channels>(); @@ -87,7 +84,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } } - protected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { var lineup = await GetLineup(info, cancellationToken).ConfigureAwait(false); @@ -102,7 +99,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun AudioCodec = i.AudioCodec, VideoCodec = i.VideoCodec, ChannelType = ChannelType.TV - }); + + }).ToList(); } private readonly Dictionary<string, DiscoverResponse> _modelCache = new Dictionary<string, DiscoverResponse>(); @@ -127,7 +125,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun CacheMode = CacheMode.Unconditional, TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds), BufferContent = false - })) + + }).ConfigureAwait(false)) { var response = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream); @@ -169,7 +168,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun CancellationToken = cancellationToken, TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds), BufferContent = false - })) + + }).ConfigureAwait(false)) { var tuners = new List<LiveTvTunerInfo>(); using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8)) @@ -536,7 +536,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun Url = string.Format("{0}/discover.json", GetApiUrl(info, false)), CancellationToken = CancellationToken.None, BufferContent = false - })) + + }).ConfigureAwait(false)) { var response = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index 601cb2666..8366c2d57 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -48,9 +48,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts private const string ChannelIdPrefix = "m3u_"; - protected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { - return await new M3uParser(Logger, _fileSystem, _httpClient, _appHost).Parse(info.Url, ChannelIdPrefix, info.Id, !info.EnableTvgId, cancellationToken).ConfigureAwait(false); + var result = await new M3uParser(Logger, _fileSystem, _httpClient, _appHost).Parse(info.Url, ChannelIdPrefix, info.Id, !info.EnableTvgId, cancellationToken).ConfigureAwait(false); + + return result.Cast<ChannelInfo>().ToList(); } public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 34d0dd853..8c4b9bf60 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -136,11 +136,26 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts channel.Name = GetChannelName(extInf, attributes); channel.Number = GetChannelNumber(extInf, attributes, mediaUrl); - var channelId = GetTunerChannelId(attributes); + string tvgId; + attributes.TryGetValue("tvg-id", out tvgId); + + string channelId; + attributes.TryGetValue("channel-id", out channelId); + + channel.TunerChannelId = string.IsNullOrWhiteSpace(tvgId) ? channelId : tvgId; + + var channelIdValues = new List<string>(); if (!string.IsNullOrWhiteSpace(channelId)) { - channel.Id = channelId; - channel.TunerChannelId = channelId; + channelIdValues.Add(channelId); + } + if (!string.IsNullOrWhiteSpace(tvgId)) + { + channelIdValues.Add(tvgId); + } + if (channelIdValues.Count > 0) + { + channel.Id = string.Join("_", channelIdValues.ToArray()); } return channel; @@ -296,19 +311,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return name; } - private string GetTunerChannelId(Dictionary<string, string> attributes) - { - string result; - attributes.TryGetValue("tvg-id", out result); - - if (string.IsNullOrWhiteSpace(result)) - { - attributes.TryGetValue("channel-id", out result); - } - - return result; - } - private Dictionary<string, string> ParseExtInf(string line, out string remaining) { var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs index a7e1b3cf3..df83d4341 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs @@ -74,10 +74,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts OnFinished = OnFinished }; - var initial = _sharedBuffer.ToList(); var list = new List<byte>(); - - foreach (var bytes in initial) + foreach (var bytes in _sharedBuffer) { list.AddRange(bytes); } |
