From 3ba9d3c12f71208cb45d58b93b7c472780a5d541 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 10 Jun 2016 12:45:04 -0400 Subject: [PATCH 1/2] update channel mapping --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 8 +++++--- MediaBrowser.Controller/LiveTv/ILiveTvManager.cs | 2 ++ .../Library/MediaSourceManager.cs | 4 ++++ .../LiveTv/Listings/SchedulesDirect.cs | 14 +++++++++++--- .../Persistence/IDbConnector.cs | 2 +- .../Persistence/SqliteExtensions.cs | 4 ++-- .../Persistence/SqliteItemRepository.cs | 2 +- MediaBrowser.Server.Mono/Native/DbConnector.cs | 4 ++-- .../Native/DbConnector.cs | 4 ++-- 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index ddc389f03..b2f0704ea 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -578,7 +578,9 @@ namespace MediaBrowser.Api.LiveTv { var config = GetConfiguration(); - var listingProvider = config.ListingProviders.First(i => string.Equals(request.ProviderId, i.Id, StringComparison.OrdinalIgnoreCase)); + var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(request.ProviderId, i.Id, StringComparison.OrdinalIgnoreCase)); + + var listingsProviderName = _liveTvManager.ListingProviders.First(i => string.Equals(i.Type, listingsProviderInfo.Type, StringComparison.OrdinalIgnoreCase)).Name; var tunerChannels = await _liveTvManager.GetChannelsForListingsProvider(request.ProviderId, CancellationToken.None) .ConfigureAwait(false); @@ -586,7 +588,7 @@ namespace MediaBrowser.Api.LiveTv var providerChannels = await _liveTvManager.GetChannelsFromListingsProviderData(request.ProviderId, CancellationToken.None) .ConfigureAwait(false); - var mappings = listingProvider.ChannelMappings.ToList(); + var mappings = listingsProviderInfo.ChannelMappings.ToList(); var result = new ChannelMappingOptions { @@ -601,7 +603,7 @@ namespace MediaBrowser.Api.LiveTv Mappings = mappings, - ProviderName = "Schedules Direct" + ProviderName = listingsProviderName }; return ToOptimizedResult(result); diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 9cb0476ba..ffba3097c 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -390,6 +390,8 @@ namespace MediaBrowser.Controller.LiveTv Task> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken); Task> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken); + List ListingProviders { get;} + event EventHandler> SeriesTimerCancelled; event EventHandler> TimerCancelled; event EventHandler> TimerCreated; diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index 0ef7efe1b..1bcb02ac3 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -73,6 +73,10 @@ namespace MediaBrowser.Server.Implementations.Library { return false; } + if (string.Equals(stream.Codec, "ssa", StringComparison.OrdinalIgnoreCase)) + { + return false; + } return true; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 6443440c8..e37109c14 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -879,6 +879,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings throw new Exception("ListingsId required"); } + await AddMetadata(info, new List(), cancellationToken).ConfigureAwait(false); + var token = await GetToken(info, cancellationToken); if (string.IsNullOrWhiteSpace(token)) @@ -886,8 +888,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings throw new Exception("token required"); } - ClearPairCache(listingsId); - var httpOptions = new HttpRequestOptions() { Url = ApiUrl + "/lineups/" + listingsId, @@ -921,10 +921,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings } channelNumber = channelNumber.TrimStart('0'); + var name = channelNumber; + var station = GetStation(listingsId, channelNumber, null); + + if (station != null) + { + name = station.name; + } + list.Add(new ChannelInfo { Number = channelNumber, - Name = map.channel + Name = name }); } } diff --git a/MediaBrowser.Server.Implementations/Persistence/IDbConnector.cs b/MediaBrowser.Server.Implementations/Persistence/IDbConnector.cs index cac9fe983..2092f830a 100644 --- a/MediaBrowser.Server.Implementations/Persistence/IDbConnector.cs +++ b/MediaBrowser.Server.Implementations/Persistence/IDbConnector.cs @@ -5,6 +5,6 @@ namespace MediaBrowser.Server.Implementations.Persistence { public interface IDbConnector { - Task Connect(string dbPath); + Task Connect(string dbPath, int? cacheSize = null); } } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteExtensions.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteExtensions.cs index dd2f15cfd..2f3f34aa4 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteExtensions.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteExtensions.cs @@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.Persistence /// The logger. /// Task{IDbConnection}. /// dbPath - public static async Task ConnectToDb(string dbPath, ILogger logger) + public static async Task ConnectToDb(string dbPath, int? cacheSize, ILogger logger) { if (string.IsNullOrEmpty(dbPath)) { @@ -35,7 +35,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var connectionstr = new SQLiteConnectionStringBuilder { PageSize = 4096, - CacheSize = 2000, + CacheSize = cacheSize ?? 2000, SyncMode = SynchronizationModes.Normal, DataSource = dbPath, JournalMode = SQLiteJournalModeEnum.Wal diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index a4cb0c48b..071951018 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -127,7 +127,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { var dbFile = Path.Combine(_config.ApplicationPaths.DataPath, "library.db"); - _connection = await dbConnector.Connect(dbFile).ConfigureAwait(false); + _connection = await dbConnector.Connect(dbFile, 6000).ConfigureAwait(false); var createMediaStreamsTableCommand = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, CodecTag TEXT NULL, Comment TEXT NULL, NalLengthSize TEXT NULL, IsAvc BIT NULL, Title TEXT NULL, TimeBase TEXT NULL, CodecTimeBase TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; diff --git a/MediaBrowser.Server.Mono/Native/DbConnector.cs b/MediaBrowser.Server.Mono/Native/DbConnector.cs index 3230f92f9..7553dbe1a 100644 --- a/MediaBrowser.Server.Mono/Native/DbConnector.cs +++ b/MediaBrowser.Server.Mono/Native/DbConnector.cs @@ -16,9 +16,9 @@ namespace MediaBrowser.Server.Mono.Native _logger = logger; } - public Task Connect(string dbPath) + public Task Connect(string dbPath, int? cacheSize = null) { - return SqliteExtensions.ConnectToDb(dbPath, _logger); + return SqliteExtensions.ConnectToDb(dbPath, cacheSize, _logger); } } } \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/Native/DbConnector.cs b/MediaBrowser.ServerApplication/Native/DbConnector.cs index 48ba7d0e7..6001ac3c0 100644 --- a/MediaBrowser.ServerApplication/Native/DbConnector.cs +++ b/MediaBrowser.ServerApplication/Native/DbConnector.cs @@ -16,11 +16,11 @@ namespace MediaBrowser.ServerApplication.Native _logger = logger; } - public async Task Connect(string dbPath) + public async Task Connect(string dbPath, int? cacheSize = null) { try { - return await SqliteExtensions.ConnectToDb(dbPath, _logger).ConfigureAwait(false); + return await SqliteExtensions.ConnectToDb(dbPath, cacheSize, _logger).ConfigureAwait(false); } catch (Exception ex) { From 682edf5abde127b59b3303dabc6445d975ef60d3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 10 Jun 2016 13:34:08 -0400 Subject: [PATCH 2/2] update channel mapper --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index b2f0704ea..41c0c39ea 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -492,6 +492,16 @@ namespace MediaBrowser.Api.LiveTv public string ProviderId { get; set; } } + [Route("/LiveTv/ChannelMappings")] + [Authenticated(AllowBeforeStartupWizard = true)] + public class SetChannelMapping + { + [ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string ProviderId { get; set; } + public string TunerChannelNumber { get; set; } + public string ProviderChannelNumber { get; set; } + } + public class ChannelMappingOptions { public List TunerChannels { get; set; } @@ -574,6 +584,40 @@ namespace MediaBrowser.Api.LiveTv return ToOptimizedResult(result); } + public async Task Post(SetChannelMapping request) + { + var config = GetConfiguration(); + + var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(request.ProviderId, i.Id, StringComparison.OrdinalIgnoreCase)); + listingsProviderInfo.ChannelMappings = listingsProviderInfo.ChannelMappings.Where(i => !string.Equals(i.Name, request.TunerChannelNumber, StringComparison.OrdinalIgnoreCase)).ToArray(); + + if (!string.Equals(request.TunerChannelNumber, request.ProviderChannelNumber, StringComparison.OrdinalIgnoreCase)) + { + var list = listingsProviderInfo.ChannelMappings.ToList(); + list.Add(new NameValuePair + { + Name = request.TunerChannelNumber, + Value = request.ProviderChannelNumber + }); + listingsProviderInfo.ChannelMappings = list.ToArray(); + } + + UpdateConfiguration(config); + + var tunerChannels = await _liveTvManager.GetChannelsForListingsProvider(request.ProviderId, CancellationToken.None) + .ConfigureAwait(false); + + var providerChannels = await _liveTvManager.GetChannelsFromListingsProviderData(request.ProviderId, CancellationToken.None) + .ConfigureAwait(false); + + var mappings = listingsProviderInfo.ChannelMappings.ToList(); + + var tunerChannelMappings = + tunerChannels.Select(i => GetTunerChannelMapping(i, mappings, providerChannels)).ToList(); + + return tunerChannelMappings.First(i => string.Equals(i.Number, request.TunerChannelNumber, StringComparison.OrdinalIgnoreCase)); + } + public async Task Get(GetChannelMappingOptions request) { var config = GetConfiguration(); @@ -704,6 +748,11 @@ namespace MediaBrowser.Api.LiveTv return _config.GetConfiguration("livetv"); } + private void UpdateConfiguration(LiveTvOptions options) + { + _config.SaveConfiguration("livetv", options); + } + public async Task Get(GetLineups request) { var info = await _liveTvManager.GetLineups(request.Type, request.Id, request.Country, request.Location).ConfigureAwait(false);