Merge pull request #1894 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-06-30 01:06:08 -04:00 committed by GitHub
commit 8f11917e84
15 changed files with 86 additions and 134 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,9 +41,10 @@ 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 =
@ -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);

View File

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

View File

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

View File

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