update sat/ip discovery

This commit is contained in:
Luke Pulverenti 2016-03-13 03:34:17 -04:00
parent dd6a4eefe5
commit 749037eb4a
9 changed files with 86 additions and 39 deletions

View File

@ -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;

View File

@ -19,7 +19,6 @@ namespace MediaBrowser.Model.ApiClient
public 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; }

View File

@ -32,6 +32,9 @@ namespace MediaBrowser.Model.LiveTv
public 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; }

View File

@ -1008,6 +1008,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private 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 ended
allPrograms = allPrograms.Where(i => i.EndDate > DateTime.UtcNow && i.StartDate > DateTime.UtcNow);

View File

@ -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.EmbyTV
catch (IOException ex)
{
Logger.ErrorException("Error deserializing {0}", ex, jsonFile);
throw;
}
catch (Exception ex)
{

View File

@ -22,15 +22,16 @@ 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;
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()

View File

@ -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.SatIp
public 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.SatIp
try
{
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.SatIp
public class SatIpTunerHostInfo : TunerHostInfo
{
public int Tuners { get; set; }
public int TunersAvailable { get; set; }
public string M3UUrl { get; set; }
public string FriendlyName { get; set; }
}
}

View File

@ -35,9 +35,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp
protected 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.SatIp
return 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.SatIp
public 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),

View File

@ -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>