Skip to content

Commit

Permalink
Merge branch 'beta' of https://github.com/MediaBrowser/Emby into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Mar 13, 2016
2 parents fb6f3aa + 04eeac6 commit 0052e14
Show file tree
Hide file tree
Showing 134 changed files with 1,426 additions and 1,866 deletions.
2 changes: 1 addition & 1 deletion MediaBrowser.Api/TvShowsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public object Get(GetUpcomingEpisodes request)
{
var user = _userManager.GetUserById(request.UserId);

var minPremiereDate = DateTime.Now.Date.AddDays(-1).ToUniversalTime();
var minPremiereDate = DateTime.Now.Date.ToUniversalTime();

var parentIds = string.IsNullOrWhiteSpace(request.ParentId) ? new string[] { } : new[] { request.ParentId };

Expand Down
5 changes: 0 additions & 5 deletions MediaBrowser.Model/ApiClient/ServerCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public void AddOrUpdateServer(ServerInfo server)
{
existing.DateLastAccessed = server.DateLastAccessed;
}

if (server.DateLastLocalConnection > existing.DateLastLocalConnection)
{
existing.DateLastLocalConnection = server.DateLastLocalConnection;
}

existing.UserLinkType = server.UserLinkType;

Expand Down
1 change: 0 additions & 1 deletion MediaBrowser.Model/ApiClient/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ServerInfo
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; }
Expand Down
3 changes: 3 additions & 0 deletions MediaBrowser.Model/LiveTv/LiveTvOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class TunerHostInfo
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; }

Expand Down
13 changes: 13 additions & 0 deletions MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,19 @@ private async Task UpdateTimersForSeriesTimer(List<ProgramInfo> epgData, SeriesT

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Linq;
using CommonIO;
using MediaBrowser.Common.IO;

namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
Expand Down Expand Up @@ -35,9 +34,10 @@ public IReadOnlyList<T> GetAll()
{
if (_items == null)
{
Logger.Info("Loading live tv data from {0}", _dataPath);
_items = GetItemsFromFile(_dataPath);
}
return _items;
return _items.ToList();
}
}

Expand All @@ -47,7 +47,7 @@ private List<T> GetItemsFromFile(string path)

try
{
return _jsonSerializer.DeserializeFromFile<List<T>>(jsonFile);
return _jsonSerializer.DeserializeFromFile<List<T>>(jsonFile) ?? new List<T>();
}
catch (FileNotFoundException)
{
Expand All @@ -58,7 +58,6 @@ private List<T> GetItemsFromFile(string path)
catch (IOException ex)
{
Logger.ErrorException("Error deserializing {0}", ex, jsonFile);
throw;
}
catch (Exception ex)
{
Expand All @@ -69,6 +68,11 @@ private List<T> GetItemsFromFile(string path)

private void UpdateList(List<T> newList)
{
if (newList == null)
{
throw new ArgumentNullException("newList");
}

var file = _dataPath + ".json";
_fileSystem.CreateDirectory(Path.GetDirectoryName(file));

Expand All @@ -81,6 +85,11 @@ private void UpdateList(List<T> newList)

public virtual void Update(T item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}

var list = GetAll().ToList();

var index = list.FindIndex(i => EqualityComparer(i, item));
Expand All @@ -97,6 +106,11 @@ public virtual void Update(T item)

public virtual void Add(T item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}

var list = GetAll().ToList();

if (list.Any(i => EqualityComparer(i, item)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ public class HdHomerunDiscovery : IServerEntryPoint
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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;
Expand All @@ -33,13 +32,6 @@ public class SatIpDiscovery : IServerEntryPoint

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;
Expand Down Expand Up @@ -83,15 +75,43 @@ private async void AddDevice(string location)

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)
{
Expand All @@ -111,6 +131,29 @@ private async void AddDevice(string location)
}
}

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()
{
}
Expand Down Expand Up @@ -158,7 +201,7 @@ public async Task<SatIpTunerHostInfo> GetInfo(string url, CancellationToken canc
}
}

if (string.IsNullOrWhiteSpace(result.Id))
if (string.IsNullOrWhiteSpace(result.DeviceId))
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -192,7 +235,7 @@ private void FillFromDeviceNode(SatIpTunerHostInfo info, XmlReader reader)
{
case "UDN":
{
info.Id = reader.ReadElementContentAsString();
info.DeviceId = reader.ReadElementContentAsString();
break;
}

Expand Down Expand Up @@ -243,9 +286,6 @@ private void FillFromDeviceNode(SatIpTunerHostInfo info, XmlReader reader)

public class SatIpTunerHostInfo : TunerHostInfo
{
public int Tuners { get; set; }
public int TunersAvailable { get; set; }
public string M3UUrl { get; set; }
public string FriendlyName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public SatIpHost(IConfigurationManager config, ILogger logger, IJsonSerializer j

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
Expand Down Expand Up @@ -128,11 +126,6 @@ protected override bool IsValidChannelId(string channelId)
return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);
}

protected override List<TunerHostInfo> GetTunerHosts()
{
return SatIpDiscovery.Current.DiscoveredHosts;
}

public string Name
{
get { return "Sat IP"; }
Expand All @@ -149,15 +142,13 @@ public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationT

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),
Expand Down
Loading

0 comments on commit 0052e14

Please sign in to comment.