diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-07-23 02:12:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-23 02:12:16 -0400 |
| commit | 5ec9d4e9fe4b3e5109ca1abf6c1ffdb87fd2d4dd (patch) | |
| tree | e49cc827583b6dffeabb142af5fae889b1a09581 /Emby.Server.Implementations/LiveTv | |
| parent | e99bc61d53f393dc475e265e3b5bc8c19b186594 (diff) | |
| parent | 0d1b5ad733e6f1bbf6d730e723969495dda99016 (diff) | |
Merge pull request #2767 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Server.Implementations/LiveTv')
6 files changed, 82 insertions, 33 deletions
diff --git a/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs b/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs index 428b6202b..143350a8b 100644 --- a/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs +++ b/Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs @@ -16,8 +16,8 @@ namespace Emby.Server.Implementations.LiveTv private readonly IMediaEncoder _mediaEncoder; private readonly ILogger _logger; - const int ProbeAnalyzeDurationMs = 2000; - const int PlaybackAnalyzeDurationMs = 2000; + const int ProbeAnalyzeDurationMs = 3000; + const int PlaybackAnalyzeDurationMs = 3000; public LiveStreamHelper(IMediaEncoder mediaEncoder, ILogger logger) { diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 24afc03da..bf11b7d3a 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1514,7 +1514,7 @@ namespace Emby.Server.Implementations.LiveTv } private DateTime _lastRecordingRefreshTime; - private async Task RefreshRecordings(CancellationToken cancellationToken) + private async Task RefreshRecordings(Guid internalLiveTvFolderId, CancellationToken cancellationToken) { const int cacheMinutes = 2; @@ -1542,10 +1542,8 @@ namespace Emby.Server.Implementations.LiveTv }); var results = await Task.WhenAll(tasks).ConfigureAwait(false); - var folder = await GetInternalLiveTvFolder(cancellationToken).ConfigureAwait(false); - var parentFolderId = folder.Id; - var recordingTasks = results.SelectMany(i => i.ToList()).Select(i => CreateRecordingRecord(i.Item1, i.Item2.Name, parentFolderId, cancellationToken)); + var recordingTasks = results.SelectMany(i => i.ToList()).Select(i => CreateRecordingRecord(i.Item1, i.Item2.Name, internalLiveTvFolderId, cancellationToken)); var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false); @@ -1559,7 +1557,7 @@ namespace Emby.Server.Implementations.LiveTv } } - private QueryResult<BaseItem> GetEmbyRecordings(RecordingQuery query, DtoOptions dtoOptions, User user) + private QueryResult<BaseItem> GetEmbyRecordings(RecordingQuery query, DtoOptions dtoOptions, Guid internalLiveTvFolderId, User user) { if (user == null) { @@ -1571,21 +1569,31 @@ namespace Emby.Server.Implementations.LiveTv return new QueryResult<BaseItem>(); } - var folders = EmbyTV.EmbyTV.Current.GetRecordingFolders() + var folderIds = EmbyTV.EmbyTV.Current.GetRecordingFolders() .SelectMany(i => i.Locations) .Distinct(StringComparer.OrdinalIgnoreCase) .Select(i => _libraryManager.FindByPath(i, true)) .Where(i => i != null) .Where(i => i.IsVisibleStandalone(user)) + .Select(i => i.Id) .ToList(); - if (folders.Count == 0) + var excludeItemTypes = new List<string>(); + + if (!query.IsInProgress.HasValue) + { + folderIds.Add(internalLiveTvFolderId); + + excludeItemTypes.Add(typeof(LiveTvChannel).Name); + excludeItemTypes.Add(typeof(LiveTvProgram).Name); + } + + if (folderIds.Count == 0) { return new QueryResult<BaseItem>(); } var includeItemTypes = new List<string>(); - var excludeItemTypes = new List<string>(); var genres = new List<string>(); if (query.IsMovie.HasValue) @@ -1631,7 +1639,7 @@ namespace Emby.Server.Implementations.LiveTv { MediaTypes = new[] { MediaType.Video }, Recursive = true, - AncestorIds = folders.Select(i => i.Id.ToString("N")).ToArray(), + AncestorIds = folderIds.Select(i => i.ToString("N")).ToArray(), IsFolder = false, IsVirtualItem = false, Limit = query.Limit, @@ -1714,12 +1722,24 @@ namespace Emby.Server.Implementations.LiveTv return new QueryResult<BaseItem>(); } - if (_services.Count == 1 && !(query.IsInProgress ?? false) && (!query.IsLibraryItem.HasValue || query.IsLibraryItem.Value)) + var folder = await GetInternalLiveTvFolder(cancellationToken).ConfigureAwait(false); + + if (_services.Count == 1 && (!query.IsInProgress.HasValue || !query.IsInProgress.Value) && (!query.IsLibraryItem.HasValue || query.IsLibraryItem.Value)) { - return GetEmbyRecordings(query, options, user); + if (!query.IsInProgress.HasValue) + { + await RefreshRecordings(folder.Id, cancellationToken).ConfigureAwait(false); + } + + return GetEmbyRecordings(query, options, folder.Id, user); } - await RefreshRecordings(cancellationToken).ConfigureAwait(false); + return await GetInternalRecordingsFromServices(query, user, options, folder.Id, cancellationToken).ConfigureAwait(false); + } + + private async Task<QueryResult<BaseItem>> GetInternalRecordingsFromServices(RecordingQuery query, User user, DtoOptions options, Guid internalLiveTvFolderId, CancellationToken cancellationToken) + { + await RefreshRecordings(internalLiveTvFolderId, cancellationToken).ConfigureAwait(false); var internalQuery = new InternalItemsQuery(user) { @@ -2620,7 +2640,8 @@ namespace Emby.Server.Implementations.LiveTv }, new DtoOptions(), cancellationToken).ConfigureAwait(false); - var recordings = recordingResult.Items.OfType<ILiveTvRecording>().ToList(); + var embyServiceName = EmbyTV.EmbyTV.Current.Name; + var recordings = recordingResult.Items.Where(i => !string.Equals(i.ServiceName, embyServiceName, StringComparison.OrdinalIgnoreCase)).OfType<ILiveTvRecording>().ToList(); var groups = new List<BaseItemDto>(); diff --git a/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs b/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs index 0329ea606..919c0f10d 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs @@ -118,7 +118,7 @@ namespace Emby.Server.Implementations.LiveTv return list; } - public async Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> OpenMediaSource(string openToken, CancellationToken cancellationToken) + public async Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> OpenMediaSource(string openToken, bool allowLiveStreamProbe, CancellationToken cancellationToken) { MediaSourceInfo stream = null; const bool isAudio = false; @@ -140,7 +140,7 @@ namespace Emby.Server.Implementations.LiveTv try { - if (!stream.SupportsProbing || stream.MediaStreams.Any(i => i.Index != -1)) + if (!allowLiveStreamProbe || !stream.SupportsProbing || stream.MediaStreams.Any(i => i.Index != -1)) { AddMediaInfo(stream, isAudio, cancellationToken); } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index 10b7132a1..4b4f61d53 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -10,9 +10,11 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.IO; using MediaBrowser.Model.Serialization; namespace Emby.Server.Implementations.LiveTv.TunerHosts @@ -23,16 +25,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts protected readonly ILogger Logger; protected IJsonSerializer JsonSerializer; protected readonly IMediaEncoder MediaEncoder; + protected readonly IFileSystem FileSystem; private readonly ConcurrentDictionary<string, ChannelCache> _channelCache = new ConcurrentDictionary<string, ChannelCache>(StringComparer.OrdinalIgnoreCase); - protected BaseTunerHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder) + protected BaseTunerHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder, IFileSystem fileSystem) { Config = config; Logger = logger; JsonSerializer = jsonSerializer; MediaEncoder = mediaEncoder; + FileSystem = fileSystem; } protected abstract Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); @@ -81,16 +85,44 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts foreach (var host in hosts) { + var channelCacheFile = Path.Combine(Config.ApplicationPaths.CachePath, host.Id + "_channels"); + try { var channels = await GetChannels(host, enableCache, cancellationToken).ConfigureAwait(false); var newChannels = channels.Where(i => !list.Any(l => string.Equals(i.Id, l.Id, StringComparison.OrdinalIgnoreCase))).ToList(); list.AddRange(newChannels); + + if (!enableCache) + { + try + { + FileSystem.CreateDirectory(FileSystem.GetDirectoryName(channelCacheFile)); + JsonSerializer.SerializeToFile(channels, channelCacheFile); + } + catch (IOException) + { + + } + } } catch (Exception ex) { Logger.ErrorException("Error getting channel list", ex); + + if (enableCache) + { + try + { + var channels = JsonSerializer.DeserializeFromFile<List<ChannelInfo>>(channelCacheFile); + list.AddRange(channels); + } + catch (IOException) + { + + } + } } } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index 153f86aed..b6ba8b45c 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -27,17 +27,14 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun public class HdHomerunHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost { private readonly IHttpClient _httpClient; - private readonly IFileSystem _fileSystem; private readonly IServerApplicationHost _appHost; private readonly ISocketFactory _socketFactory; private readonly INetworkManager _networkManager; private readonly IEnvironmentInfo _environment; - public HdHomerunHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder, IHttpClient httpClient, IFileSystem fileSystem, IServerApplicationHost appHost, ISocketFactory socketFactory, INetworkManager networkManager, IEnvironmentInfo environment) - : base(config, logger, jsonSerializer, mediaEncoder) + public HdHomerunHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IHttpClient httpClient, IServerApplicationHost appHost, ISocketFactory socketFactory, INetworkManager networkManager, IEnvironmentInfo environment) : base(config, logger, jsonSerializer, mediaEncoder, fileSystem) { _httpClient = httpClient; - _fileSystem = fileSystem; _appHost = appHost; _socketFactory = socketFactory; _networkManager = networkManager; @@ -509,7 +506,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun if (hdhomerunChannel != null && hdhomerunChannel.IsLegacyTuner) { - return new HdHomerunUdpStream(mediaSource, streamId, new LegacyHdHomerunChannelCommands(hdhomerunChannel.Url), modelInfo.TunerCount, _fileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment); + return new HdHomerunUdpStream(mediaSource, streamId, new LegacyHdHomerunChannelCommands(hdhomerunChannel.Url), modelInfo.TunerCount, FileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment); } // The UDP method is not working reliably on OSX, and on BSD it hasn't been tested yet @@ -529,10 +526,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } mediaSource.Path = httpUrl; - return new HdHomerunHttpStream(mediaSource, streamId, _fileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _environment); + return new HdHomerunHttpStream(mediaSource, streamId, FileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _environment); } - return new HdHomerunUdpStream(mediaSource, streamId, new HdHomerunChannelCommands(hdhomerunChannel.Number, profile), modelInfo.TunerCount, _fileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment); + return new HdHomerunUdpStream(mediaSource, streamId, new HdHomerunChannelCommands(hdhomerunChannel.Number, profile), modelInfo.TunerCount, FileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment); } public async Task Validate(TunerHostInfo info) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index 8bf7a052e..113cb33f4 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -25,15 +25,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { public class M3UTunerHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost { - private readonly IFileSystem _fileSystem; private readonly IHttpClient _httpClient; private readonly IServerApplicationHost _appHost; private readonly IEnvironmentInfo _environment; - public M3UTunerHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IHttpClient httpClient, IServerApplicationHost appHost, IEnvironmentInfo environment) - : base(config, logger, jsonSerializer, mediaEncoder) + public M3UTunerHost(IServerConfigurationManager config, ILogger logger, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IHttpClient httpClient, IServerApplicationHost appHost, IEnvironmentInfo environment) : base(config, logger, jsonSerializer, mediaEncoder, fileSystem) { - _fileSystem = fileSystem; _httpClient = httpClient; _appHost = appHost; _environment = environment; @@ -51,7 +48,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { - var result = 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(); } @@ -76,13 +73,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { var sources = await GetChannelStreamMediaSources(info, channelId, cancellationToken).ConfigureAwait(false); - var liveStream = new LiveStream(sources.First(), _environment, _fileSystem); + var liveStream = new LiveStream(sources.First(), _environment, FileSystem); return liveStream; } public async Task Validate(TunerHostInfo info) { - using (var stream = await new M3uParser(Logger, _fileSystem, _httpClient, _appHost).GetListingsStream(info.Url, CancellationToken.None).ConfigureAwait(false)) + using (var stream = await new M3uParser(Logger, FileSystem, _httpClient, _appHost).GetListingsStream(info.Url, CancellationToken.None).ConfigureAwait(false)) { } @@ -154,7 +151,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts Id = channel.Path.GetMD5().ToString("N"), IsInfiniteStream = true, - IsRemote = true + IsRemote = true, + + IgnoreDts = true }; mediaSource.InferTotalBitrate(); |
