From 14b9f94e0a8516f96cc2e115ed767cb67260aa17 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 17 Mar 2016 14:19:39 -0400 Subject: [PATCH] add sat ini mappings --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 12 +++++++ .../LiveTv/ILiveTvManager.cs | 6 ++++ .../LiveTv/LiveTvManager.cs | 35 +++++++++++++++++++ ...MediaBrowser.Server.Implementations.csproj | 3 ++ .../packages.config | 1 + 5 files changed, 57 insertions(+) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 344d6ab3d..fea548d12 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -478,6 +478,13 @@ namespace MediaBrowser.Api.LiveTv public string Feature { get; set; } } + [Route("/LiveTv/TunerHosts/Satip/IniMappings", "GET", Summary = "Gets available mappings")] + [Authenticated(AllowBeforeStartupWizard = true)] + public class GetSatIniMappings : IReturn> + { + + } + public class LiveTvService : BaseApiService { private readonly ILiveTvManager _liveTvManager; @@ -500,6 +507,11 @@ namespace MediaBrowser.Api.LiveTv return ToOptimizedResult(result); } + public object Get(GetSatIniMappings request) + { + return ToOptimizedResult(_liveTvManager.GetSatIniMappings()); + } + public async Task Get(GetSchedulesDirectCountries request) { // https://json.schedulesdirect.org/20141201/available/countries diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 5dffb5e9b..a8f847f53 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -397,5 +397,11 @@ namespace MediaBrowser.Controller.LiveTv /// The recording. /// Task. Task OnRecordingFileDeleted(ILiveTvRecording recording); + + /// + /// Gets the sat ini mappings. + /// + /// List<NameValuePair>. + List GetSatIniMappings(); } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 6b848d0f6..e54adc0c5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -30,6 +30,8 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using IniParser; +using IniParser.Model; namespace MediaBrowser.Server.Implementations.LiveTv { @@ -2488,5 +2490,38 @@ namespace MediaBrowser.Server.Implementations.LiveTv IsRegistered = true }); } + + public List GetSatIniMappings() + { + var names = GetType().Assembly.GetManifestResourceNames().Where(i => i.IndexOf("SatIp.ini.satellite", StringComparison.OrdinalIgnoreCase) != -1).ToList(); + + return names.Select(GetSatIniMappings).Where(i => i != null).DistinctBy(i => i.Value.Split('|')[0]).ToList(); + } + + public NameValuePair GetSatIniMappings(string resource) + { + 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; + } + + return new NameValuePair + { + Name = satType1 + " " + satType2, + Value = satType2 + "|" + Path.GetFileName(resource) + }; + } + } + } } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index b30fb5809..5cba98c5d 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -49,6 +49,9 @@ False ..\packages\Emby.XmlTv.1.0.0.48\lib\net45\Emby.XmlTv.dll + + ..\packages\ini-parser.2.2.4\lib\net20\INIFileParser.dll + ..\packages\Interfaces.IO.1.0.0.5\lib\portable-net45+sl4+wp71+win8+wpa81\Interfaces.IO.dll diff --git a/MediaBrowser.Server.Implementations/packages.config b/MediaBrowser.Server.Implementations/packages.config index 0175a44b8..7523ccd0a 100644 --- a/MediaBrowser.Server.Implementations/packages.config +++ b/MediaBrowser.Server.Implementations/packages.config @@ -2,6 +2,7 @@ +