rework tuner setup

This commit is contained in:
Luke Pulverenti 2017-03-13 14:57:45 -04:00
parent 2ff7608b7a
commit a8fc480489
6 changed files with 36 additions and 158 deletions

View File

@ -2553,7 +2553,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private async Task ScanForTunerDeviceChanges(ITunerHost host, CancellationToken cancellationToken) private async Task ScanForTunerDeviceChanges(ITunerHost host, CancellationToken cancellationToken)
{ {
var discoveredDevices = await DiscoverDevices(host, 2000, cancellationToken).ConfigureAwait(false); var discoveredDevices = await DiscoverDevices(host, 3000, cancellationToken).ConfigureAwait(false);
var configuredDevices = GetConfiguration().TunerHosts var configuredDevices = GetConfiguration().TunerHosts
.Where(i => string.Equals(i.Type, host.Type, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Type, host.Type, StringComparison.OrdinalIgnoreCase))

View File

@ -150,6 +150,16 @@ namespace Emby.Server.Implementations.LiveTv
get { return _listingProviders; } get { return _listingProviders; }
} }
public List<NameIdPair> GetTunerHostTypes()
{
return _tunerHosts.OrderBy(i => i.Name).Select(i => new NameIdPair
{
Name = i.Name,
Id = i.Type
}).ToList();
}
void service_DataSourceChanged(object sender, EventArgs e) void service_DataSourceChanged(object sender, EventArgs e)
{ {
if (!_isDisposed) if (!_isDisposed)
@ -3002,50 +3012,6 @@ namespace Emby.Server.Implementations.LiveTv
return _security.GetRegistrationStatus(feature); return _security.GetRegistrationStatus(feature);
} }
public List<NameValuePair> GetSatIniMappings()
{
return new List<NameValuePair>();
//var names = GetType().Assembly.GetManifestResourceNames().Where(i => i.IndexOf("SatIp.ini", StringComparison.OrdinalIgnoreCase) != -1).ToList();
//return names.Select(GetSatIniMappings).Where(i => i != null).DistinctBy(i => i.Value.Split('|')[0]).ToList();
}
public NameValuePair GetSatIniMappings(string resource)
{
return new NameValuePair();
//using (var stream = GetType().Assembly.GetManifestResourceStream(resource))
//{
// using (var reader = new StreamReader(stream))
// {
// var parser = new StreamIniDataParser();
// IniData data = parser.ReadData(reader);
// var satType1 = data["SATTYPE"]["1"];
// var satType2 = data["SATTYPE"]["2"];
// if (string.IsNullOrWhiteSpace(satType2))
// {
// return null;
// }
// var srch = "SatIp.ini.";
// var filename = Path.GetFileName(resource);
// return new NameValuePair
// {
// Name = satType1 + " " + satType2,
// Value = satType2 + "|" + filename.Substring(filename.IndexOf(srch) + srch.Length)
// };
// }
//}
}
public Task<List<ChannelInfo>> GetSatChannelScanResult(TunerHostInfo info, CancellationToken cancellationToken)
{
return Task.FromResult(new List<ChannelInfo>());
//return new TunerHosts.SatIp.ChannelScan(_logger).Scan(info, cancellationToken);
}
public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken) public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken)
{ {
var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)); var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));

View File

