Merge pull request #1834 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-06-10 13:36:45 -04:00 committed by GitHub
commit 80863516c3
9 changed files with 80 additions and 15 deletions

View File

@ -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<TunerChannelMapping> TunerChannels { get; set; }
@ -574,11 +584,25 @@ namespace MediaBrowser.Api.LiveTv
return ToOptimizedResult(result);
}
public async Task<object> Get(GetChannelMappingOptions request)
public async Task<object> Post(SetChannelMapping request)
{
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));
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);
@ -586,7 +610,29 @@ 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 tunerChannelMappings =
tunerChannels.Select(i => GetTunerChannelMapping(i, mappings, providerChannels)).ToList();
return tunerChannelMappings.First(i => string.Equals(i.Number, request.TunerChannelNumber, StringComparison.OrdinalIgnoreCase));
}
public async Task<object> Get(GetChannelMappingOptions request)
{
var config = GetConfiguration();
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);
var providerChannels = await _liveTvManager.GetChannelsFromListingsProviderData(request.ProviderId, CancellationToken.None)
.ConfigureAwait(false);
var mappings = listingsProviderInfo.ChannelMappings.ToList();
var result = new ChannelMappingOptions
{
@ -601,7 +647,7 @@ namespace MediaBrowser.Api.LiveTv
Mappings = mappings,
ProviderName = "Schedules Direct"
ProviderName = listingsProviderName
};
return ToOptimizedResult(result);
@ -702,6 +748,11 @@ namespace MediaBrowser.Api.LiveTv
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
private void UpdateConfiguration(LiveTvOptions options)
{
_config.SaveConfiguration("livetv", options);
}
public async Task<object> Get(GetLineups request)
{
var info = await _liveTvManager.GetLineups(request.Type, request.Id, request.Country, request.Location).ConfigureAwait(false);

View File

@ -390,6 +390,8 @@ namespace MediaBrowser.Controller.LiveTv
Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken);
Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken);
List<IListingsProvider> ListingProviders { get;}
event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled;
event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCancelled;
event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCreated;

View File

@ -73,6 +73,10 @@ namespace MediaBrowser.Server.Implementations.Library
{
return false;
}
if (string.Equals(stream.Codec, "ssa", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return true;
}

View File

@ -879,6 +879,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
throw new Exception("ListingsId required");
}
await AddMetadata(info, new List<ChannelInfo>(), 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
});
}
}

View File

@ -5,6 +5,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
public interface IDbConnector
{
Task<IDbConnection> Connect(string dbPath);
Task<IDbConnection> Connect(string dbPath, int? cacheSize = null);
}
}

View File

@ -23,7 +23,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// <param name="logger">The logger.</param>
/// <returns>Task{IDbConnection}.</returns>
/// <exception cref="System.ArgumentNullException">dbPath</exception>
public static async Task<IDbConnection> ConnectToDb(string dbPath, ILogger logger)
public static async Task<IDbConnection> 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

View File

@ -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))";

View File

@ -16,9 +16,9 @@ namespace MediaBrowser.Server.Mono.Native
_logger = logger;
}
public Task<IDbConnection> Connect(string dbPath)
public Task<IDbConnection> Connect(string dbPath, int? cacheSize = null)
{
return SqliteExtensions.ConnectToDb(dbPath, _logger);
return SqliteExtensions.ConnectToDb(dbPath, cacheSize, _logger);
}
}
}

View File

@ -16,11 +16,11 @@ namespace MediaBrowser.ServerApplication.Native
_logger = logger;
}
public async Task<IDbConnection> Connect(string dbPath)
public async Task<IDbConnection> 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)
{