aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-03-09 12:53:39 -0500
committerLuke <luke.pulverenti@gmail.com>2016-03-09 12:53:39 -0500
commit00eab4146c0b103ab38565eef58b521d47343c63 (patch)
treec71e7568427015e968fe87f925b2aa57bade062a /MediaBrowser.Server.Implementations
parent91c949bd65092395c9aea3584c66bbec6db7c411 (diff)
parentaa23da0dc44afbfe47a83d2dda0644472ad4e0e4 (diff)
Merge pull request #1539 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Connect/ConnectManager.cs16
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs38
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs16
3 files changed, 53 insertions, 17 deletions
diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs
index d7477225c..618b7ffc5 100644
--- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs
+++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs
@@ -81,6 +81,12 @@ namespace MediaBrowser.Server.Implementations.Connect
if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
!ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
+ // Handle ipv6
+ if (ip.IndexOf(':') != -1)
+ {
+ ip = "[" + ip + "]";
+ }
+
ip = (_appHost.EnableHttps ? "https://" : "http://") + ip;
}
@@ -316,7 +322,7 @@ namespace MediaBrowser.Server.Implementations.Connect
try
{
- _fileSystem.CreateDirectory(Path.GetDirectoryName(path));
+ _fileSystem.CreateDirectory(Path.GetDirectoryName(path));
var json = _json.SerializeToString(_data);
@@ -324,7 +330,7 @@ namespace MediaBrowser.Server.Implementations.Connect
lock (_dataFileLock)
{
- _fileSystem.WriteAllText(path, encrypted, Encoding.UTF8);
+ _fileSystem.WriteAllText(path, encrypted, Encoding.UTF8);
}
}
catch (Exception ex)
@@ -341,7 +347,7 @@ namespace MediaBrowser.Server.Implementations.Connect
{
lock (_dataFileLock)
{
- var encrypted = _fileSystem.ReadAllText(path, Encoding.UTF8);
+ var encrypted = _fileSystem.ReadAllText(path, Encoding.UTF8);
var json = _encryption.DecryptString(encrypted);
@@ -381,7 +387,7 @@ namespace MediaBrowser.Server.Implementations.Connect
{
await UpdateConnectInfo().ConfigureAwait(false);
}
-
+
await _operationLock.WaitAsync().ConfigureAwait(false);
try
@@ -480,7 +486,7 @@ namespace MediaBrowser.Server.Implementations.Connect
{
await UpdateConnectInfo().ConfigureAwait(false);
}
-
+
await _operationLock.WaitAsync().ConfigureAwait(false);
try
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs
index 0a03e60fa..aa4030b81 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunDiscovery.cs
@@ -10,6 +10,7 @@ using System;
using System.Linq;
using System.Threading;
using MediaBrowser.Common.Net;
+using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
{
@@ -21,6 +22,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
private readonly ILiveTvManager _liveTvManager;
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private readonly IHttpClient _httpClient;
+ private IJsonSerializer _json;
public HdHomerunDiscovery(IDeviceDiscovery deviceDiscovery, IServerConfigurationManager config, ILogger logger, ILiveTvManager liveTvManager, IHttpClient httpClient)
{
@@ -79,21 +81,37 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
url = new Uri(url).GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped).TrimEnd('/');
// Test it by pulling down the lineup
- using (await _httpClient.Get(new HttpRequestOptions
+ using (var stream = await _httpClient.Get(new HttpRequestOptions
{
- Url = string.Format("{0}/lineup.json", url),
+ Url = string.Format("{0}/discover.json", url),
CancellationToken = CancellationToken.None
}))
{
- }
-
- await _liveTvManager.SaveTunerHost(new TunerHostInfo
- {
- Type = HdHomerunHost.DeviceType,
- Url = url,
- DataVersion = 1
+ var response = _json.DeserializeFromStream<HdHomerunHost.DiscoverResponse>(stream);
- }).ConfigureAwait(false);
+ var existing = GetConfiguration().TunerHosts
+ .FirstOrDefault(i => string.Equals(i.Type, HdHomerunHost.DeviceType, StringComparison.OrdinalIgnoreCase) && string.Equals(i.DeviceId, response.DeviceID, StringComparison.OrdinalIgnoreCase));
+
+ if (existing == null)
+ {
+ await _liveTvManager.SaveTunerHost(new TunerHostInfo
+ {
+ Type = HdHomerunHost.DeviceType,
+ Url = url,
+ DataVersion = 1,
+ DeviceId = response.DeviceID
+
+ }).ConfigureAwait(false);
+ }
+ else
+ {
+ if (!string.Equals(existing.Url, url, StringComparison.OrdinalIgnoreCase))
+ {
+ existing.Url = url;
+ await _liveTvManager.SaveTunerHost(existing).ConfigureAwait(false);
+ }
+ }
+ }
}
catch (Exception ex)
{
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
index bdfbee521..1995fc311 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
@@ -415,9 +415,21 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
public async Task Validate(TunerHostInfo info)
{
- if (info.IsEnabled)
+ if (!info.IsEnabled)
{
- await GetChannels(info, false, CancellationToken.None).ConfigureAwait(false);
+ return;
+ }
+
+ // Test it by pulling down the lineup
+ using (var stream = await _httpClient.Get(new HttpRequestOptions
+ {
+ Url = string.Format("{0}/discover.json", GetApiUrl(info, false)),
+ CancellationToken = CancellationToken.None
+ }))
+ {
+ var response = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream);
+
+ info.DeviceId = response.DeviceID;
}
}