This commit is contained in:
LukePulverenti
2013-02-24 16:53:54 -05:00
parent 6c86721f6d
commit 8ce3e74e81
93 changed files with 2458 additions and 1584 deletions

View File

@@ -1,12 +1,12 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Drawing
/// <summary>
/// Class ImageManager
/// </summary>
public class ImageManager : BaseManager<Kernel>
public class ImageManager : IDisposable
{
/// <summary>
/// Gets the image size cache.
@@ -57,20 +57,32 @@ namespace MediaBrowser.Controller.Drawing
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// The _protobuf serializer
/// </summary>
private readonly IProtobufSerializer _protobufSerializer;
/// <summary>
/// The _kernel
/// </summary>
private readonly Kernel _kernel;
/// <summary>
/// Initializes a new instance of the <see cref="ImageManager" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="protobufSerializer">The protobuf serializer.</param>
/// <param name="logger">The logger.</param>
public ImageManager(Kernel kernel, ILogger logger)
: base(kernel)
public ImageManager(Kernel kernel, IProtobufSerializer protobufSerializer, ILogger logger)
{
_protobufSerializer = protobufSerializer;
_logger = logger;
_kernel = kernel;
ImageSizeCache = new FileSystemRepository(Path.Combine(Kernel.ApplicationPaths.ImageCachePath, "image-sizes"));
ResizedImageCache = new FileSystemRepository(Path.Combine(Kernel.ApplicationPaths.ImageCachePath, "resized-images"));
CroppedImageCache = new FileSystemRepository(Path.Combine(Kernel.ApplicationPaths.ImageCachePath, "cropped-images"));
EnhancedImageCache = new FileSystemRepository(Path.Combine(Kernel.ApplicationPaths.ImageCachePath, "enhanced-images"));
ImageSizeCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "image-sizes"));
ResizedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "resized-images"));
CroppedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "cropped-images"));
EnhancedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "enhanced-images"));
}
/// <summary>
@@ -276,7 +288,7 @@ namespace MediaBrowser.Controller.Drawing
try
{
var result = Kernel.ProtobufSerializer.DeserializeFromFile<int[]>(fullCachePath);
var result = _protobufSerializer.DeserializeFromFile<int[]>(fullCachePath);
return new ImageSize { Width = result[0], Height = result[1] };
}
@@ -305,7 +317,7 @@ namespace MediaBrowser.Controller.Drawing
{
var output = new[] { width, height };
Kernel.ProtobufSerializer.SerializeToFile(output, cachePath);
_protobufSerializer.SerializeToFile(output, cachePath);
}
/// <summary>
@@ -472,7 +484,7 @@ namespace MediaBrowser.Controller.Drawing
throw new ArgumentNullException("item");
}
var supportedEnhancers = Kernel.ImageEnhancers.Where(i => i.Supports(item, imageType)).ToList();
var supportedEnhancers = _kernel.ImageEnhancers.Where(i => i.Supports(item, imageType)).ToList();
// No enhancement - don't cache
if (supportedEnhancers.Count == 0)
@@ -526,7 +538,7 @@ namespace MediaBrowser.Controller.Drawing
var dateModified = GetImageDateModified(item, imagePath);
var supportedEnhancers = Kernel.ImageEnhancers.Where(i => i.Supports(item, imageType));
var supportedEnhancers = _kernel.ImageEnhancers.Where(i => i.Supports(item, imageType));
return GetImageCacheTag(imagePath, dateModified, supportedEnhancers, item, imageType);
}
@@ -600,11 +612,16 @@ namespace MediaBrowser.Controller.Drawing
return result;
}
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool dispose)
protected void Dispose(bool dispose)
{
if (dispose)
{
@@ -613,8 +630,6 @@ namespace MediaBrowser.Controller.Drawing
CroppedImageCache.Dispose();
EnhancedImageCache.Dispose();
}
base.Dispose(dispose);
}
}
}

View File

