The Free Software Media System - Server Backend & API
update sat/ip discovery
Luke Pulverenti749037eb4a73
diff --git a/MediaBrowser.Model/ApiClient/ServerCredentials.cs b/MediaBrowser.Model/ApiClient/ServerCredentials.csindex f9af0fa4ef..0f0ab65d4a 100644--- a/MediaBrowser.Model/ApiClient/ServerCredentials.cs+++ b/MediaBrowser.Model/ApiClient/ServerCredentials.cs@@ -41,11 +41,6 @@ namespace MediaBrowser.Model.ApiClient{existing.DateLastAccessed = server.DateLastAccessed;}-- if (server.DateLastLocalConnection > existing.DateLastLocalConnection)- {- existing.DateLastLocalConnection = server.DateLastLocalConnection;- }existing.UserLinkType = server.UserLinkType;diff --git a/MediaBrowser.Model/ApiClient/ServerInfo.cs b/MediaBrowser.Model/ApiClient/ServerInfo.csindex 53ae5be528..e1fa581d7b 100644--- a/MediaBrowser.Model/ApiClient/ServerInfo.cs+++ b/MediaBrowser.Model/ApiClient/ServerInfo.cs@@ -19,7 +19,6 @@ namespace MediaBrowser.Model.ApiClientpublic String AccessToken { get; set; }public List<WakeOnLanInfo> WakeOnLanInfos { get; set; }public DateTime DateLastAccessed { get; set; }- public DateTime DateLastLocalConnection { get; set; }public String ExchangeToken { get; set; }public UserLinkType? UserLinkType { get; set; }public ConnectionMode? LastConnectionMode { get; set; }diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.csindex c6b8385b0f..78c6830642 100644--- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs+++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs@@ -32,6 +32,9 @@ namespace MediaBrowser.Model.LiveTvpublic string DeviceId { get; set; }public bool ImportFavoritesOnly { get; set; }public bool IsEnabled { get; set; }+ public string M3UUrl { get; set; }+ public string FriendlyName { get; set; }+ public int Tuners { get; set; }public int DataVersion { get; set; }diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.csindex aa4583ef8c..e00a68e32b 100644--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs@@ -1008,6 +1008,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTVprivate IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> allPrograms, IReadOnlyList<RecordingInfo> currentRecordings){+ if (seriesTimer == null)+ {+ throw new ArgumentNullException("seriesTimer");+ }+ if (allPrograms == null)+ {+ throw new ArgumentNullException("allPrograms");+ }+ if (currentRecordings == null)+ {+ throw new ArgumentNullException("currentRecordings");+ }+// Exclude programs that have already endedallPrograms = allPrograms.Where(i => i.EndDate > DateTime.UtcNow && i.StartDate > DateTime.UtcNow);diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.csindex a4eb23d993..79b26468e6 100644--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs@@ -5,7 +5,6 @@ using System.Collections.Generic;using System.IO;using System.Linq;using CommonIO;-using MediaBrowser.Common.IO;namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV{@@ -35,9 +34,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV{if (_items == null){+ Logger.Info("Loading live tv data from {0}", _dataPath);_items = GetItemsFromFile(_dataPath);}- return _items;+ return _items.ToList();}}@@ -58,7 +58,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTVcatch (IOException ex){Logger.ErrorException("Error deserializing {0}", ex, jsonFile);- throw;}catch (Exception ex){diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.csindex aa4030b813..9ba1c60cc9 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs@@ -22,15 +22,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerunprivate readonly ILiveTvManager _liveTvManager;private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);private readonly IHttpClient _httpClient;- private IJsonSerializer _json;+ private readonly IJsonSerializer _json;- public HdHomerunDiscovery(IDeviceDiscovery deviceDiscovery, IServerConfigurationManager config, ILogger logger, ILiveTvManager liveTvManager, IHttpClient httpClient)+ public HdHomerunDiscovery(IDeviceDiscovery deviceDiscovery, IServerConfigurationManager config, ILogger logger, ILiveTvManager liveTvManager, IHttpClient httpClient, IJsonSerializer json){_deviceDiscovery = deviceDiscovery;_config = config;_logger = logger;_liveTvManager = liveTvManager;_httpClient = httpClient;+ _json = json;}public void Run()diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpDiscovery.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpDiscovery.csindex 6781e498ac..9a02413cd6 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpDiscovery.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpDiscovery.cs@@ -14,7 +14,6 @@ using MediaBrowser.Controller.Configuration;using MediaBrowser.Controller.Dlna;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Controller.Plugins;-using MediaBrowser.Model.Extensions;using MediaBrowser.Model.LiveTv;using MediaBrowser.Model.Logging;using MediaBrowser.Model.Serialization;@@ -33,13 +32,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIppublic static SatIpDiscovery Current;- private readonly List<TunerHostInfo> _discoveredHosts = new List<TunerHostInfo>();-- public List<TunerHostInfo> DiscoveredHosts- {- get { return _discoveredHosts.ToList(); }- }-public SatIpDiscovery(IDeviceDiscovery deviceDiscovery, IServerConfigurationManager config, ILogger logger, ILiveTvManager liveTvManager, IHttpClient httpClient, IJsonSerializer json){_deviceDiscovery = deviceDiscovery;@@ -83,15 +75,43 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIptry{- if (_discoveredHosts.Any(i => string.Equals(i.Type, SatIpHost.DeviceType, StringComparison.OrdinalIgnoreCase) && string.Equals(location, i.Url, StringComparison.OrdinalIgnoreCase)))+ var options = GetConfiguration();++ if (options.TunerHosts.Any(i => string.Equals(i.Type, SatIpHost.DeviceType, StringComparison.OrdinalIgnoreCase) && UriEquals(i.Url, location))){return;}-+_logger.Debug("Will attempt to add SAT device {0}", location);var info = await GetInfo(location, CancellationToken.None).ConfigureAwait(false);- _discoveredHosts.Add(info);+ var existing = GetConfiguration().TunerHosts+ .FirstOrDefault(i => string.Equals(i.Type, SatIpHost.DeviceType, StringComparison.OrdinalIgnoreCase) && string.Equals(i.DeviceId, info.DeviceId, StringComparison.OrdinalIgnoreCase));++ if (existing == null)+ {+ await _liveTvManager.SaveTunerHost(new TunerHostInfo+ {+ Type = SatIpHost.DeviceType,+ Url = location,+ DataVersion = 1,+ DeviceId = info.DeviceId,+ FriendlyName = info.FriendlyName,+ Tuners = info.Tuners++ }).ConfigureAwait(false);+ }+ else+ {+ if (!string.Equals(existing.Url, location, StringComparison.OrdinalIgnoreCase))+ {+ existing.Url = location;+ existing.M3UUrl = info.M3UUrl;+ existing.FriendlyName = info.FriendlyName;+ existing.Tuners = info.Tuners;+ await _liveTvManager.SaveTunerHost(existing).ConfigureAwait(false);+ }+ }}catch (OperationCanceledException){@@ -111,6 +131,29 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp}}+ private bool UriEquals(string savedUri, string location)+ {+ return string.Equals(NormalizeUrl(location), NormalizeUrl(savedUri), StringComparison.OrdinalIgnoreCase);+ }++ private string NormalizeUrl(string url)+ {+ if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase))+ {+ url = "http://" + url;+ }++ url = url.TrimEnd('/');++ // Strip off the port+ return new Uri(url).GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped);+ }++ private LiveTvOptions GetConfiguration()+ {+ return _config.GetConfiguration<LiveTvOptions>("livetv");+ }+public void Dispose(){}@@ -158,7 +201,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp}}- if (string.IsNullOrWhiteSpace(result.Id))+ if (string.IsNullOrWhiteSpace(result.DeviceId)){throw new NotImplementedException();}@@ -192,7 +235,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp{case "UDN":{- info.Id = reader.ReadElementContentAsString();+ info.DeviceId = reader.ReadElementContentAsString();break;}@@ -243,9 +286,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIppublic class SatIpTunerHostInfo : TunerHostInfo{- public int Tuners { get; set; }public int TunersAvailable { get; set; }- public string M3UUrl { get; set; }- public string FriendlyName { get; set; }}}diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.csindex d305a886a6..4bbb7e85ca 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs@@ -35,9 +35,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIpprotected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken){- var satInfo = (SatIpTunerHostInfo)tuner;-- return await new M3uParser(Logger, _fileSystem, _httpClient).Parse(satInfo.M3UUrl, ChannelIdPrefix, tuner.Id, cancellationToken).ConfigureAwait(false);+ return await new M3uParser(Logger, _fileSystem, _httpClient).Parse(tuner.M3UUrl, ChannelIdPrefix, tuner.Id, cancellationToken).ConfigureAwait(false);}public static string DeviceType@@ -128,11 +126,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIpreturn channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);}- protected override List<TunerHostInfo> GetTunerHosts()- {- return SatIpDiscovery.Current.DiscoveredHosts;- }-public string Name{get { return "Sat IP"; }@@ -149,15 +142,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIppublic List<LiveTvTunerInfo> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken){- var satInfo = (SatIpTunerHostInfo)info;-var list = new List<LiveTvTunerInfo>();- for (var i = 0; i < satInfo.Tuners; i++)+ for (var i = 0; i < info.Tuners; i++){list.Add(new LiveTvTunerInfo{- Name = satInfo.FriendlyName ?? Name,+ Name = info.FriendlyName ?? Name,SourceType = Type,Status = LiveTvTunerStatus.Available,Id = info.Url.GetMD5().ToString("N") + i.ToString(CultureInfo.InvariantCulture),diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csprojindex 74bc05fe82..fb52b58b75 100644--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj@@ -272,6 +272,9 @@<Content Include="dashboard-ui\livetvtunerprovider-m3u.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\livetvtunerprovider-satip.html">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\mypreferenceshome.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>@@ -302,6 +305,9 @@<Content Include="dashboard-ui\scripts\livetvtunerprovider-m3u.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\scripts\livetvtunerprovider-satip.js">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\scripts\localsync.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>