The Free Software Media System - Server Backend & API
completed tuner hosts
Luke Pulverenti9457ff7ce87e
diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.csindex c474642d5d..49ba001cef 100644--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs@@ -1,4 +1,5 @@-using MediaBrowser.Controller.Dto;+using MediaBrowser.Common.Configuration;+using MediaBrowser.Controller.Dto;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Controller.Net;@@ -330,15 +331,31 @@ namespace MediaBrowser.Api.LiveTvpublic string UserId { get; set; }}+ [Route("/LiveTv/TunerHosts", "POST", Summary = "Adds a tuner host")]+ [Authenticated]+ public class AddTunerHost : TunerHostInfo, IReturnVoid+ {+ }++ [Route("/LiveTv/TunerHosts", "DELETE", Summary = "Deletes a tuner host")]+ [Authenticated]+ public class DeleteTunerHost : IReturnVoid+ {+ [ApiMember(Name = "Id", Description = "Tuner host id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "DELETE")]+ public string Id { get; set; }+ }+public class LiveTvService : BaseApiService{private readonly ILiveTvManager _liveTvManager;private readonly IUserManager _userManager;+ private readonly IConfigurationManager _config;- public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager)+ public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, IConfigurationManager config){_liveTvManager = liveTvManager;_userManager = userManager;+ _config = config;}private void AssertUserCanManageLiveTv()@@ -356,6 +373,34 @@ namespace MediaBrowser.Api.LiveTv}}+ public void Post(AddTunerHost request)+ {+ var config = GetConfiguration();++ config.TunerHosts.Add(new TunerHostInfo+ {+ Id = Guid.NewGuid().ToString("N"),+ Url = request.Url,+ Type = request.Type+ });++ _config.SaveConfiguration("livetv", config);+ }++ public void Delete(DeleteTunerHost request)+ {+ var config = GetConfiguration();++ config.TunerHosts = config.TunerHosts.Where(i => !string.Equals(request.Id, i.Id, StringComparison.OrdinalIgnoreCase)).ToList();++ _config.SaveConfiguration("livetv", config);+ }++ private LiveTvOptions GetConfiguration()+ {+ return _config.GetConfiguration<LiveTvOptions>("livetv");+ }+public async Task<object> Get(GetLiveTvInfo request){var info = await _liveTvManager.GetLiveTvInfo(CancellationToken.None).ConfigureAwait(false);diff --git a/MediaBrowser.Controller/LiveTv/IListingsProvider.cs b/MediaBrowser.Controller/LiveTv/IListingsProvider.csindex 2cef455e8b..75ca7e0dcc 100644--- a/MediaBrowser.Controller/LiveTv/IListingsProvider.cs+++ b/MediaBrowser.Controller/LiveTv/IListingsProvider.cs@@ -1,7 +1,12 @@-+using System;+using System.Collections.Generic;+using System.Threading;+using System.Threading.Tasks;+namespace MediaBrowser.Controller.LiveTv{public interface IListingsProvider{+ Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ChannelInfo channel, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken);}}diff --git a/MediaBrowser.Controller/LiveTv/LiveTvServiceStatusInfo.cs b/MediaBrowser.Controller/LiveTv/LiveTvServiceStatusInfo.csindex 0cb064aba3..4da238acf5 100644--- a/MediaBrowser.Controller/LiveTv/LiveTvServiceStatusInfo.cs+++ b/MediaBrowser.Controller/LiveTv/LiveTvServiceStatusInfo.cs@@ -34,10 +34,16 @@ namespace MediaBrowser.Controller.LiveTv/// </summary>/// <value>The tuners.</value>public List<LiveTvTunerInfo> Tuners { get; set; }-+ /// <summary>+ /// Gets or sets a value indicating whether this instance is visible.+ /// </summary>+ /// <value><c>true</c> if this instance is visible; otherwise, <c>false</c>.</value>+ public bool IsVisible { get; set; }+public LiveTvServiceStatusInfo(){Tuners = new List<LiveTvTunerInfo>();+ IsVisible = true;}}}diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.csindex 303b12af7d..2ca7397c1e 100644--- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs+++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs@@ -18,6 +18,7 @@ namespace MediaBrowser.Model.LiveTvpublic class TunerHostInfo{+ public string Id { get; set; }public string Url { get; set; }public string Type { get; set; }}diff --git a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.csindex 264870ffbb..25d3b289f0 100644--- a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs+++ b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs@@ -42,6 +42,11 @@ namespace MediaBrowser.Model.LiveTv/// </summary>/// <value><c>true</c> if this instance has update available; otherwise, <c>false</c>.</value>public bool HasUpdateAvailable { get; set; }+ /// <summary>+ /// Gets or sets a value indicating whether this instance is visible.+ /// </summary>+ /// <value><c>true</c> if this instance is visible; otherwise, <c>false</c>.</value>+ public bool IsVisible { get; set; }public List<LiveTvTunerInfoDto> Tuners { get; set; }diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.csindex d0a2712606..b71d62f433 100644--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs@@ -20,6 +20,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV{public class EmbyTV : ILiveTvService, IDisposable{+ private readonly IApplicationHost _appHpst;private readonly ILogger _logger;private readonly IHttpClient _httpClient;private readonly IConfigurationManager _config;@@ -32,6 +33,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTVpublic EmbyTV(IApplicationHost appHost, ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IConfigurationManager config){+ _appHpst = appHost;_logger = logger;_httpClient = httpClient;_config = config;@@ -90,6 +92,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTVstatus.Tuners = list;status.Status = LiveTvServiceStatus.Ok;+ status.Version = _appHpst.ApplicationVersion.ToString();+ status.IsVisible = false;return status;}diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.csnew file mode 100644index 0000000000..7070c5a5fd--- /dev/null+++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs@@ -0,0 +1,16 @@+using MediaBrowser.Controller.LiveTv;+using System;+using System.Collections.Generic;+using System.Threading;+using System.Threading.Tasks;++namespace MediaBrowser.Server.Implementations.LiveTv.Listings+{+ public class SchedulesDirect : IListingsProvider+ {+ public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ChannelInfo channel, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)+ {+ throw new NotImplementedException();+ }+ }+}diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csindex 80ec2a0365..05bc276b86 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs@@ -2057,6 +2057,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvinfo.Version = statusInfo.Version;info.HasUpdateAvailable = statusInfo.HasUpdateAvailable;info.HomePageUrl = service.HomePageUrl;+ info.IsVisible = statusInfo.IsVisible;info.Tuners = statusInfo.Tuners.Select(i =>{diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun.csindex cadbe7bc3b..b5b588682a 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun.cs@@ -3,6 +3,7 @@ using MediaBrowser.Common.Net;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Extensions;using MediaBrowser.Model.LiveTv;using MediaBrowser.Model.Logging;using MediaBrowser.Model.MediaInfo;@@ -14,6 +15,7 @@ using System.IO;using System.Linq;using System.Threading;using System.Threading.Tasks;+using MediaBrowser.Server.Implementations.LiveTv.EmbyTV;namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts{@@ -70,12 +72,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHostspublic async Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken){- var httpOptions = new HttpRequestOptions()+ string model = null;++ using (var stream = await _httpClient.Get(new HttpRequestOptions()+ {+ Url = string.Format("{0}/", GetApiUrl(info)),+ CancellationToken = cancellationToken+ }))+ {+ using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8))+ {+ while (!sr.EndOfStream)+ {+ string line = StripXML(sr.ReadLine());+ if (line.StartsWith("Model:")) { model = line.Replace("Model: ", ""); }+ //if (line.StartsWith("Device ID:")) { deviceID = line.Replace("Device ID: ", ""); }+ //if (line.StartsWith("Firmware:")) { firmware = line.Replace("Firmware: ", ""); }+ }+ }+ }++ using (var stream = await _httpClient.Get(new HttpRequestOptions(){Url = string.Format("{0}/tuners.html", GetApiUrl(info)),CancellationToken = cancellationToken- };- using (var stream = await _httpClient.Get(httpOptions))+ })){var tuners = new List<LiveTvTunerInfo>();using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8))@@ -93,7 +114,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHoststuners.Add(new LiveTvTunerInfo(){Name = name,- SourceType = Name,+ SourceType = string.IsNullOrWhiteSpace(model) ? Name : model,ProgramName = currentChannel,Status = status});diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.jsonindex 2d56e96567..89ff3a9844 100644--- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json+++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json@@ -816,5 +816,6 @@"ButtonShareHelp": "Share a web page containing media information with social media. Media files are never shared publicly.","ButtonShare": "Share","HeaderConfirm": "Confirm",- "ButtonAdvancedRefresh": "Advanced Refresh"+ "ButtonAdvancedRefresh": "Advanced Refresh",+ "MessageConfirmDeleteTunerDevice": "Are you sure you wish to delete this device?"}diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.jsonindex 5a1d9f29ed..b6c1321fa5 100644--- a/MediaBrowser.Server.Implementations/Localization/Server/server.json+++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json@@ -1473,5 +1473,12 @@"HeaderShortOverview": "Short Overview","HeaderType": "Type","HeaderSeverity": "Severity",- "OptionReportActivities": "Activities Log"+ "OptionReportActivities": "Activities Log",+ "HeaderTunerDevices": "Tuner Devices",+ "ButtonAddDevice": "Add Device",+ "HeaderAddDevice": "Add Device",+ "HeaderExternalServices": "External Services",+ "LabelIpAddressPath": "IP Address / Path:",+ "TabExternalServices": "External Services",+ "TabTuners": "Tuners"}diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csprojindex bc1d07426c..dc149318b8 100644--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj@@ -221,6 +221,7 @@<Compile Include="LiveTv\EmbyTV\RecordingHelper.cs" /><Compile Include="LiveTv\EmbyTV\SeriesTimerManager.cs" /><Compile Include="LiveTv\EmbyTV\TimerManager.cs" />+ <Compile Include="LiveTv\Listings\SchedulesDirect.cs" /><Compile Include="LiveTv\LiveTvConfigurationFactory.cs" /><Compile Include="LiveTv\LiveTvDtoService.cs" /><Compile Include="LiveTv\LiveTvManager.cs" />