Просмотр исходного кода

Merge pull request #1894 from MediaBrowser/dev

Dev
Luke 9 лет назад
Родитель
Сommit
8f11917e84

+ 0 - 2
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -302,7 +302,6 @@
     <Compile Include="Providers\IMetadataService.cs" />
     <Compile Include="Providers\IRemoteMetadataProvider.cs" />
     <Compile Include="Providers\IRemoteSearchProvider.cs" />
-    <Compile Include="Providers\ISeriesOrderProvider.cs" />
     <Compile Include="Providers\ItemInfo.cs" />
     <Compile Include="Providers\LiveTvProgramLookupInfo.cs" />
     <Compile Include="Providers\LocalImageInfo.cs" />
@@ -330,7 +329,6 @@
     <Compile Include="Subtitles\ISubtitleProvider.cs" />
     <Compile Include="Providers\ItemLookupInfo.cs" />
     <Compile Include="Providers\MetadataRefreshOptions.cs" />
-    <Compile Include="Providers\ISeriesOrderManager.cs" />
     <Compile Include="Session\ISessionManager.cs" />
     <Compile Include="Entities\AggregateFolder.cs" />
     <Compile Include="Entities\Audio\Audio.cs" />

+ 1 - 1
MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs

@@ -131,7 +131,7 @@ namespace MediaBrowser.Controller.MediaEncoding
         /// <returns>System.String.</returns>
         string EscapeSubtitleFilterPath(string path);
 
-        void Init();
+        Task Init();
 
         Task UpdateEncoderPath(string path, string pathType);
     }

+ 0 - 11
MediaBrowser.Controller/Providers/ISeriesOrderManager.cs

@@ -1,11 +0,0 @@
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace MediaBrowser.Controller.Providers
-{
-    public interface ISeriesOrderManager
-    {
-        Task<int?> FindSeriesIndex(string orderType, string seriesName);
-        void AddParts(IEnumerable<ISeriesOrderProvider> orderProviders);
-    }
-}

+ 0 - 10
MediaBrowser.Controller/Providers/ISeriesOrderProvider.cs

@@ -1,10 +0,0 @@
-using System.Threading.Tasks;
-
-namespace MediaBrowser.Controller.Providers
-{
-    public interface ISeriesOrderProvider
-    {
-        string OrderType { get; }
-        Task<int?> FindSeriesIndex(string seriesName);
-    }
-}

+ 33 - 11
MediaBrowser.Dlna/DlnaManager.cs

@@ -29,6 +29,8 @@ namespace MediaBrowser.Dlna
         private readonly IJsonSerializer _jsonSerializer;
         private readonly IServerApplicationHost _appHost;
 
+        private readonly Dictionary<string, DeviceProfile> _profiles = new Dictionary<string, DeviceProfile>(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;
+                }
+
+                try
+                {
+                    profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
 
-                profile.Id = path.ToLower().GetMD5().ToString("N");
-                profile.ProfileType = type;
+                    profile.Id = path.ToLower().GetMD5().ToString("N");
+                    profile.ProfileType = type;
 
-                return profile;
-            }
-            catch (Exception ex)
-            {
-                _logger.ErrorException("Error parsing profile xml: {0}", ex, path);
+                    _profiles[path] = profile;
 
-                return null;
+                    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);
         }
 

+ 14 - 17
MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs → 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<string>,List<string>> Validate(string encoderPath)
+        public Tuple<List<string>, List<string>> 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<string>, List<string>>(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
                     {

+ 19 - 2
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<string, string>(ffmpegPath, ffprobePath);

+ 1 - 0
MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj

@@ -71,6 +71,7 @@
     <Compile Include="Encoder\EncodingJob.cs" />
     <Compile Include="Encoder\EncodingJobFactory.cs" />
     <Compile Include="Encoder\EncodingUtils.cs" />
+    <Compile Include="Encoder\EncoderValidator.cs" />
     <Compile Include="Encoder\JobLogger.cs" />
     <Compile Include="Encoder\MediaEncoder.cs" />
     <Compile Include="Encoder\VideoEncoder.cs" />

+ 0 - 35
MediaBrowser.Providers/Manager/SeriesOrderManager.cs

@@ -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<string, ISeriesOrderProvider[]> _providers;
-
-        public void AddParts(IEnumerable<ISeriesOrderProvider> orderProviders)
-        {
-            _providers = orderProviders
-                .GroupBy(p => p.OrderType)
-                .ToDictionary(g => g.Key, g => g.ToArray());
-        }
-
-        public async Task<int?> 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;
-        }
-    }
-}

+ 0 - 1
MediaBrowser.Providers/MediaBrowser.Providers.csproj

@@ -103,7 +103,6 @@
     <Compile Include="Manager\ItemImageProvider.cs" />
     <Compile Include="Manager\ProviderManager.cs" />
     <Compile Include="Manager\MetadataService.cs" />
-    <Compile Include="Manager\SeriesOrderManager.cs" />
     <Compile Include="MediaInfo\FFProbeAudioInfo.cs" />
     <Compile Include="MediaInfo\FFProbeProvider.cs" />
     <Compile Include="MediaInfo\FFProbeVideoInfo.cs" />

+ 1 - 15
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<string, string> seriesProviderIds)
         {
             string idString;

+ 9 - 5
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);

+ 7 - 2
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)

+ 1 - 21
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; }
 
         /// <summary>
         /// 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<double> 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<ISearchEngine>(() => 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<IImageSaver>(),
                                      GetExports<IExternalId>());
 
-            SeriesOrderManager.AddParts(GetExports<ISeriesOrderProvider>());
-
             ImageProcessor.AddParts(GetExports<IImageEnhancer>());
 
             LiveTvManager.AddParts(GetExports<ILiveTvService>(), GetExports<ITunerHost>(), GetExports<IListingsProvider>());

+ 0 - 1
MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj

@@ -68,7 +68,6 @@
     <Compile Include="FFMpeg\FFMpegLoader.cs" />
     <Compile Include="FFMpeg\FFMpegInstallInfo.cs" />
     <Compile Include="FFMpeg\FFMpegInfo.cs" />
-    <Compile Include="FFMpeg\FFmpegValidator.cs" />
     <Compile Include="INativeApp.cs" />
     <Compile Include="MbLinkShortcutHandler.cs" />
     <Compile Include="Migrations\CollectionGroupingMigration.cs" />