mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
commit
00eab4146c
@ -79,5 +79,12 @@ namespace MediaBrowser.Controller
|
||||
/// <param name="host">The host.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetLocalApiUrl(string host);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the local API URL.
|
||||
/// </summary>
|
||||
/// <param name="ipAddress">The ip address.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetLocalApiUrl(IPAddress ipAddress);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ namespace MediaBrowser.Dlna.Main
|
||||
|
||||
var descriptorURI = "/dlna/" + udn + "/description.xml";
|
||||
|
||||
var uri = new Uri(_appHost.GetLocalApiUrl(addressString) + descriptorURI);
|
||||
var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorURI);
|
||||
|
||||
var services = new List<string>
|
||||
{
|
||||
|
@ -171,7 +171,7 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||
|
||||
private string GetServerAddress(IPAddress localIp)
|
||||
{
|
||||
return _appHost.GetLocalApiUrl(localIp.ToString());
|
||||
return _appHost.GetLocalApiUrl(localIp);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -29,6 +29,7 @@ namespace MediaBrowser.Model.LiveTv
|
||||
public string Id { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string DeviceId { get; set; }
|
||||
public bool ImportFavoritesOnly { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,22 +81,38 @@ 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
|
||||
}))
|
||||
{
|
||||
}
|
||||
var response = _json.DeserializeFromStream<HdHomerunHost.DiscoverResponse>(stream);
|
||||
|
||||
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
|
||||
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)
|
||||
{
|
||||
_logger.ErrorException("Error saving device", ex);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,7 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -1134,7 +1135,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
|
||||
if (address != null)
|
||||
{
|
||||
return GetLocalApiUrl(address.ToString());
|
||||
return GetLocalApiUrl(address);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -1148,6 +1149,16 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
}
|
||||
}
|
||||
|
||||
public string GetLocalApiUrl(IPAddress ipAddress)
|
||||
{
|
||||
if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6)
|
||||
{
|
||||
return GetLocalApiUrl("[" + ipAddress + "]");
|
||||
}
|
||||
|
||||
return GetLocalApiUrl(ipAddress.ToString());
|
||||
}
|
||||
|
||||
public string GetLocalApiUrl(string host)
|
||||
{
|
||||
return string.Format("http://{0}:{1}",
|
||||
@ -1180,7 +1191,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||
return true;
|
||||
}
|
||||
|
||||
var apiUrl = GetLocalApiUrl(address.ToString());
|
||||
var apiUrl = GetLocalApiUrl(address);
|
||||
apiUrl += "/system/ping";
|
||||
|
||||
if ((DateTime.UtcNow - _lastAddressCacheClear).TotalMinutes >= 5)
|
||||
|
Loading…
x
Reference in New Issue
Block a user