@@ -1,15 +1,13 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Tasks;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Entities
{
@@ -170,7 +168,7 @@ namespace MediaBrowser.Controller.Entities
get
{
// Lazy load
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => XmlSerializer.GetXmlConfiguration<UserConfiguration>(ConfigurationFilePath, Logger));
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => (UserConfiguration)Kernel.Instance.GetXmlConfiguration(typeof(UserConfiguration), ConfigurationFilePath));
return _configuration;
}
private set
@@ -338,9 +336,9 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// Saves the current configuration to the file system
/// </summary>
public void SaveConfiguration()
public void SaveConfiguration(IXmlSerializer serializer)
{
XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath);
serializer.SerializeToFile(Configuration, ConfigurationFilePath);
}
/// <summary>
@@ -376,8 +374,9 @@ namespace MediaBrowser.Controller.Entities
/// Updates the configuration.
/// </summary>
/// <param name="config">The config.</param>
/// <param name="serializer">The serializer.</param>
/// <exception cref="System.ArgumentNullException">config</exception>
public void UpdateConfiguration(UserConfiguration config)
public void UpdateConfiguration(UserConfiguration config, IXmlSerializer serializer)
{
if (config == null)
{
@@ -387,7 +386,7 @@ namespace MediaBrowser.Controller.Entities
var customLibraryChanged = config.UseCustomLibrary != Configuration.UseCustomLibrary;
Configuration = config;
SaveConfiguration();
SaveConfiguration(serializer);
// Force these to be lazy loaded again
if (customLibraryChanged)

View File

@@ -0,0 +1,85 @@
using MediaBrowser.Common.Kernel;
namespace MediaBrowser.Controller
{
public interface IServerApplicationPaths : IApplicationPaths
{
/// <summary>
/// Gets the path to the base root media directory
/// </summary>
/// <value>The root folder path.</value>
string RootFolderPath { get; }
/// <summary>
/// Gets the path to the default user view directory. Used if no specific user view is defined.
/// </summary>
/// <value>The default user views path.</value>
string DefaultUserViewsPath { get; }
/// <summary>
/// Gets the path to localization data.
/// </summary>
/// <value>The localization path.</value>
string LocalizationPath { get; }
/// <summary>
/// Gets the path to the Images By Name directory
/// </summary>
/// <value>The images by name path.</value>
string ImagesByNamePath { get; }
/// <summary>
/// Gets the path to the People directory
/// </summary>
/// <value>The people path.</value>
string PeoplePath { get; }
/// <summary>
/// Gets the path to the Genre directory
/// </summary>
/// <value>The genre path.</value>
string GenrePath { get; }
/// <summary>
/// Gets the path to the Studio directory
/// </summary>
/// <value>The studio path.</value>
string StudioPath { get; }
/// <summary>
/// Gets the path to the Year directory
/// </summary>
/// <value>The year path.</value>
string YearPath { get; }
/// <summary>
/// Gets the path to the General IBN directory
/// </summary>
/// <value>The general path.</value>
string GeneralPath { get; }
/// <summary>
/// Gets the path to the Ratings IBN directory
/// </summary>
/// <value>The ratings path.</value>
string RatingsPath { get; }
/// <summary>
/// Gets the path to the user configuration directory
/// </summary>
/// <value>The user configuration directory path.</value>
string UserConfigurationDirectoryPath { get; }
/// <summary>
/// Gets the FF MPEG stream cache path.
/// </summary>
/// <value>The FF MPEG stream cache path.</value>
string FFMpegStreamCachePath { get; }
/// <summary>
/// Gets the folder path to tools
/// </summary>
/// <value>The media tools path.</value>
string MediaToolsPath { get; }
}
}

View File

@@ -1,5 +1,6 @@
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
@@ -16,6 +17,7 @@ using MediaBrowser.Controller.Updates;
using MediaBrowser.Controller.Weather;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using System;
using System.Collections.Generic;
@@ -28,7 +30,7 @@ namespace MediaBrowser.Controller
/// <summary>
/// Class Kernel
/// </summary>
public class Kernel : BaseKernel<ServerConfiguration, ServerApplicationPaths>
public class Kernel : BaseKernel<ServerConfiguration, IServerApplicationPaths>
{
/// <summary>
/// The MB admin URL
@@ -291,17 +293,24 @@ namespace MediaBrowser.Controller
get { return 7359; }
}
private readonly ITaskManager _taskManager;
/// <summary>
/// Creates a kernel based on a Data path, which is akin to our current programdata path
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="appPaths">The app paths.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
/// <param name="taskManager">The task manager.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">isoManager</exception>
public Kernel(IApplicationHost appHost, ILogger logger)
: base(appHost, logger)
public Kernel(IApplicationHost appHost, IServerApplicationPaths appPaths, IXmlSerializer xmlSerializer, ITaskManager taskManager, ILogger logger)
: base(appHost, appPaths, xmlSerializer, logger)
{
Instance = this;
_taskManager = taskManager;
// For now there's no real way to inject this properly
BaseItem.Logger = logger;
Ratings.Logger = logger;
@@ -310,21 +319,10 @@ namespace MediaBrowser.Controller
BaseMetadataProvider.Logger = logger;
}
/// <summary>
/// Composes the exported values.
/// </summary>
protected override void RegisterExportedValues()
{
ApplicationHost.RegisterSingleInstance(this);
base.RegisterExportedValues();
}
/// <summary>
/// Composes the parts with ioc container.
/// </summary>
/// <param name="allTypes">All types.</param>
protected override void FindParts(Type[] allTypes)
protected override void FindParts()
{
InstallationManager = (InstallationManager)ApplicationHost.CreateInstance(typeof(InstallationManager));
FFMpegManager = (FFMpegManager)ApplicationHost.CreateInstance(typeof(FFMpegManager));
@@ -335,21 +333,21 @@ namespace MediaBrowser.Controller
UserDataManager = (UserDataManager)ApplicationHost.CreateInstance(typeof(UserDataManager));
PluginSecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager));
base.FindParts(allTypes);
base.FindParts();
EntityResolutionIgnoreRules = GetExports<IResolutionIgnoreRule>(allTypes);
UserDataRepositories = GetExports<IUserDataRepository>(allTypes);
UserRepositories = GetExports<IUserRepository>(allTypes);
DisplayPreferencesRepositories = GetExports<IDisplayPreferencesRepository>(allTypes);
ItemRepositories = GetExports<IItemRepository>(allTypes);
WeatherProviders = GetExports<IWeatherProvider>(allTypes);
IntroProviders = GetExports<IIntroProvider>(allTypes);
PluginConfigurationPages = GetExports<IPluginConfigurationPage>(allTypes);
ImageEnhancers = GetExports<IImageEnhancer>(allTypes).OrderBy(e => e.Priority).ToArray();
PluginFolderCreators = GetExports<IVirtualFolderCreator>(allTypes);
StringFiles = GetExports<LocalizedStringData>(allTypes);
EntityResolvers = GetExports<IBaseItemResolver>(allTypes).OrderBy(e => e.Priority).ToArray();
MetadataProviders = GetExports<BaseMetadataProvider>(allTypes).OrderBy(e => e.Priority).ToArray();
EntityResolutionIgnoreRules = ApplicationHost.GetExports<IResolutionIgnoreRule>();
UserDataRepositories = ApplicationHost.GetExports<IUserDataRepository>();
UserRepositories = ApplicationHost.GetExports<IUserRepository>();
DisplayPreferencesRepositories = ApplicationHost.GetExports<IDisplayPreferencesRepository>();
ItemRepositories = ApplicationHost.GetExports<IItemRepository>();
WeatherProviders = ApplicationHost.GetExports<IWeatherProvider>();
IntroProviders = ApplicationHost.GetExports<IIntroProvider>();
PluginConfigurationPages = ApplicationHost.GetExports<IPluginConfigurationPage>();
ImageEnhancers = ApplicationHost.GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray();
PluginFolderCreators = ApplicationHost.GetExports<IVirtualFolderCreator>();
StringFiles = ApplicationHost.GetExports<LocalizedStringData>();
EntityResolvers = ApplicationHost.GetExports<IBaseItemResolver>().OrderBy(e => e.Priority).ToArray();
MetadataProviders = ApplicationHost.GetExports<BaseMetadataProvider>().OrderBy(e => e.Priority).ToArray();
}
/// <summary>
@@ -471,7 +469,7 @@ namespace MediaBrowser.Controller
{
DisposeFileSystemManager();
FileSystemManager = new FileSystemManager(this, Logger, TaskManager);
FileSystemManager = new FileSystemManager(this, Logger, _taskManager);
FileSystemManager.StartWatchers();
}
@@ -570,11 +568,11 @@ namespace MediaBrowser.Controller
ProviderManager.ValidateCurrentlyRunningProviders();
// Any number of configuration settings could change the way the library is refreshed, so do that now
TaskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
_taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
if (refreshPeopleAfterUpdate)
{
TaskManager.CancelIfRunningAndQueue<PeopleValidationTask>();
_taskManager.CancelIfRunningAndQueue<PeopleValidationTask>();
}
});
}