@ -582,13 +582,13 @@ namespace MediaBrowser.Api.LiveTv
} }
[Route("/LiveTv/ListingProviders/Default", "GET")] [Route("/LiveTv/ListingProviders/Default", "GET")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class GetDefaultListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo> public class GetDefaultListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo>
{ {
} }
[Route("/LiveTv/ListingProviders", "POST", Summary = "Adds a listing provider")] [Route("/LiveTv/ListingProviders", "POST", Summary = "Adds a listing provider")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class AddListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo> public class AddListingProvider : ListingsProviderInfo, IReturn<ListingsProviderInfo>
{ {
public bool ValidateLogin { get; set; } public bool ValidateLogin { get; set; }
@ -596,7 +596,7 @@ namespace MediaBrowser.Api.LiveTv
} }
[Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")] [Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class DeleteListingProvider : IReturnVoid public class DeleteListingProvider : IReturnVoid
{ {
[ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "DELETE")] [ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "DELETE")]
@ -604,7 +604,7 @@ namespace MediaBrowser.Api.LiveTv
} }
[Route("/LiveTv/ListingProviders/Lineups", "GET", Summary = "Gets available lineups")] [Route("/LiveTv/ListingProviders/Lineups", "GET", Summary = "Gets available lineups")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class GetLineups : IReturn<List<NameIdPair>> public class GetLineups : IReturn<List<NameIdPair>>
{ {
[ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "Id", Description = "Provider id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
@ -621,13 +621,13 @@ namespace MediaBrowser.Api.LiveTv
} }
[Route("/LiveTv/ListingProviders/SchedulesDirect/Countries", "GET", Summary = "Gets available lineups")] [Route("/LiveTv/ListingProviders/SchedulesDirect/Countries", "GET", Summary = "Gets available lineups")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class GetSchedulesDirectCountries public class GetSchedulesDirectCountries
{ {
} }
[Route("/LiveTv/ChannelMappingOptions")] [Route("/LiveTv/ChannelMappingOptions")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class GetChannelMappingOptions public class GetChannelMappingOptions
{ {
[ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
@ -635,7 +635,7 @@ namespace MediaBrowser.Api.LiveTv
} }
[Route("/LiveTv/ChannelMappings")] [Route("/LiveTv/ChannelMappings")]
[Authenticated(AllowBeforeStartupWizard = true)] [Authenticated]
public class SetChannelMapping public class SetChannelMapping
{ {
[ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "Id", Description = "Provider id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
@ -660,20 +660,6 @@ namespace MediaBrowser.Api.LiveTv
public string Feature { get; set; } public string Feature { get; set; }
} }
[Route("/LiveTv/TunerHosts/Satip/IniMappings", "GET", Summary = "Gets available mappings")]
[Authenticated(AllowBeforeStartupWizard = true)]
public class GetSatIniMappings : IReturn<List<NameValuePair>>
{
}
[Route("/LiveTv/TunerHosts/Satip/ChannelScan", "GET", Summary = "Scans for available channels")]
[Authenticated(AllowBeforeStartupWizard = true)]
public class GetSatChannnelScanResult : TunerHostInfo
{
}
[Route("/LiveTv/LiveStreamFiles/{Id}/stream.{Container}", "GET", Summary = "Gets a live tv channel")] [Route("/LiveTv/LiveStreamFiles/{Id}/stream.{Container}", "GET", Summary = "Gets a live tv channel")]
public class GetLiveStreamFile public class GetLiveStreamFile
{ {
@ -687,6 +673,13 @@ namespace MediaBrowser.Api.LiveTv
public string Id { get; set; } public string Id { get; set; }
} }
[Route("/LiveTv/TunerHosts/Types", "GET")]
[Authenticated]
public class GetTunerHostTypes : IReturn<List<NameIdPair>>
{
}
public class LiveTvService : BaseApiService public class LiveTvService : BaseApiService
{ {
private readonly ILiveTvManager _liveTvManager; private readonly ILiveTvManager _liveTvManager;
@ -712,6 +705,12 @@ namespace MediaBrowser.Api.LiveTv
_sessionContext = sessionContext; _sessionContext = sessionContext;
} }
public object Get(GetTunerHostTypes request)
{
var list = _liveTvManager.GetTunerHostTypes();
return ToOptimizedResult(list);
}
public object Get(GetLiveRecordingFile request) public object Get(GetLiveRecordingFile request)
{ {
var path = _liveTvManager.GetEmbyTvActiveRecordingPath(request.Id); var path = _liveTvManager.GetEmbyTvActiveRecordingPath(request.Id);
@ -749,13 +748,6 @@ namespace MediaBrowser.Api.LiveTv
return ToOptimizedResult(new ListingsProviderInfo()); return ToOptimizedResult(new ListingsProviderInfo());
} }
public async Task<object> Get(GetSatChannnelScanResult request)
{
var result = await _liveTvManager.GetSatChannelScanResult(request, CancellationToken.None).ConfigureAwait(false);
return ToOptimizedResult(result);
}
public async Task<object> Get(GetLiveTvRegistrationInfo request) public async Task<object> Get(GetLiveTvRegistrationInfo request)
{ {
var result = await _liveTvManager.GetRegistrationInfo(request.Feature).ConfigureAwait(false); var result = await _liveTvManager.GetRegistrationInfo(request.Feature).ConfigureAwait(false);
@ -803,11 +795,6 @@ namespace MediaBrowser.Api.LiveTv
return ToOptimizedResult(result); return ToOptimizedResult(result);
} }
public object Get(GetSatIniMappings request)
{
return ToOptimizedResult(_liveTvManager.GetSatIniMappings());
}
public async Task<object> Get(GetSchedulesDirectCountries request) public async Task<object> Get(GetSchedulesDirectCountries request)
{ {
// https://json.schedulesdirect.org/20141201/available/countries // https://json.schedulesdirect.org/20141201/available/countries

View File

@ -1,12 +1,9 @@
using MediaBrowser.Common.Configuration; using MediaBrowser.Controller;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Connect; using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.LiveTv;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -52,16 +49,14 @@ namespace MediaBrowser.Api
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IConnectManager _connectManager; private readonly IConnectManager _connectManager;
private readonly ILiveTvManager _liveTvManager;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
public StartupWizardService(IServerConfigurationManager config, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, ILiveTvManager liveTvManager, IMediaEncoder mediaEncoder) public StartupWizardService(IServerConfigurationManager config, IServerApplicationHost appHost, IUserManager userManager, IConnectManager connectManager, IMediaEncoder mediaEncoder)
{ {
_config = config; _config = config;
_appHost = appHost; _appHost = appHost;
_userManager = userManager; _userManager = userManager;
_connectManager = connectManager; _connectManager = connectManager;
_liveTvManager = liveTvManager;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
} }
@ -92,20 +87,6 @@ namespace MediaBrowser.Api
PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage PreferredMetadataLanguage = _config.Configuration.PreferredMetadataLanguage
}; };
var tvConfig = GetLiveTVConfiguration();
if (tvConfig.TunerHosts.Count > 0)
{
result.LiveTvTunerPath = tvConfig.TunerHosts[0].Url;
result.LiveTvTunerType = tvConfig.TunerHosts[0].Type;
}
if (tvConfig.ListingProviders.Count > 0)
{
result.LiveTvGuideProviderId = tvConfig.ListingProviders[0].Id;
result.LiveTvGuideProviderType = tvConfig.ListingProviders[0].Type;
}
return result; return result;
} }
@ -129,9 +110,6 @@ namespace MediaBrowser.Api
_config.Configuration.MetadataCountryCode = request.MetadataCountryCode; _config.Configuration.MetadataCountryCode = request.MetadataCountryCode;
_config.Configuration.PreferredMetadataLanguage = request.PreferredMetadataLanguage; _config.Configuration.PreferredMetadataLanguage = request.PreferredMetadataLanguage;
_config.SaveConfiguration(); _config.SaveConfiguration();
var task = UpdateTuners(request);
Task.WaitAll(task);
} }
public object Get(GetStartupUser request) public object Get(GetStartupUser request)
@ -166,50 +144,6 @@ namespace MediaBrowser.Api
return result; return result;
} }
private async Task UpdateTuners(UpdateStartupConfiguration request)
{
var config = GetLiveTVConfiguration();
var save = false;
if (string.IsNullOrWhiteSpace(request.LiveTvTunerPath) ||
string.IsNullOrWhiteSpace(request.LiveTvTunerType))
{
if (config.TunerHosts.Count > 0)
{
config.TunerHosts.Clear();
save = true;
}
}
else
{
if (!config.TunerHosts.Any(i => string.Equals(i.Type, request.LiveTvTunerType, StringComparison.OrdinalIgnoreCase) && string.Equals(i.Url, request.LiveTvTunerPath, StringComparison.OrdinalIgnoreCase)))
{
// Add tuner
await _liveTvManager.SaveTunerHost(new TunerHostInfo
{
Type = request.LiveTvTunerType,
Url = request.LiveTvTunerPath
}).ConfigureAwait(false);
}
}
if (save)
{
SaveLiveTVConfiguration(config);
}
}
private void SaveLiveTVConfiguration(LiveTvOptions config)
{
_config.SaveConfiguration("livetv", config);
}
private LiveTvOptions GetLiveTVConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
} }
public class StartupConfiguration public class StartupConfiguration
@ -217,10 +151,6 @@ namespace MediaBrowser.Api
public string UICulture { get; set; } public string UICulture { get; set; }
public string MetadataCountryCode { get; set; } public string MetadataCountryCode { get; set; }
public string PreferredMetadataLanguage { get; set; } public string PreferredMetadataLanguage { get; set; }
public string LiveTvTunerType { get; set; }
public string LiveTvTunerPath { get; set; }
public string LiveTvGuideProviderId { get; set; }
public string LiveTvGuideProviderType { get; set; }
} }
public class StartupInfo public class StartupInfo

View File

@ -376,19 +376,13 @@ namespace MediaBrowser.Controller.LiveTv
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task OnRecordingFileDeleted(BaseItem recording); Task OnRecordingFileDeleted(BaseItem recording);
/// <summary>
/// Gets the sat ini mappings.
/// </summary>
/// <returns>List&lt;NameValuePair&gt;.</returns>
List<NameValuePair> GetSatIniMappings();
Task<List<ChannelInfo>> GetSatChannelScanResult(TunerHostInfo info, CancellationToken cancellationToken);
Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken); Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken);
Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken); Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken);
List<IListingsProvider> ListingProviders { get; } List<IListingsProvider> ListingProviders { get; }
List<NameIdPair> GetTunerHostTypes();
event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled; event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCancelled;
event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCancelled; event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCancelled;
event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCreated; event EventHandler<GenericEventArgs<TimerEventInfo>> TimerCreated;

View File

@ -46,6 +46,7 @@ namespace MediaBrowser.Model.LiveTv
public string Url { get; set; } public string Url { get; set; }
public string Type { get; set; } public string Type { get; set; }
public string DeviceId { get; set; } public string DeviceId { get; set; }
public string FriendlyName { get; set; }
public bool ImportFavoritesOnly { get; set; } public bool ImportFavoritesOnly { get; set; }
public bool AllowHWTranscoding { get; set; } public bool AllowHWTranscoding { get; set; }
public bool EnableTvgId { get; set; } public bool EnableTvgId { get; set; }