diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 9b4c35c41..d1429c366 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -302,7 +302,6 @@ - @@ -330,7 +329,6 @@ - diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 12c893b0f..62377b19e 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -131,7 +131,7 @@ namespace MediaBrowser.Controller.MediaEncoding /// System.String. string EscapeSubtitleFilterPath(string path); - void Init(); + Task Init(); Task UpdateEncoderPath(string path, string pathType); } diff --git a/MediaBrowser.Controller/Providers/ISeriesOrderManager.cs b/MediaBrowser.Controller/Providers/ISeriesOrderManager.cs deleted file mode 100644 index 970f7a7be..000000000 --- a/MediaBrowser.Controller/Providers/ISeriesOrderManager.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Providers -{ - public interface ISeriesOrderManager - { - Task FindSeriesIndex(string orderType, string seriesName); - void AddParts(IEnumerable orderProviders); - } -} diff --git a/MediaBrowser.Controller/Providers/ISeriesOrderProvider.cs b/MediaBrowser.Controller/Providers/ISeriesOrderProvider.cs deleted file mode 100644 index ee0f3c197..000000000 --- a/MediaBrowser.Controller/Providers/ISeriesOrderProvider.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Providers -{ - public interface ISeriesOrderProvider - { - string OrderType { get; } - Task FindSeriesIndex(string seriesName); - } -} \ No newline at end of file diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs index 3cc6a4379..b4127a91f 100644 --- a/MediaBrowser.Dlna/DlnaManager.cs +++ b/MediaBrowser.Dlna/DlnaManager.cs @@ -29,6 +29,8 @@ namespace MediaBrowser.Dlna private readonly IJsonSerializer _jsonSerializer; private readonly IServerApplicationHost _appHost; + private readonly Dictionary _profiles = new Dictionary(StringComparer.Ordinal); + public DlnaManager(IXmlSerializer xmlSerializer, IFileSystem fileSystem, IApplicationPaths appPaths, @@ -300,20 +302,31 @@ namespace MediaBrowser.Dlna private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type) { - try + lock (_profiles) { - var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); + DeviceProfile profile; + if (_profiles.TryGetValue(path, out profile)) + { + return profile; + } - profile.Id = path.ToLower().GetMD5().ToString("N"); - profile.ProfileType = type; + try + { + profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - return profile; - } - catch (Exception ex) - { - _logger.ErrorException("Error parsing profile xml: {0}", ex, path); + profile.Id = path.ToLower().GetMD5().ToString("N"); + profile.ProfileType = type; - return null; + _profiles[path] = profile; + + return profile; + } + catch (Exception ex) + { + _logger.ErrorException("Error parsing profile xml: {0}", ex, path); + + return null; + } } } @@ -428,7 +441,7 @@ namespace MediaBrowser.Dlna var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml"; var path = Path.Combine(UserProfilesPath, newFilename); - _xmlSerializer.SerializeToFile(profile, path); + SaveProfile(profile, path); } public void UpdateProfile(DeviceProfile profile) @@ -455,6 +468,15 @@ namespace MediaBrowser.Dlna _fileSystem.DeleteFile(current.Path); } + SaveProfile(profile, path); + } + + private void SaveProfile(DeviceProfile profile, string path) + { + lock (_profiles) + { + _profiles[path] = profile; + } _xmlSerializer.SerializeToFile(profile, path); } diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs similarity index 84% rename from MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs rename to MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index d92dc1b96..6059108c8 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -1,31 +1,29 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Logging; -using System; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Collections.Generic; -using CommonIO; +using MediaBrowser.Model.Logging; -namespace MediaBrowser.Server.Startup.Common.FFMpeg +namespace MediaBrowser.MediaEncoding.Encoder { - public class FFmpegValidator + public class EncoderValidator { private readonly ILogger _logger; - private readonly IApplicationPaths _appPaths; - private readonly IFileSystem _fileSystem; - public FFmpegValidator(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem) + public EncoderValidator(ILogger logger) { _logger = logger; - _appPaths = appPaths; - _fileSystem = fileSystem; } - public Tuple,List> Validate(string encoderPath) + public Tuple, List> Validate(string encoderPath) { + _logger.Info("Validating media encoder at {0}", encoderPath); + var decoders = GetDecoders(encoderPath); var encoders = GetEncoders(encoderPath); + _logger.Info("Encoder validation complete"); + return new Tuple, List>(decoders, encoders); } @@ -136,13 +134,12 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg { process.BeginErrorReadLine(); - using (var reader = new StreamReader(process.StandardOutput.BaseStream)) - { - return reader.ReadToEnd(); - } + return process.StandardOutput.ReadToEnd(); } catch { + _logger.Info("Killing process {0} {1}", path, arguments); + // Hate having to do this try { diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 5b9a2a682..7264ad2d1 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -132,7 +132,20 @@ namespace MediaBrowser.MediaEncoding.Encoder return false; } - public void Init() + public async Task Init() + { + InitPaths(); + + if (!string.IsNullOrWhiteSpace(FFMpegPath)) + { + var result = new EncoderValidator(_logger).Validate(FFMpegPath); + + SetAvailableDecoders(result.Item1); + SetAvailableEncoders(result.Item2); + } + } + + private void InitPaths() { ConfigureEncoderPaths(); @@ -322,7 +335,11 @@ namespace MediaBrowser.MediaEncoding.Encoder files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); ffmpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase)); - ffprobePath = GetProbePathFromEncoderPath(ffmpegPath); + + if (!string.IsNullOrWhiteSpace(ffmpegPath)) + { + ffprobePath = GetProbePathFromEncoderPath(ffmpegPath); + } } return new Tuple(ffmpegPath, ffprobePath); diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 5576a49bd..794353451 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -71,6 +71,7 @@ + diff --git a/MediaBrowser.Providers/Manager/SeriesOrderManager.cs b/MediaBrowser.Providers/Manager/SeriesOrderManager.cs deleted file mode 100644 index 1050bdbbd..000000000 --- a/MediaBrowser.Providers/Manager/SeriesOrderManager.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediaBrowser.Controller.Providers; - -namespace MediaBrowser.Providers.Manager -{ - public class SeriesOrderManager : ISeriesOrderManager - { - private Dictionary _providers; - - public void AddParts(IEnumerable orderProviders) - { - _providers = orderProviders - .GroupBy(p => p.OrderType) - .ToDictionary(g => g.Key, g => g.ToArray()); - } - - public async Task FindSeriesIndex(string orderType, string seriesName) - { - ISeriesOrderProvider[] providers; - if (!_providers.TryGetValue(orderType, out providers)) - return null; - - foreach (ISeriesOrderProvider provider in providers) - { - int? index = await provider.FindSeriesIndex(seriesName); - if (index != null) - return index; - } - - return null; - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 240b2e2cc..99d8b15b6 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -103,7 +103,6 @@ - diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index 49ca5cdf2..b6cc8777d 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -38,17 +38,15 @@ namespace MediaBrowser.Providers.TV private readonly IServerConfigurationManager _config; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly ILogger _logger; - private readonly ISeriesOrderManager _seriesOrder; private readonly ILibraryManager _libraryManager; - public TvdbSeriesProvider(IZipClient zipClient, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager config, ILogger logger, ISeriesOrderManager seriesOrder, ILibraryManager libraryManager) + public TvdbSeriesProvider(IZipClient zipClient, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager) { _zipClient = zipClient; _httpClient = httpClient; _fileSystem = fileSystem; _config = config; _logger = logger; - _seriesOrder = seriesOrder; _libraryManager = libraryManager; Current = this; } @@ -112,23 +110,11 @@ namespace MediaBrowser.Providers.TV result.HasMetadata = true; FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken); - await FindAnimeSeriesIndex(result.Item, itemId).ConfigureAwait(false); } return result; } - private async Task FindAnimeSeriesIndex(Series series, SeriesInfo info) - { - var index = await _seriesOrder.FindSeriesIndex(SeriesOrderTypes.Anime, series.Name); - if (index == null) - return; - - var offset = info.AnimeSeriesIndex - index; - var id = string.Format(TvdbSeriesOffsetFormat, series.GetProviderId(MetadataProviders.Tvdb), offset); - series.SetProviderId(TvdbSeriesOffset, id); - } - internal static int? GetSeriesOffset(Dictionary seriesProviderIds) { string idString; diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs index ea12e332d..28a62c012 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -41,14 +41,15 @@ namespace MediaBrowser.Server.Implementations.Connect public void Run() { - Task.Run(() => LoadCachedAddress()); + LoadCachedAddress(); _timer = new PeriodicTimer(TimerCallback, null, TimeSpan.FromSeconds(5), TimeSpan.FromHours(3)); + ((ConnectManager)_connectManager).Start(); } private readonly string[] _ipLookups = { - "http://bot.whatismyipaddress.com", + "http://bot.whatismyipaddress.com", "https://connect.emby.media/service/ip" }; @@ -78,17 +79,18 @@ namespace MediaBrowser.Server.Implementations.Connect } // If this produced an ipv6 address, try again - if (validIpAddress == null || validIpAddress.AddressFamily == AddressFamily.InterNetworkV6) + if (validIpAddress != null && validIpAddress.AddressFamily == AddressFamily.InterNetworkV6) { foreach (var ipLookupUrl in _ipLookups) { try { - validIpAddress = await GetIpAddress(ipLookupUrl, true).ConfigureAwait(false); + var newAddress = await GetIpAddress(ipLookupUrl, true).ConfigureAwait(false); // Try to find the ipv4 address, if present - if (validIpAddress.AddressFamily == AddressFamily.InterNetwork) + if (newAddress.AddressFamily == AddressFamily.InterNetwork) { + validIpAddress = newAddress; break; } } @@ -162,6 +164,8 @@ namespace MediaBrowser.Server.Implementations.Connect { var path = CacheFilePath; + _logger.Info("Loading data from {0}", path); + try { var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8); diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 6190a9da0..24750de94 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -139,11 +139,14 @@ namespace MediaBrowser.Server.Implementations.Connect _securityManager = securityManager; _fileSystem = fileSystem; - _config.ConfigurationUpdated += _config_ConfigurationUpdated; - LoadCachedData(); } + internal void Start() + { + _config.ConfigurationUpdated += _config_ConfigurationUpdated; + } + internal void OnWanAddressResolved(IPAddress address) { DiscoveredWanIpAddress = address; @@ -359,6 +362,8 @@ namespace MediaBrowser.Server.Implementations.Connect { var path = CacheFilePath; + _logger.Info("Loading data from {0}", path); + try { lock (_dataFileLock) diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 651b0e01f..1e5c54d93 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -160,7 +160,6 @@ namespace MediaBrowser.Server.Startup.Common private IHttpServer HttpServer { get; set; } private IDtoService DtoService { get; set; } private IImageProcessor ImageProcessor { get; set; } - private ISeriesOrderManager SeriesOrderManager { get; set; } /// /// Gets or sets the media encoder. @@ -323,7 +322,7 @@ namespace MediaBrowser.Server.Startup.Common await base.RunStartupTasks().ConfigureAwait(false); - InitMediaEncoder(); + await MediaEncoder.Init().ConfigureAwait(false); Logger.Info("ServerId: {0}", SystemId); Logger.Info("Core startup complete"); @@ -351,20 +350,6 @@ namespace MediaBrowser.Server.Startup.Common LogManager.RemoveConsoleOutput(); } - private void InitMediaEncoder() - { - MediaEncoder.Init(); - - Task.Run(() => - { - var result = new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(MediaEncoder.EncoderPath); - - var mediaEncoder = (MediaEncoder) MediaEncoder; - mediaEncoder.SetAvailableDecoders(result.Item1); - mediaEncoder.SetAvailableEncoders(result.Item2); - }); - } - public override Task Init(IProgress progress) { HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; @@ -476,9 +461,6 @@ namespace MediaBrowser.Server.Startup.Common ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); RegisterSingleInstance(ProviderManager); - SeriesOrderManager = new SeriesOrderManager(); - RegisterSingleInstance(SeriesOrderManager); - RegisterSingleInstance(() => new SearchEngine(LogManager, LibraryManager, UserManager)); HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, "Emby", "web/index.html"); @@ -819,8 +801,6 @@ namespace MediaBrowser.Server.Startup.Common GetExports(), GetExports()); - SeriesOrderManager.AddParts(GetExports()); - ImageProcessor.AddParts(GetExports()); LiveTvManager.AddParts(GetExports(), GetExports(), GetExports()); diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 5b88a6bd9..808d25fc9 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -68,7 +68,6 @@ -