View File

@@ -110,6 +110,7 @@
<Compile Include="IO\FileSystem.cs" />
<Compile Include="IO\FileSystemManager.cs" />
<Compile Include="IO\NativeMethods.cs" />
<Compile Include="IServerApplicationPaths.cs" />
<Compile Include="Library\ChildrenChangedEventArgs.cs" />
<Compile Include="Library\DtoBuilder.cs" />
<Compile Include="Library\Profiler.cs" />
@@ -183,7 +184,6 @@
<Compile Include="ScheduledTasks\PeopleValidationTask.cs" />
<Compile Include="ScheduledTasks\PluginUpdateTask.cs" />
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" />
<Compile Include="ServerApplicationPaths.cs" />
<Compile Include="Library\ItemResolveArgs.cs" />
<Compile Include="IO\DirectoryWatchers.cs" />
<Compile Include="IO\FileData.cs" />

View File

@@ -1,12 +1,10 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -23,7 +21,7 @@ namespace MediaBrowser.Controller.MediaInfo
/// <summary>
/// Class FFMpegManager
/// </summary>
public class FFMpegManager : BaseManager<Kernel>
public class FFMpegManager : IDisposable
{
/// <summary>
/// Gets or sets the video image cache.
@@ -47,30 +45,66 @@ namespace MediaBrowser.Controller.MediaInfo
/// Gets or sets the zip client.
/// </summary>
/// <value>The zip client.</value>
private IZipClient ZipClient { get; set; }
private readonly IZipClient _zipClient;
/// <summary>
/// The _logger
/// </summary>
private readonly Kernel _kernel;
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Gets the json serializer.
/// </summary>
/// <value>The json serializer.</value>
private readonly IJsonSerializer _jsonSerializer;
/// <summary>
/// The _protobuf serializer
/// </summary>
private readonly IProtobufSerializer _protobufSerializer;
/// <summary>
/// Initializes a new instance of the <see cref="FFMpegManager" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="zipClient">The zip client.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="protobufSerializer">The protobuf serializer.</param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">zipClient</exception>
public FFMpegManager(Kernel kernel, IZipClient zipClient, ILogger logger)
: base(kernel)
public FFMpegManager(Kernel kernel, IZipClient zipClient, IJsonSerializer jsonSerializer, IProtobufSerializer protobufSerializer, ILogger logger)
{
if (kernel == null)
{
throw new ArgumentNullException("kernel");
}
if (zipClient == null)
{
throw new ArgumentNullException("zipClient");
}
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
if (protobufSerializer == null)
{
throw new ArgumentNullException("protobufSerializer");
}
if (logger == null)
{
throw new ArgumentNullException("logger");
}
_kernel = kernel;
_zipClient = zipClient;
_jsonSerializer = jsonSerializer;
_protobufSerializer = protobufSerializer;
_logger = logger;
ZipClient = zipClient;
// Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
@@ -82,11 +116,16 @@ namespace MediaBrowser.Controller.MediaInfo
Task.Run(() => VersionedDirectoryPath = GetVersionedDirectoryPath());
}
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool dispose)
protected void Dispose(bool dispose)
{
if (dispose)
{
@@ -95,8 +134,6 @@ namespace MediaBrowser.Controller.MediaInfo
AudioImageCache.Dispose();
VideoImageCache.Dispose();
}
base.Dispose(dispose);
}
/// <summary>
@@ -186,7 +223,7 @@ namespace MediaBrowser.Controller.MediaInfo
{
if (_videoImagesDataPath == null)
{
_videoImagesDataPath = Path.Combine(Kernel.ApplicationPaths.DataPath, "ffmpeg-video-images");
_videoImagesDataPath = Path.Combine(_kernel.ApplicationPaths.DataPath, "ffmpeg-video-images");
if (!Directory.Exists(_videoImagesDataPath))
{
@@ -212,7 +249,7 @@ namespace MediaBrowser.Controller.MediaInfo
{
if (_audioImagesDataPath == null)
{
_audioImagesDataPath = Path.Combine(Kernel.ApplicationPaths.DataPath, "ffmpeg-audio-images");
_audioImagesDataPath = Path.Combine(_kernel.ApplicationPaths.DataPath, "ffmpeg-audio-images");
if (!Directory.Exists(_audioImagesDataPath))
{
@@ -238,7 +275,7 @@ namespace MediaBrowser.Controller.MediaInfo
{
if (_subtitleCachePath == null)
{
_subtitleCachePath = Path.Combine(Kernel.ApplicationPaths.CachePath, "ffmpeg-subtitles");
_subtitleCachePath = Path.Combine(_kernel.ApplicationPaths.CachePath, "ffmpeg-subtitles");
if (!Directory.Exists(_subtitleCachePath))
{
@@ -265,7 +302,7 @@ namespace MediaBrowser.Controller.MediaInfo
var filename = resource.Substring(resource.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) + prefix.Length);
var versionedDirectoryPath = Path.Combine(Kernel.ApplicationPaths.MediaToolsPath, Path.GetFileNameWithoutExtension(filename));
var versionedDirectoryPath = Path.Combine(_kernel.ApplicationPaths.MediaToolsPath, Path.GetFileNameWithoutExtension(filename));
if (!Directory.Exists(versionedDirectoryPath))
{
@@ -287,7 +324,7 @@ namespace MediaBrowser.Controller.MediaInfo
{
using (var resourceStream = assembly.GetManifestResourceStream(zipFileResourcePath))
{
ZipClient.ExtractAll(resourceStream, targetPath, false);
_zipClient.ExtractAll(resourceStream, targetPath, false);
}
}
@@ -353,7 +390,7 @@ namespace MediaBrowser.Controller.MediaInfo
// Avoid File.Exists by just trying to deserialize
try
{
return Task.FromResult(Kernel.ProtobufSerializer.DeserializeFromFile<FFProbeResult>(cacheFilePath));
return Task.FromResult(_protobufSerializer.DeserializeFromFile<FFProbeResult>(cacheFilePath));
}
catch (FileNotFoundException)
{
@@ -428,7 +465,7 @@ namespace MediaBrowser.Controller.MediaInfo
process.BeginErrorReadLine();
}
result = JsonSerializer.DeserializeFromStream<FFProbeResult>(process.StandardOutput.BaseStream);
result = _jsonSerializer.DeserializeFromStream<FFProbeResult>(process.StandardOutput.BaseStream);
if (extractChapters)
{
@@ -470,7 +507,7 @@ namespace MediaBrowser.Controller.MediaInfo
AddChapters(result, standardError);
}
Kernel.ProtobufSerializer.SerializeToFile(result, cacheFile);
_protobufSerializer.SerializeToFile(result, cacheFile);
return result;
}
@@ -595,7 +632,7 @@ namespace MediaBrowser.Controller.MediaInfo
if (saveItem && changesMade)
{
await Kernel.ItemRepository.SaveItem(video, CancellationToken.None).ConfigureAwait(false);
await _kernel.ItemRepository.SaveItem(video, CancellationToken.None).ConfigureAwait(false);
}
}

View File

@@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.MediaInfo;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
@@ -28,29 +29,44 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// Gets or sets the bluray examiner.
/// </summary>
/// <value>The bluray examiner.</value>
private IBlurayExaminer BlurayExaminer { get; set; }
private readonly IBlurayExaminer _blurayExaminer;
/// <summary>
/// <summary>
/// The _iso manager
/// </summary>
private readonly IIsoManager _isoManager;
/// <summary>
/// The _protobuf serializer
/// </summary>
private readonly IProtobufSerializer _protobufSerializer;
/// <summary>
/// Initializes a new instance of the <see cref="FFProbeVideoInfoProvider" /> class.
/// </summary>
/// <param name="isoManager">The iso manager.</param>
/// <param name="blurayExaminer">The bluray examiner.</param>
/// <param name="protobufSerializer">The protobuf serializer.</param>
/// <exception cref="System.ArgumentNullException">blurayExaminer</exception>
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer)
public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IProtobufSerializer protobufSerializer)
: base()
{
if (isoManager == null)
{
throw new ArgumentNullException("isoManager");
}
if (blurayExaminer == null)
{
throw new ArgumentNullException("blurayExaminer");
}
if (protobufSerializer == null)
{
throw new ArgumentNullException("protobufSerializer");
}
BlurayExaminer = blurayExaminer;
_blurayExaminer = blurayExaminer;
_isoManager = isoManager;
_protobufSerializer = protobufSerializer;
BdInfoCache = new FileSystemRepository(Path.Combine(Kernel.Instance.ApplicationPaths.CachePath, "bdinfo"));
}
@@ -315,13 +331,13 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
try
{
result = Kernel.Instance.ProtobufSerializer.DeserializeFromFile<BlurayDiscInfo>(cacheFile);
result = _protobufSerializer.DeserializeFromFile<BlurayDiscInfo>(cacheFile);
}
catch (FileNotFoundException)
{
result = GetBDInfo(inputPath);
Kernel.Instance.ProtobufSerializer.SerializeToFile(result, cacheFile);
_protobufSerializer.SerializeToFile(result, cacheFile);
}
cancellationToken.ThrowIfCancellationRequested();
@@ -400,7 +416,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <returns>VideoStream.</returns>
private BlurayDiscInfo GetBDInfo(string path)
{
return BlurayExaminer.GetDiscInfo(path);
return _blurayExaminer.GetDiscInfo(path);
}
/// <summary>

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Entities;
@@ -15,6 +14,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Providers.Movies
{
@@ -30,6 +30,27 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
public class MovieDbProvider : BaseMetadataProvider
{
/// <summary>
/// Gets the json serializer.
/// </summary>
/// <value>The json serializer.</value>
protected IJsonSerializer JsonSerializer { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
/// </summary>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
public MovieDbProvider(IJsonSerializer jsonSerializer)
: base()
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
JsonSerializer = jsonSerializer;
}
/// <summary>
/// Gets the priority.
/// </summary>
@@ -93,7 +114,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
get
{
LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, GetTmdbSettings);
LazyInitializer.EnsureInitialized(ref _tmdbSettingsTask, ref _tmdbSettingsTaskInitialized, ref _tmdbSettingsTaskSyncLock, () => GetTmdbSettings(JsonSerializer));
return _tmdbSettingsTask;
}
}
@@ -102,13 +123,13 @@ namespace MediaBrowser.Controller.Providers.Movies
/// Gets the TMDB settings.
/// </summary>
/// <returns>Task{TmdbSettingsResult}.</returns>
private static async Task<TmdbSettingsResult> GetTmdbSettings()
private static async Task<TmdbSettingsResult> GetTmdbSettings(IJsonSerializer jsonSerializer)
{
try
{
using (var json = await Kernel.Instance.HttpManager.Get(String.Format(TmdbConfigUrl, ApiKey), Kernel.Instance.ResourcePools.MovieDb, CancellationToken.None).ConfigureAwait(false))
{
return JsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
return jsonSerializer.DeserializeFromStream<TmdbSettingsResult>(json);
}
}
catch (HttpException e)
@@ -168,7 +189,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
//in addition to ours, we need to set the last refreshed time for the local data provider
//so it won't see the new files we download and process them all over again
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson();
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(JsonSerializer);
var data = item.ProviderData.GetValueOrDefault(JsonProvider.Id, new BaseProviderInfo { ProviderId = JsonProvider.Id });
data.LastRefreshed = value;
item.ProviderData[JsonProvider.Id] = data;

View File

@@ -1,5 +1,5 @@
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Threading;
@@ -12,6 +12,10 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
public class MovieProviderFromJson : MovieDbProvider
{
public MovieProviderFromJson(IJsonSerializer jsonSerializer) : base(jsonSerializer)
{
}
/// <summary>
/// Gets the priority.
/// </summary>

View File

@@ -1,5 +1,5 @@
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Threading;
@@ -12,6 +12,10 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
class PersonProviderFromJson : TmdbPersonProvider
{
public PersonProviderFromJson(IJsonSerializer jsonSerializer) : base(jsonSerializer)
{
}
/// <summary>
/// Supportses the specified item.
/// </summary>

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Serialization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Net;
using System;
@@ -10,6 +9,7 @@ using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Controller.Providers.Movies
{
@@ -23,6 +23,27 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
protected const string MetaFileName = "MBPerson.json";
/// <summary>
/// Gets the json serializer.
/// </summary>
/// <value>The json serializer.</value>
protected IJsonSerializer JsonSerializer { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="MovieDbProvider" /> class.
/// </summary>
/// <param name="jsonSerializer">The json serializer.</param>
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
public TmdbPersonProvider(IJsonSerializer jsonSerializer)
: base()
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
JsonSerializer = jsonSerializer;
}
/// <summary>
/// Supportses the specified item.
/// </summary>
@@ -56,7 +77,7 @@ namespace MediaBrowser.Controller.Providers.Movies
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var person = (Person)item;
var tasks = new List<Task>();
@@ -169,7 +190,7 @@ namespace MediaBrowser.Controller.Providers.Movies
}
cancellationToken.ThrowIfCancellationRequested();
if (searchResult != null && searchResult.Biography != null)
{
ProcessInfo(person, searchResult);

View File

@@ -28,9 +28,9 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new BaseTaskTrigger[]
return new ITaskTrigger[]
{
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(4) }
};

View File

@@ -20,7 +20,8 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Initializes a new instance of the <see cref="ImageCleanupTask" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="logger"></param>
/// <param name="taskManager">The task manager.</param>
/// <param name="logger">The logger.</param>
public ImageCleanupTask(Kernel kernel, ITaskManager taskManager, ILogger logger)
: base(kernel, taskManager, logger)
{
@@ -30,9 +31,9 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new BaseTaskTrigger[]
return new ITaskTrigger[]
{
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(2) }
};

View File

@@ -26,9 +26,9 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new BaseTaskTrigger[]
return new ITaskTrigger[]
{
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(2) },

View File

@@ -29,9 +29,9 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new BaseTaskTrigger[] {
return new ITaskTrigger[] {
// 1:30am
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(1.5) },

View File

@@ -27,9 +27,9 @@ namespace MediaBrowser.Controller.ScheduledTasks
/// Gets the default triggers.
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers()
public override IEnumerable<ITaskTrigger> GetDefaultTriggers()
{
return new BaseTaskTrigger[] {
return new ITaskTrigger[] {
new StartupTrigger(),

View File

@@ -1,334 +0,0 @@
using MediaBrowser.Common.Kernel;
using System.IO;
namespace MediaBrowser.Controller
{
/// <summary>
/// Extends BaseApplicationPaths to add paths that are only applicable on the server
/// </summary>
public class ServerApplicationPaths : BaseApplicationPaths
{
/// <summary>
/// The _root folder path
/// </summary>
private string _rootFolderPath;
/// <summary>
/// Gets the path to the base root media directory
/// </summary>
/// <value>The root folder path.</value>
public string RootFolderPath
{
get
{
if (_rootFolderPath == null)
{
_rootFolderPath = Path.Combine(ProgramDataPath, "Root");
if (!Directory.Exists(_rootFolderPath))
{
Directory.CreateDirectory(_rootFolderPath);
}
}
return _rootFolderPath;
}
}
/// <summary>
/// The _default user views path
/// </summary>
private string _defaultUserViewsPath;
/// <summary>
/// Gets the path to the default user view directory. Used if no specific user view is defined.
/// </summary>
/// <value>The default user views path.</value>
public string DefaultUserViewsPath
{
get
{
if (_defaultUserViewsPath == null)
{
_defaultUserViewsPath = Path.Combine(RootFolderPath, "Default");
if (!Directory.Exists(_defaultUserViewsPath))
{
Directory.CreateDirectory(_defaultUserViewsPath);
}
}
return _defaultUserViewsPath;
}
}
/// <summary>
/// The _localization path
/// </summary>
private string _localizationPath;
/// <summary>
/// Gets the path to localization data.
/// </summary>
/// <value>The localization path.</value>
public string LocalizationPath
{
get
{
if (_localizationPath == null)
{
_localizationPath = Path.Combine(ProgramDataPath, "Localization");
if (!Directory.Exists(_localizationPath))
{
Directory.CreateDirectory(_localizationPath);
}
}
return _localizationPath;
}
}
/// <summary>
/// The _ibn path
/// </summary>
private string _ibnPath;
/// <summary>
/// Gets the path to the Images By Name directory
/// </summary>
/// <value>The images by name path.</value>
public string ImagesByNamePath
{
get
{
if (_ibnPath == null)
{
_ibnPath = Path.Combine(ProgramDataPath, "ImagesByName");
if (!Directory.Exists(_ibnPath))
{
Directory.CreateDirectory(_ibnPath);
}
}
return _ibnPath;
}
}
/// <summary>
/// The _people path
/// </summary>
private string _peoplePath;
/// <summary>
/// Gets the path to the People directory
/// </summary>
/// <value>The people path.</value>
public string PeoplePath
{
get
{
if (_peoplePath == null)
{
_peoplePath = Path.Combine(ImagesByNamePath, "People");
if (!Directory.Exists(_peoplePath))
{
Directory.CreateDirectory(_peoplePath);
}
}
return _peoplePath;
}
}
/// <summary>
/// The _genre path
/// </summary>
private string _genrePath;
/// <summary>
/// Gets the path to the Genre directory
/// </summary>
/// <value>The genre path.</value>
public string GenrePath
{
get
{
if (_genrePath == null)
{
_genrePath = Path.Combine(ImagesByNamePath, "Genre");
if (!Directory.Exists(_genrePath))
{
Directory.CreateDirectory(_genrePath);
}
}
return _genrePath;
}
}
/// <summary>
/// The _studio path
/// </summary>
private string _studioPath;
/// <summary>
/// Gets the path to the Studio directory
/// </summary>
/// <value>The studio path.</value>
public string StudioPath
{
get
{
if (_studioPath == null)
{
_studioPath = Path.Combine(ImagesByNamePath, "Studio");
if (!Directory.Exists(_studioPath))
{
Directory.CreateDirectory(_studioPath);
}
}
return _studioPath;
}
}
/// <summary>
/// The _year path
/// </summary>
private string _yearPath;
/// <summary>
/// Gets the path to the Year directory
/// </summary>
/// <value>The year path.</value>
public string YearPath
{
get
{
if (_yearPath == null)
{
_yearPath = Path.Combine(ImagesByNamePath, "Year");
if (!Directory.Exists(_yearPath))
{
Directory.CreateDirectory(_yearPath);
}
}
return _yearPath;
}
}
/// <summary>
/// The _general path
/// </summary>
private string _generalPath;
/// <summary>
/// Gets the path to the General IBN directory
/// </summary>
/// <value>The general path.</value>
public string GeneralPath
{
get
{
if (_generalPath == null)
{
_generalPath = Path.Combine(ImagesByNamePath, "General");
if (!Directory.Exists(_generalPath))
{
Directory.CreateDirectory(_generalPath);
}
}
return _generalPath;
}
}
/// <summary>
/// The _ratings path
/// </summary>
private string _ratingsPath;
/// <summary>
/// Gets the path to the Ratings IBN directory
/// </summary>
/// <value>The ratings path.</value>
public string RatingsPath
{
get
{
if (_ratingsPath == null)
{
_ratingsPath = Path.Combine(ImagesByNamePath, "Ratings");
if (!Directory.Exists(_ratingsPath))
{
Directory.CreateDirectory(_ratingsPath);
}
}
return _ratingsPath;
}
}
/// <summary>
/// The _user configuration directory path
/// </summary>
private string _userConfigurationDirectoryPath;
/// <summary>
/// Gets the path to the user configuration directory
/// </summary>
/// <value>The user configuration directory path.</value>
public string UserConfigurationDirectoryPath
{
get
{
if (_userConfigurationDirectoryPath == null)
{
_userConfigurationDirectoryPath = Path.Combine(ConfigurationDirectoryPath, "users");
if (!Directory.Exists(_userConfigurationDirectoryPath))
{
Directory.CreateDirectory(_userConfigurationDirectoryPath);
}
}
return _userConfigurationDirectoryPath;
}
}
/// <summary>
/// The _f F MPEG stream cache path
/// </summary>
private string _fFMpegStreamCachePath;
/// <summary>
/// Gets the FF MPEG stream cache path.
/// </summary>
/// <value>The FF MPEG stream cache path.</value>
public string FFMpegStreamCachePath
{
get
{
if (_fFMpegStreamCachePath == null)
{
_fFMpegStreamCachePath = Path.Combine(CachePath, "ffmpeg-streams");
if (!Directory.Exists(_fFMpegStreamCachePath))
{
Directory.CreateDirectory(_fFMpegStreamCachePath);
}
}
return _fFMpegStreamCachePath;
}
}
/// <summary>
/// The _media tools path
/// </summary>
private string _mediaToolsPath;
/// <summary>
/// Gets the folder path to tools
/// </summary>
/// <value>The media tools path.</value>
public string MediaToolsPath
{
get
{
if (_mediaToolsPath == null)
{
_mediaToolsPath = Path.Combine(ProgramDataPath, "MediaTools");
if (!Directory.Exists(_mediaToolsPath))
{
Directory.CreateDirectory(_mediaToolsPath);
}
}
return _mediaToolsPath;
}
}
}
}

View File

@@ -1,18 +1,17 @@
using System.Security.Cryptography;
using MediaBrowser.Common.Events;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Events;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Updates;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
@@ -32,8 +31,8 @@ namespace MediaBrowser.Controller.Updates
/// <summary>
/// The completed installations
/// </summary>
public readonly ConcurrentBag<InstallationInfo> CompletedInstallations = new ConcurrentBag<InstallationInfo>();
public readonly ConcurrentBag<InstallationInfo> CompletedInstallations = new ConcurrentBag<InstallationInfo>();
#region PluginUninstalled Event
/// <summary>
/// Occurs when [plugin uninstalled].
@@ -68,7 +67,7 @@ namespace MediaBrowser.Controller.Updates
_logger.Info("Plugin updated: {0} {1} {2}", newVersion.name, newVersion.version, newVersion.classification);
EventHelper.QueueEventIfNotNull(PluginUpdated, this, new GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> { Argument = new Tuple<IPlugin, PackageVersionInfo>(plugin, newVersion) }, _logger);
Kernel.NotifyPendingRestart();
}
#endregion
@@ -108,15 +107,22 @@ namespace MediaBrowser.Controller.Updates
/// </summary>
private readonly INetworkManager _networkManager;
/// <summary>
/// Gets the json serializer.
/// </summary>
/// <value>The json serializer.</value>
protected IJsonSerializer JsonSerializer { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="InstallationManager" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="zipClient">The zip client.</param>
/// <param name="networkManager">The network manager.</param>
/// <param name="jsonSerializer"></param>
/// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">zipClient</exception>
public InstallationManager(Kernel kernel, IZipClient zipClient, INetworkManager networkManager, ILogger logger)
public InstallationManager(Kernel kernel, IZipClient zipClient, INetworkManager networkManager, IJsonSerializer jsonSerializer, ILogger logger)
: base(kernel)
{
if (zipClient == null)
@@ -131,6 +137,12 @@ namespace MediaBrowser.Controller.Updates
{
throw new ArgumentNullException("logger");
}
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
JsonSerializer = jsonSerializer;
_networkManager = networkManager;
_logger = logger;
@@ -161,7 +173,7 @@ namespace MediaBrowser.Controller.Updates
package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl))
.OrderByDescending(v => v.version).ToList();
}
if (packageType.HasValue)
{
packages = packages.Where(p => p.type == packageType.Value).ToList();
@@ -178,7 +190,7 @@ namespace MediaBrowser.Controller.Updates
// Remove packages with no versions
packages = packages.Where(p => p.versions.Any()).ToList();
return packages;
}
}
@@ -320,7 +332,7 @@ namespace MediaBrowser.Controller.Updates
var innerCancellationTokenSource = new CancellationTokenSource();
var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource);
// Add it to the in-progress list
lock (CurrentInstallations)
{
@@ -364,7 +376,7 @@ namespace MediaBrowser.Controller.Updates
_logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr);
Kernel.TcpManager.SendWebSocketMessage("PackageInstallationCancelled", installationInfo);
throw;
}
catch
@@ -373,7 +385,7 @@ namespace MediaBrowser.Controller.Updates
{
CurrentInstallations.Remove(tuple);
}
Kernel.TcpManager.SendWebSocketMessage("PackageInstallationFailed", installationInfo);
throw;
@@ -421,7 +433,7 @@ namespace MediaBrowser.Controller.Updates
}
cancellationToken.ThrowIfCancellationRequested();
// Success - move it to the real target based on type
if (isArchive)
{
@@ -435,7 +447,7 @@ namespace MediaBrowser.Controller.Updates
throw;
}
}
}
else
{
try
@@ -448,8 +460,8 @@ namespace MediaBrowser.Controller.Updates
_logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target);
throw;
}
}
}
// Set last update time if we were installed before
var plugin = Kernel.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase));