extracted provider manager. took more off the kernel

This commit is contained in:
LukePulverenti
2013-03-08 00:08:27 -05:00
parent 211d24e66e
commit 9911df11e8
54 changed files with 756 additions and 636 deletions

View File

@@ -96,9 +96,10 @@ namespace MediaBrowser.Controller.Entities
/// <summary>
/// The logger
/// </summary>
protected static internal ILogger Logger { get; internal set; }
protected static internal ILibraryManager LibraryManager { get; internal set; }
protected static internal IServerConfigurationManager ConfigurationManager { get; internal set; }
public static ILogger Logger { get; set; }
public static ILibraryManager LibraryManager { get; set; }
public static IServerConfigurationManager ConfigurationManager { get; set; }
public static IProviderManager ProviderManager { get; set; }
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
@@ -652,7 +653,7 @@ namespace MediaBrowser.Controller.Entities
LocalTrailers = null;
// Refresh for the item
var itemRefreshTask = Kernel.Instance.ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
cancellationToken.ThrowIfCancellationRequested();

View File

@@ -18,8 +18,8 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class User : BaseItem
{
internal static IUserManager UserManager { get; set; }
internal static IXmlSerializer XmlSerializer { get; set; }
public static IUserManager UserManager { get; set; }
public static IXmlSerializer XmlSerializer { get; set; }
/// <summary>
/// The _root folder path
@@ -363,7 +363,7 @@ namespace MediaBrowser.Controller.Entities
ResolveArgs = null;
}
var changed = await Kernel.Instance.ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders).ConfigureAwait(false);
var changed = await ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders).ConfigureAwait(false);
if (changed || forceSave)
{

View File

@@ -1,542 +0,0 @@
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.ScheduledTasks;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.IO
{
/// <summary>
/// Class DirectoryWatchers
/// </summary>
public class DirectoryWatchers : IDisposable
{
/// <summary>
/// The file system watchers
/// </summary>
private ConcurrentBag<FileSystemWatcher> FileSystemWatchers = new ConcurrentBag<FileSystemWatcher>();
/// <summary>
/// The update timer
/// </summary>
private Timer updateTimer;
/// <summary>
/// The affected paths
/// </summary>
private readonly ConcurrentDictionary<string, string> affectedPaths = new ConcurrentDictionary<string, string>();
/// <summary>
/// A dynamic list of paths that should be ignored. Added to during our own file sytem modifications.
/// </summary>
private readonly ConcurrentDictionary<string,string> TempIgnoredPaths = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// The timer lock
/// </summary>
private readonly object timerLock = new object();
/// <summary>
/// Add the path to our temporary ignore list. Use when writing to a path within our listening scope.
/// </summary>
/// <param name="path">The path.</param>
public void TemporarilyIgnore(string path)
{
TempIgnoredPaths[path] = path;
}
/// <summary>
/// Removes the temp ignore.
/// </summary>
/// <param name="path">The path.</param>
public void RemoveTempIgnore(string path)
{
string val;
TempIgnoredPaths.TryRemove(path, out val);
}
/// <summary>
/// Gets or sets the logger.
/// </summary>
/// <value>The logger.</value>
private ILogger Logger { get; set; }
/// <summary>
/// Gets or sets the task manager.
/// </summary>
/// <value>The task manager.</value>
private ITaskManager TaskManager { get; set; }
private ILibraryManager LibraryManager { get; set; }
private IServerConfigurationManager ConfigurationManager { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="DirectoryWatchers" /> class.
/// </summary>
public DirectoryWatchers(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager)
{
if (taskManager == null)
{
throw new ArgumentNullException("taskManager");
}
LibraryManager = libraryManager;
TaskManager = taskManager;
Logger = logManager.GetLogger("DirectoryWatchers");
ConfigurationManager = configurationManager;
}
/// <summary>
/// Starts this instance.
/// </summary>
internal void Start()
{
LibraryManager.LibraryChanged += Instance_LibraryChanged;
var pathsToWatch = new List<string> { LibraryManager.RootFolder.Path };
var paths = LibraryManager.RootFolder.Children.OfType<Folder>()
.SelectMany(f =>
{
try
{
// Accessing ResolveArgs could involve file system access
return f.ResolveArgs.PhysicalLocations;
}
catch (IOException)
{
return new string[] {};
}
})
.Where(Path.IsPathRooted);
foreach (var path in paths)
{
if (!ContainsParentFolder(pathsToWatch, path))
{
pathsToWatch.Add(path);
}
}
foreach (var path in pathsToWatch)
{
StartWatchingPath(path);
}
}
/// <summary>
/// Examine a list of strings assumed to be file paths to see if it contains a parent of
/// the provided path.
/// </summary>
/// <param name="lst">The LST.</param>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [contains parent folder] [the specified LST]; otherwise, <c>false</c>.</returns>
/// <exception cref="System.ArgumentNullException">path</exception>
private static bool ContainsParentFolder(IEnumerable<string> lst, string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}
path = path.TrimEnd(Path.DirectorySeparatorChar);
return lst.Any(str =>
{
//this should be a little quicker than examining each actual parent folder...
var compare = str.TrimEnd(Path.DirectorySeparatorChar);
return (path.Equals(compare, StringComparison.OrdinalIgnoreCase) || (path.StartsWith(compare, StringComparison.OrdinalIgnoreCase) && path[compare.Length] == Path.DirectorySeparatorChar));
});
}
/// <summary>
/// Starts the watching path.
/// </summary>
/// <param name="path">The path.</param>
private void StartWatchingPath(string path)
{
// Creating a FileSystemWatcher over the LAN can take hundreds of milliseconds, so wrap it in a Task to do them all in parallel
Task.Run(() =>
{
var newWatcher = new FileSystemWatcher(path, "*") { IncludeSubdirectories = true, InternalBufferSize = 32767 };
newWatcher.Created += watcher_Changed;
newWatcher.Deleted += watcher_Changed;
newWatcher.Renamed += watcher_Changed;
newWatcher.Changed += watcher_Changed;
newWatcher.Error += watcher_Error;
try
{
newWatcher.EnableRaisingEvents = true;
FileSystemWatchers.Add(newWatcher);
Logger.Info("Watching directory " + path);
}
catch (IOException ex)
{
Logger.ErrorException("Error watching path: {0}", ex, path);
}
catch (PlatformNotSupportedException ex)
{
Logger.ErrorException("Error watching path: {0}", ex, path);
}
});
}
/// <summary>
/// Stops the watching path.
/// </summary>
/// <param name="path">The path.</param>
private void StopWatchingPath(string path)
{
var watcher = FileSystemWatchers.FirstOrDefault(f => f.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
if (watcher != null)
{
DisposeWatcher(watcher);
}
}
/// <summary>
/// Disposes the watcher.
/// </summary>
/// <param name="watcher">The watcher.</param>
private void DisposeWatcher(FileSystemWatcher watcher)
{
Logger.Info("Stopping directory watching for path {0}", watcher.Path);
watcher.EnableRaisingEvents = false;
watcher.Dispose();
var watchers = FileSystemWatchers.ToList();
watchers.Remove(watcher);
FileSystemWatchers = new ConcurrentBag<FileSystemWatcher>(watchers);
}
/// <summary>
/// Handles the LibraryChanged event of the Kernel
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Library.ChildrenChangedEventArgs" /> instance containing the event data.</param>
void Instance_LibraryChanged(object sender, ChildrenChangedEventArgs e)
{
if (e.Folder is AggregateFolder && e.HasAddOrRemoveChange)
{
if (e.ItemsRemoved != null)
{
foreach (var item in e.ItemsRemoved.OfType<Folder>())
{
StopWatchingPath(item.Path);
}
}
if (e.ItemsAdded != null)
{
foreach (var item in e.ItemsAdded.OfType<Folder>())
{
StartWatchingPath(item.Path);
}
}
}
}
/// <summary>
/// Handles the Error event of the watcher control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ErrorEventArgs" /> instance containing the event data.</param>
async void watcher_Error(object sender, ErrorEventArgs e)
{
var ex = e.GetException();
var dw = (FileSystemWatcher) sender;
Logger.ErrorException("Error in Directory watcher for: "+dw.Path, ex);
if (ex.Message.Contains("network name is no longer available"))
{
//Network either dropped or, we are coming out of sleep and it hasn't reconnected yet - wait and retry
Logger.Warn("Network connection lost - will retry...");
var retries = 0;
var success = false;
while (!success && retries < 10)
{
await Task.Delay(500).ConfigureAwait(false);
try
{
dw.EnableRaisingEvents = false;
dw.EnableRaisingEvents = true;
success = true;
}
catch (IOException)
{
Logger.Warn("Network still unavailable...");
retries++;
}
}
if (!success)
{
Logger.Warn("Unable to access network. Giving up.");
DisposeWatcher(dw);
}
}
else
{
if (!ex.Message.Contains("BIOS command limit"))
{
Logger.Info("Attempting to re-start watcher.");
dw.EnableRaisingEvents = false;
dw.EnableRaisingEvents = true;
}
}
}
/// <summary>
/// Handles the Changed event of the watcher control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="FileSystemEventArgs" /> instance containing the event data.</param>
void watcher_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created && e.Name == "New folder")
{
return;
}
if (TempIgnoredPaths.ContainsKey(e.FullPath))
{
Logger.Info("Watcher requested to ignore change to " + e.FullPath);
return;
}
Logger.Info("Watcher sees change of type " + e.ChangeType.ToString() + " to " + e.FullPath);
//Since we're watching created, deleted and renamed we always want the parent of the item to be the affected path
var affectedPath = e.FullPath;
affectedPaths.AddOrUpdate(affectedPath, affectedPath, (key, oldValue) => affectedPath);
lock (timerLock)
{
if (updateTimer == null)
{
updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1));
}
else
{
updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1));
}
}
}
/// <summary>
/// Timers the stopped.
/// </summary>
/// <param name="stateInfo">The state info.</param>
private async void TimerStopped(object stateInfo)
{
lock (timerLock)
{
// Extend the timer as long as any of the paths are still being written to.
if (affectedPaths.Any(p => IsFileLocked(p.Key)))
{
Logger.Info("Timer extended.");
updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1));
return;
}
Logger.Info("Timer stopped.");
updateTimer.Dispose();
updateTimer = null;
}
var paths = affectedPaths.Keys.ToList();
affectedPaths.Clear();
await ProcessPathChanges(paths).ConfigureAwait(false);
}
/// <summary>
/// Try and determine if a file is locked
/// This is not perfect, and is subject to race conditions, so I'd rather not make this a re-usable library method.
/// </summary>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is file locked] [the specified path]; otherwise, <c>false</c>.</returns>
private bool IsFileLocked(string path)
{
try
{
var data = FileSystem.GetFileData(path);
if (!data.HasValue || data.Value.IsDirectory)
{
return false;
}
}
catch (IOException)
{
return false;
}
FileStream stream = null;
try
{
stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
}
catch
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
/// <summary>
/// Processes the path changes.
/// </summary>
/// <param name="paths">The paths.</param>
/// <returns>Task.</returns>
private async Task ProcessPathChanges(List<string> paths)
{
var itemsToRefresh = paths.Select(Path.GetDirectoryName)
.Select(GetAffectedBaseItem)
.Where(item => item != null)
.Distinct()
.ToList();
foreach (var p in paths) Logger.Info(p + " reports change.");
// If the root folder changed, run the library task so the user can see it
if (itemsToRefresh.Any(i => i is AggregateFolder))
{
TaskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
return;
}
await Task.WhenAll(itemsToRefresh.Select(i => Task.Run(async () =>
{
Logger.Info(i.Name + " (" + i.Path + ") will be refreshed.");
try
{
await i.ChangedExternally().ConfigureAwait(false);
}
catch (IOException ex)
{
// For now swallow and log.
// Research item: If an IOException occurs, the item may be in a disconnected state (media unavailable)
// Should we remove it from it's parent?
Logger.ErrorException("Error refreshing {0}", ex, i.Name);
}
}))).ConfigureAwait(false);
}
/// <summary>
/// Gets the affected base item.
/// </summary>
/// <param name="path">The path.</param>
/// <returns>BaseItem.</returns>
private BaseItem GetAffectedBaseItem(string path)
{
BaseItem item = null;
while (item == null && !string.IsNullOrEmpty(path))
{
item = LibraryManager.RootFolder.FindByPath(path);
path = Path.GetDirectoryName(path);
}
if (item != null)
{
// If the item has been deleted find the first valid parent that still exists
while (!Directory.Exists(item.Path) && !File.Exists(item.Path))
{
item = item.Parent;
if (item == null)
{
break;
}
}
}
return item;
}
/// <summary>
/// Stops this instance.
/// </summary>
private void Stop()
{
LibraryManager.LibraryChanged -= Instance_LibraryChanged;
FileSystemWatcher watcher;
while (FileSystemWatchers.TryTake(out watcher))
{
watcher.Changed -= watcher_Changed;
watcher.EnableRaisingEvents = false;
watcher.Dispose();
}
lock (timerLock)
{
if (updateTimer != null)
{
updateTimer.Dispose();
updateTimer = null;
}
}
affectedPaths.Clear();
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <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 virtual void Dispose(bool dispose)
{
if (dispose)
{
Stop();
}
}
}
}

View File

@@ -1,120 +0,0 @@
using MediaBrowser.Common.IO;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.IO
{
/// <summary>
/// This class will manage our file system watching and modifications. Any process that needs to
/// modify the directories that the system is watching for changes should use the methods of
/// this class to do so. This way we can have the watchers correctly respond to only external changes.
/// </summary>
public class FileSystemManager : IDisposable
{
/// <summary>
/// Gets or sets the directory watchers.
/// </summary>
/// <value>The directory watchers.</value>
private DirectoryWatchers DirectoryWatchers { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemManager" /> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
/// <param name="taskManager">The task manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
public FileSystemManager(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager)
{
DirectoryWatchers = new DirectoryWatchers(logManager, taskManager, libraryManager, configurationManager);
}
/// <summary>
/// Start the directory watchers on our library folders
/// </summary>
public void StartWatchers()
{
DirectoryWatchers.Start();
}
/// <summary>
/// Saves to library filesystem.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="path">The path.</param>
/// <param name="dataToSave">The data to save.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task SaveToLibraryFilesystem(BaseItem item, string path, Stream dataToSave, CancellationToken cancellationToken)
{
if (item == null)
{
throw new ArgumentNullException();
}
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException();
}
if (dataToSave == null)
{
throw new ArgumentNullException();
}
if (cancellationToken == null)
{
throw new ArgumentNullException();
}
cancellationToken.ThrowIfCancellationRequested();
//Tell the watchers to ignore
DirectoryWatchers.TemporarilyIgnore(path);
//Make the mod
dataToSave.Position = 0;
try
{
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
{
await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
dataToSave.Dispose();
// If this is ever used for something other than metadata we can add a file type param
item.ResolveArgs.AddMetadataFile(path);
}
}
finally
{
//Remove the ignore
DirectoryWatchers.RemoveTempIgnore(path);
}
}
/// <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 virtual void Dispose(bool dispose)
{
if (dispose)
{
DirectoryWatchers.Dispose();
}
}
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
namespace MediaBrowser.Controller.IO
{
public interface IDirectoryWatchers : IDisposable
{
/// <summary>
/// Add the path to our temporary ignore list. Use when writing to a path within our listening scope.
/// </summary>
/// <param name="path">The path.</param>
void TemporarilyIgnore(string path);
/// <summary>
/// Removes the temp ignore.
/// </summary>
/// <param name="path">The path.</param>
void RemoveTempIgnore(string path);
/// <summary>
/// Starts this instance.
/// </summary>
void Start();
/// <summary>
/// Stops this instance.
/// </summary>
void Stop();
}
}

View File

@@ -74,12 +74,18 @@ namespace MediaBrowser.Controller
/// Gets the FF MPEG stream cache path.
/// </summary>
/// <value>The FF MPEG stream cache path.</value>
string FFMpegStreamCachePath { get; }
string EncodedMediaCachePath { get; }
/// <summary>
/// Gets the folder path to tools
/// </summary>
/// <value>The media tools path.</value>
string MediaToolsPath { get; }
/// <summary>
/// Gets the downloaded images data path.
/// </summary>
/// <value>The downloaded images data path.</value>
string DownloadedImagesDataPath { get; }
}
}

View File

@@ -1,22 +1,13 @@
using MediaBrowser.Common;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.MediaInfo;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Weather;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller
@@ -24,7 +15,7 @@ namespace MediaBrowser.Controller
/// <summary>
/// Class Kernel
/// </summary>
public class Kernel : IDisposable
public class Kernel
{
/// <summary>
/// Gets the instance.
@@ -36,25 +27,13 @@ namespace MediaBrowser.Controller
/// Gets the image manager.
/// </summary>
/// <value>The image manager.</value>
public ImageManager ImageManager { get; private set; }
public ImageManager ImageManager { get; set; }
/// <summary>
/// Gets the FFMPEG controller.
/// </summary>
/// <value>The FFMPEG controller.</value>
public FFMpegManager FFMpegManager { get; private set; }
/// <summary>
/// Gets or sets the file system manager.
/// </summary>
/// <value>The file system manager.</value>
public FileSystemManager FileSystemManager { get; private set; }
/// <summary>
/// Gets the provider manager.
/// </summary>
/// <value>The provider manager.</value>
public ProviderManager ProviderManager { get; private set; }
public FFMpegManager FFMpegManager { get; set; }
/// <summary>
/// Gets the name of the web application that can be used for url building.
@@ -82,74 +61,68 @@ namespace MediaBrowser.Controller
/// Gets the list of Localized string files
/// </summary>
/// <value>The string files.</value>
public IEnumerable<LocalizedStringData> StringFiles { get; private set; }
public IEnumerable<LocalizedStringData> StringFiles { get; set; }
/// <summary>
/// Gets the list of currently registered weather prvoiders
/// </summary>
/// <value>The weather providers.</value>
public IEnumerable<IWeatherProvider> WeatherProviders { get; private set; }
/// <summary>
/// Gets the list of currently registered metadata prvoiders
/// </summary>
/// <value>The metadata providers enumerable.</value>
public BaseMetadataProvider[] MetadataProviders { get; private set; }
public IEnumerable<IWeatherProvider> WeatherProviders { get; set; }
/// <summary>
/// Gets the list of currently registered image processors
/// Image processors are specialized metadata providers that run after the normal ones
/// </summary>
/// <value>The image enhancers.</value>
public IEnumerable<IImageEnhancer> ImageEnhancers { get; private set; }
public IEnumerable<IImageEnhancer> ImageEnhancers { get; set; }
/// <summary>
/// Gets the list of available user repositories
/// </summary>
/// <value>The user repositories.</value>
private IEnumerable<IUserRepository> UserRepositories { get; set; }
public IEnumerable<IUserRepository> UserRepositories { get; set; }
/// <summary>
/// Gets the active user repository
/// </summary>
/// <value>The user repository.</value>
public IUserRepository UserRepository { get; private set; }
public IUserRepository UserRepository { get; set; }
/// <summary>
/// Gets the active user repository
/// </summary>
/// <value>The display preferences repository.</value>
public IDisplayPreferencesRepository DisplayPreferencesRepository { get; private set; }
public IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
/// <summary>
/// Gets the list of available item repositories
/// </summary>
/// <value>The item repositories.</value>
private IEnumerable<IItemRepository> ItemRepositories { get; set; }
public IEnumerable<IItemRepository> ItemRepositories { get; set; }
/// <summary>
/// Gets the active item repository
/// </summary>
/// <value>The item repository.</value>
public IItemRepository ItemRepository { get; private set; }
public IItemRepository ItemRepository { get; set; }
/// <summary>
/// Gets the list of available DisplayPreferencesRepositories
/// </summary>
/// <value>The display preferences repositories.</value>
private IEnumerable<IDisplayPreferencesRepository> DisplayPreferencesRepositories { get; set; }
public IEnumerable<IDisplayPreferencesRepository> DisplayPreferencesRepositories { get; set; }
/// <summary>
/// Gets the list of available item repositories
/// </summary>
/// <value>The user data repositories.</value>
private IEnumerable<IUserDataRepository> UserDataRepositories { get; set; }
public IEnumerable<IUserDataRepository> UserDataRepositories { get; set; }
/// <summary>
/// Gets the active user data repository
/// </summary>
/// <value>The user data repository.</value>
public IUserDataRepository UserDataRepository { get; private set; }
public IUserDataRepository UserDataRepository { get; set; }
/// <summary>
/// Gets the UDP server port number.
@@ -160,121 +133,39 @@ namespace MediaBrowser.Controller
get { return 7359; }
}
private readonly IXmlSerializer _xmlSerializer;
private readonly IServerConfigurationManager _configurationManager;
private readonly ILogManager _logManager;
private IApplicationHost ApplicationHost { get; set; }
/// <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="xmlSerializer">The XML serializer.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <exception cref="System.ArgumentNullException">isoManager</exception>
public Kernel(IApplicationHost appHost, IXmlSerializer xmlSerializer, ILogManager logManager, IServerConfigurationManager configurationManager)
public Kernel(IServerConfigurationManager configurationManager)
{
Instance = this;
ApplicationHost = appHost;
_configurationManager = configurationManager;
_xmlSerializer = xmlSerializer;
_logManager = logManager;
// For now there's no real way to inject these properly
BaseItem.Logger = logManager.GetLogger("BaseItem");
User.XmlSerializer = _xmlSerializer;
Ratings.ConfigurationManager = _configurationManager;
LocalizedStrings.ApplicationPaths = _configurationManager.ApplicationPaths;
BaseItem.ConfigurationManager = configurationManager;
}
/// <summary>
/// Composes the parts with ioc container.
/// </summary>
protected void FindParts()
{
// For now there's no real way to inject these properly
BaseItem.LibraryManager = ApplicationHost.Resolve<ILibraryManager>();
User.UserManager = ApplicationHost.Resolve<IUserManager>();
FFMpegManager = (FFMpegManager)ApplicationHost.CreateInstance(typeof(FFMpegManager));
ImageManager = (ImageManager)ApplicationHost.CreateInstance(typeof(ImageManager));
ProviderManager = (ProviderManager)ApplicationHost.CreateInstance(typeof(ProviderManager));
UserDataRepositories = ApplicationHost.GetExports<IUserDataRepository>();
UserRepositories = ApplicationHost.GetExports<IUserRepository>();
DisplayPreferencesRepositories = ApplicationHost.GetExports<IDisplayPreferencesRepository>();
ItemRepositories = ApplicationHost.GetExports<IItemRepository>();
WeatherProviders = ApplicationHost.GetExports<IWeatherProvider>();
ImageEnhancers = ApplicationHost.GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray();
StringFiles = ApplicationHost.GetExports<LocalizedStringData>();
MetadataProviders = ApplicationHost.GetExports<BaseMetadataProvider>().OrderBy(e => e.Priority).ToArray();
}
/// <summary>
/// Performs initializations that can be reloaded at anytime
/// </summary>
/// <returns>Task.</returns>
public async Task Init()
{
FindParts();
await LoadRepositories().ConfigureAwait(false);
await ApplicationHost.Resolve<IUserManager>().RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false);
foreach (var entryPoint in ApplicationHost.GetExports<IServerEntryPoint>())
{
entryPoint.Run();
}
ReloadFileSystemManager();
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <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 virtual void Dispose(bool dispose)
{
if (dispose)
{
DisposeFileSystemManager();
}
}
/// <summary>
/// Called when [composable parts loaded].
/// </summary>
/// <returns>Task.</returns>
protected Task LoadRepositories()
public Task LoadRepositories(IServerConfigurationManager configurationManager)
{
// Get the current item repository
ItemRepository = GetRepository(ItemRepositories, _configurationManager.Configuration.ItemRepository);
ItemRepository = GetRepository(ItemRepositories, configurationManager.Configuration.ItemRepository);
var itemRepoTask = ItemRepository.Initialize();
// Get the current user repository
UserRepository = GetRepository(UserRepositories, _configurationManager.Configuration.UserRepository);
UserRepository = GetRepository(UserRepositories, configurationManager.Configuration.UserRepository);
var userRepoTask = UserRepository.Initialize();
// Get the current item repository
UserDataRepository = GetRepository(UserDataRepositories, _configurationManager.Configuration.UserDataRepository);
UserDataRepository = GetRepository(UserDataRepositories, configurationManager.Configuration.UserDataRepository);
var userDataRepoTask = UserDataRepository.Initialize();
// Get the current display preferences repository
DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, _configurationManager.Configuration.DisplayPreferencesRepository);
DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, configurationManager.Configuration.DisplayPreferencesRepository);
var displayPreferencesRepoTask = DisplayPreferencesRepository.Initialize();
return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask);
@@ -295,28 +186,5 @@ namespace MediaBrowser.Controller
return enumerable.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) ??
enumerable.FirstOrDefault();
}
/// <summary>
/// Disposes the file system manager.
/// </summary>
private void DisposeFileSystemManager()
{
if (FileSystemManager != null)
{
FileSystemManager.Dispose();
FileSystemManager = null;
}
}
/// <summary>
/// Reloads the file system manager.
/// </summary>
private void ReloadFileSystemManager()
{
DisposeFileSystemManager();
FileSystemManager = new FileSystemManager(_logManager, ApplicationHost.Resolve<ITaskManager>(), ApplicationHost.Resolve<ILibraryManager>(), _configurationManager);
FileSystemManager.StartWatchers();
}
}
}

View File

@@ -15,7 +15,7 @@ namespace MediaBrowser.Controller.Localization
/// </summary>
public class LocalizedStrings
{
internal static IServerApplicationPaths ApplicationPaths;
public static IServerApplicationPaths ApplicationPaths;
/// <summary>
/// The base prefix

View File

@@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Localization
/// </summary>
public static class Ratings
{
internal static IServerConfigurationManager ConfigurationManager;
public static IServerConfigurationManager ConfigurationManager;
/// <summary>
/// The ratings def

View File

@@ -102,12 +102,14 @@
<Compile Include="Entities\Year.cs" />
<Compile Include="Extensions\XmlExtensions.cs" />
<Compile Include="IO\FileSystem.cs" />
<Compile Include="IO\FileSystemManager.cs" />
<Compile Include="IO\IDirectoryWatchers.cs" />
<Compile Include="IO\NativeMethods.cs" />
<Compile Include="IServerApplicationHost.cs" />
<Compile Include="IServerApplicationPaths.cs" />
<Compile Include="Library\ChildrenChangedEventArgs.cs" />
<Compile Include="Library\DtoBuilder.cs" />
<Compile Include="Providers\IProviderManager.cs" />
<Compile Include="Providers\MetadataProviderPriority.cs" />
<Compile Include="Providers\Music\LastfmAlbumProvider.cs" />
<Compile Include="Providers\Music\FanArtAlbumProvider.cs" />
<Compile Include="Providers\Music\FanArtArtistProvider.cs" />
@@ -154,7 +156,6 @@
<Compile Include="Providers\Movies\MovieProviderFromXml.cs" />
<Compile Include="Providers\Movies\PersonProviderFromJson.cs" />
<Compile Include="Providers\Movies\TmdbPersonProvider.cs" />
<Compile Include="Providers\ProviderManager.cs" />
<Compile Include="Providers\SortNameProvider.cs" />
<Compile Include="Providers\TV\EpisodeImageFromMediaLocationProvider.cs" />
<Compile Include="Providers\TV\EpisodeProviderFromXml.cs" />
@@ -176,7 +177,6 @@
<Compile Include="Library\TVUtils.cs" />
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" />
<Compile Include="Library\ItemResolveArgs.cs" />
<Compile Include="IO\DirectoryWatchers.cs" />
<Compile Include="IO\FileData.cs" />
<Compile Include="Kernel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Logging;
@@ -12,7 +11,7 @@ namespace MediaBrowser.Controller.Providers
/// <summary>
/// Class BaseMetadataProvider
/// </summary>
public abstract class BaseMetadataProvider : IDisposable
public abstract class BaseMetadataProvider
{
/// <summary>
/// Gets the logger.
@@ -27,16 +26,6 @@ namespace MediaBrowser.Controller.Providers
/// <value>The configuration manager.</value>
protected IServerConfigurationManager ConfigurationManager { get; private set; }
// Cache these since they will be used a lot
/// <summary>
/// The false task result
/// </summary>
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// The _id
/// </summary>
@@ -135,7 +124,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="providerVersion">The provider version.</param>
/// <param name="status">The status.</param>
/// <exception cref="System.ArgumentNullException">item</exception>
protected virtual void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
public virtual void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
{
if (item == null)
{
@@ -162,7 +151,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="item">The item.</param>
/// <param name="value">The value.</param>
/// <param name="status">The status.</param>
protected virtual void SetLastRefreshed(BaseItem item, DateTime value, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
public void SetLastRefreshed(BaseItem item, DateTime value, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
{
SetLastRefreshed(item, value, ProviderVersion, status);
}
@@ -254,76 +243,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
if (item == null)
{
throw new ArgumentNullException();
}
cancellationToken.ThrowIfCancellationRequested();
Logger.Info("Running for {0}", item.Path ?? item.Name ?? "--Unknown--");
// This provides the ability to cancel just this one provider
var innerCancellationTokenSource = new CancellationTokenSource();
Kernel.Instance.ProviderManager.OnProviderRefreshBeginning(this, item, innerCancellationTokenSource);
try
{
var task = FetchAsyncInternal(item, force, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token);
await task.ConfigureAwait(false);
if (task.IsFaulted)
{
// Log the AggregateException
if (task.Exception != null)
{
Logger.ErrorException("AggregateException:", task.Exception);
}
return false;
}
return task.Result;
}
catch (OperationCanceledException ex)
{
Logger.Info("{0} cancelled for {1}", GetType().Name, item.Name);
// If the outer cancellation token is the one that caused the cancellation, throw it
if (cancellationToken.IsCancellationRequested && ex.CancellationToken == cancellationToken)
{
throw;
}
return false;
}
catch (Exception ex)
{
Logger.ErrorException("failed refreshing {0}", ex, item.Name);
SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.Failure);
return true;
}
finally
{
innerCancellationTokenSource.Dispose();
Kernel.Instance.ProviderManager.OnProviderRefreshCompleted(this, item);
}
}
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
/// <param name="item">The item.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected abstract Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken);
public abstract Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken);
/// <summary>
/// Gets the priority.
@@ -331,23 +251,6 @@ namespace MediaBrowser.Controller.Providers
/// <value>The priority.</value>
public abstract MetadataProviderPriority Priority { get; }
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <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 virtual void Dispose(bool dispose)
{
}
/// <summary>
/// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
/// </summary>
@@ -386,34 +289,4 @@ namespace MediaBrowser.Controller.Providers
return item.FileSystemStamp;
}
}
/// <summary>
/// Determines when a provider should execute, relative to others
/// </summary>
public enum MetadataProviderPriority
{
// Run this provider at the beginning
/// <summary>
/// The first
/// </summary>
First = 1,
// Run this provider after all first priority providers
/// <summary>
/// The second
/// </summary>
Second = 2,
// Run this provider after all second priority providers
/// <summary>
/// The third
/// </summary>
Third = 3,
// Run this provider last
/// <summary>
/// The last
/// </summary>
Last = 4
}
}

View File

@@ -56,7 +56,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() => Fetch(item, cancellationToken));
}

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers
{
public interface IProviderManager : IDisposable
{
/// <summary>
/// Downloads the and save image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="source">The source.</param>
/// <param name="targetName">Name of the target.</param>
/// <param name="resourcePool">The resource pool.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.String}.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
Task<string> DownloadAndSaveImage(BaseItem item, string source, string targetName, SemaphoreSlim resourcePool, CancellationToken cancellationToken);
/// <summary>
/// Saves to library filesystem.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="path">The path.</param>
/// <param name="dataToSave">The data to save.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
Task SaveToLibraryFilesystem(BaseItem item, string path, Stream dataToSave, CancellationToken cancellationToken);
/// <summary>
/// Executes the metadata providers.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
/// <returns>Task{System.Boolean}.</returns>
Task<bool> ExecuteMetadataProviders(BaseItem item, CancellationToken cancellationToken, bool force = false, bool allowSlowProviders = true);
/// <summary>
/// Adds the metadata providers.
/// </summary>
/// <param name="providers">The providers.</param>
void AddMetadataProviders(IEnumerable<BaseMetadataProvider> providers);
}
}

View File

@@ -52,6 +52,11 @@ namespace MediaBrowser.Controller.Providers
}
}
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
@@ -59,7 +64,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

View File

@@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// Provides a base class for extracting media information through ffprobe
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class BaseFFProbeProvider<T> : BaseFFMpegProvider<T>
public abstract class BaseFFProbeProvider<T> : BaseFFMpegProvider<T>, IDisposable
where T : BaseItem
{
protected BaseFFProbeProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
@@ -69,7 +69,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var myItem = (T)item;
@@ -351,14 +351,17 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// 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 virtual void Dispose(bool dispose)
{
if (dispose)
{
FFProbeCache.Dispose();
}
}
base.Dispose(dispose);
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -19,6 +19,11 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
{
}
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
@@ -26,7 +31,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var audio = (Audio)item;

View File

@@ -59,6 +59,11 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
return false;
}
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
@@ -66,7 +71,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(item.PrimaryImagePath))
{

View File

@@ -0,0 +1,33 @@

namespace MediaBrowser.Controller.Providers
{
/// <summary>
/// Determines when a provider should execute, relative to others
/// </summary>
public enum MetadataProviderPriority
{
// Run this provider at the beginning
/// <summary>
/// The first
/// </summary>
First = 1,
// Run this provider after all first priority providers
/// <summary>
/// The second
/// </summary>
Second = 2,
// Run this provider after all second priority providers
/// <summary>
/// The third
/// </summary>
Third = 3,
// Run this provider last
/// <summary>
/// The last
/// </summary>
Last = 4
}
}

View File

@@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <summary>
/// Class FanArtMovieProvider
/// </summary>
class FanArtMovieProvider : FanartBaseProvider
class FanArtMovieProvider : FanartBaseProvider, IDisposable
{
/// <summary>
/// The fan art
@@ -32,6 +32,8 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <value>The HTTP client.</value>
protected IHttpClient HttpClient { get; private set; }
private readonly IProviderManager _providerManager;
/// <summary>
/// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class.
/// </summary>
@@ -39,7 +41,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <exception cref="System.ArgumentNullException">httpClient</exception>
public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (httpClient == null)
@@ -47,19 +49,19 @@ namespace MediaBrowser.Controller.Providers.Movies
throw new ArgumentNullException("httpClient");
}
HttpClient = httpClient;
_providerManager = providerManager;
}
/// <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 virtual void Dispose(bool dispose)
{
if (dispose)
{
FanArtResourcePool.Dispose();
}
base.Dispose(dispose);
}
/// <summary>
@@ -103,7 +105,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -147,7 +149,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("FanArtProvider getting ClearLogo for " + movie.Name);
try
{
movie.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, LOGO_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(movie, path, LOGO_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -173,7 +175,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("FanArtProvider getting ClearArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, ART_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(movie, path, ART_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -196,7 +198,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("FanArtProvider getting DiscArt for " + movie.Name);
try
{
movie.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, DISC_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(movie, path, DISC_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -220,7 +222,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
movie.SetImage(ImageType.Banner, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, BANNER_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(movie, path, BANNER_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -244,7 +246,7 @@ namespace MediaBrowser.Controller.Providers.Movies
Logger.Debug("FanArtProvider getting Banner for " + movie.Name);
try
{
movie.SetImage(ImageType.Thumb, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, THUMB_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
movie.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(movie, path, THUMB_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -260,5 +262,10 @@ namespace MediaBrowser.Controller.Providers.Movies
SetLastRefreshed(movie, DateTime.UtcNow);
return true;
}
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -30,8 +30,10 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <summary>
/// Class MovieDbProvider
/// </summary>
public class MovieDbProvider : BaseMetadataProvider
public class MovieDbProvider : BaseMetadataProvider, IDisposable
{
protected readonly IProviderManager ProviderManager;
/// <summary>
/// The movie db
/// </summary>
@@ -58,11 +60,12 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="httpClient">The HTTP client.</param>
public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient)
public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IProviderManager providerManager)
: base(logManager, configurationManager)
{
JsonSerializer = jsonSerializer;
HttpClient = httpClient;
ProviderManager = providerManager;
Current = this;
}
@@ -70,13 +73,12 @@ namespace MediaBrowser.Controller.Providers.Movies
/// 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 virtual void Dispose(bool dispose)
{
if (dispose)
{
MovieDbResourcePool.Dispose();
}
base.Dispose(dispose);
}
/// <summary>
@@ -209,16 +211,17 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
/// <param name="item">The item.</param>
/// <param name="value">The value.</param>
/// <param name="providerVersion">The provider version.</param>
/// <param name="status">The status.</param>
protected override void SetLastRefreshed(BaseItem item, DateTime value, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
public override void SetLastRefreshed(BaseItem item, DateTime value, string providerVersion, ProviderRefreshStatus status = ProviderRefreshStatus.Success)
{
base.SetLastRefreshed(item, value, status);
base.SetLastRefreshed(item, value, providerVersion, status);
if (ConfigurationManager.Configuration.SaveLocalMeta)
{
//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(LogManager, ConfigurationManager, JsonSerializer, HttpClient);
if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(LogManager, ConfigurationManager, JsonSerializer, HttpClient, ProviderManager);
var data = item.ProviderData.GetValueOrDefault(JsonProvider.Id, new BaseProviderInfo { ProviderId = JsonProvider.Id });
data.LastRefreshed = value;
item.ProviderData[JsonProvider.Id] = data;
@@ -291,7 +294,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
if (HasAltMeta(item))
{
@@ -724,7 +727,7 @@ namespace MediaBrowser.Controller.Providers.Movies
cancellationToken.ThrowIfCancellationRequested();
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
await ProviderManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
}
}
@@ -1018,7 +1021,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
try
{
item.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
item.PrimaryImagePath = await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
}
catch (HttpException)
{
@@ -1050,7 +1053,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
try
{
item.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
item.BackdropImagePaths.Add(await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -1661,5 +1664,10 @@ namespace MediaBrowser.Controller.Providers.Movies
public TmdbImageSettings images { get; set; }
}
#endregion
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -15,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
public class MovieProviderFromJson : MovieDbProvider
{
public MovieProviderFromJson(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient) :
base(logManager, configurationManager, jsonSerializer, httpClient)
public MovieProviderFromJson(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient, IProviderManager providerManager)
: base(logManager, configurationManager, jsonSerializer, httpClient, providerManager)
{
}
@@ -79,7 +79,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
// Since we don't have anything truly async, and since deserializing can be expensive, create a task to force parallelism
return Task.Run(() =>

View File

@@ -56,7 +56,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() => Fetch(item, cancellationToken));
}

View File

@@ -15,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
class PersonProviderFromJson : TmdbPersonProvider
{
public PersonProviderFromJson(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager) :
base(httpClient, jsonSerializer, logManager, configurationManager)
public PersonProviderFromJson(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(httpClient, jsonSerializer, logManager, configurationManager, providerManager)
{
}
@@ -90,7 +90,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() =>
{

View File

@@ -26,7 +26,9 @@ namespace MediaBrowser.Controller.Providers.Movies
/// </summary>
protected const string MetaFileName = "MBPerson.json";
public TmdbPersonProvider(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager)
protected readonly IProviderManager ProviderManager;
public TmdbPersonProvider(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (jsonSerializer == null)
@@ -39,6 +41,7 @@ namespace MediaBrowser.Controller.Providers.Movies
}
HttpClient = httpClient;
JsonSerializer = jsonSerializer;
ProviderManager = providerManager;
}
/// <summary>
@@ -83,7 +86,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -209,7 +212,7 @@ namespace MediaBrowser.Controller.Providers.Movies
JsonSerializer.SerializeToStream(searchResult, memoryStream);
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(person, Path.Combine(person.MetaLocation, MetaFileName), memoryStream, cancellationToken);
await ProviderManager.SaveToLibraryFilesystem(person, Path.Combine(person.MetaLocation, MetaFileName), memoryStream, cancellationToken);
Logger.Debug("TmdbPersonProvider downloaded and saved information for {0}", person.Name);
}
@@ -288,7 +291,7 @@ namespace MediaBrowser.Controller.Providers.Movies
}
if (profile != null)
{
var tmdbSettings = await Kernel.Instance.MetadataProviders.OfType<MovieDbProvider>().First().TmdbSettings.ConfigureAwait(false);
var tmdbSettings = await MovieDbProvider.Current.TmdbSettings.ConfigureAwait(false);
var img = await DownloadAndSaveImage(person, tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedProfileSize + profile.File_Path,
"folder" + Path.GetExtension(profile.File_Path), cancellationToken).ConfigureAwait(false);
@@ -319,7 +322,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{
using (var sourceStream = await HttpClient.GetMemoryStream(source, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false))
{
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(item, localPath, sourceStream, cancellationToken).ConfigureAwait(false);
await ProviderManager.SaveToLibraryFilesystem(item, localPath, sourceStream, cancellationToken).ConfigureAwait(false);
Logger.Debug("TmdbPersonProvider downloaded and saved image for {0}", item.Name);
}

View File

@@ -15,8 +15,12 @@ namespace MediaBrowser.Controller.Providers.Music
{
public class FanArtAlbumProvider : FanartBaseProvider
{
public FanArtAlbumProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
private readonly IProviderManager _providerManager;
public FanArtAlbumProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
_providerManager = providerManager;
}
public override bool Supports(BaseItem item)
@@ -37,7 +41,7 @@ namespace MediaBrowser.Controller.Providers.Music
DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
}
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var mbid = item.GetProviderId(MetadataProviders.Musicbrainz);
if (mbid == null)
@@ -67,7 +71,7 @@ namespace MediaBrowser.Controller.Providers.Music
return false;
}
item.SetImage(ImageType.Primary, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, cover, "folder.jpg", FanArtResourcePool, cancellationToken).ConfigureAwait(false));
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, cover, "folder.jpg", FanArtResourcePool, cancellationToken).ConfigureAwait(false));
return true;
}
}

View File

@@ -28,7 +28,9 @@ namespace MediaBrowser.Controller.Providers.Music
/// <value>The HTTP client.</value>
protected IHttpClient HttpClient { get; private set; }
public FanArtArtistProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
private readonly IProviderManager _providerManager;
public FanArtArtistProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (httpClient == null)
@@ -36,6 +38,7 @@ namespace MediaBrowser.Controller.Providers.Music
throw new ArgumentNullException("httpClient");
}
HttpClient = httpClient;
_providerManager = providerManager;
}
/// <summary>
@@ -80,7 +83,7 @@ namespace MediaBrowser.Controller.Providers.Music
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -118,7 +121,7 @@ namespace MediaBrowser.Controller.Providers.Music
Logger.Debug("FanArtProvider getting ClearLogo for " + artist.Name);
try
{
artist.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, LOGO_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
artist.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(artist, path, LOGO_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -146,7 +149,7 @@ namespace MediaBrowser.Controller.Providers.Music
Logger.Debug("FanArtProvider getting Backdrop for " + artist.Name);
try
{
artist.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, ("Backdrop"+(numBackdrops > 0 ? numBackdrops.ToString() : "")+".jpg"), FanArtResourcePool, cancellationToken).ConfigureAwait(false));
artist.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(artist, path, ("Backdrop" + (numBackdrops > 0 ? numBackdrops.ToString() : "") + ".jpg"), FanArtResourcePool, cancellationToken).ConfigureAwait(false));
numBackdrops++;
if (numBackdrops >= ConfigurationManager.Configuration.MaxBackdrops) break;
}
@@ -203,7 +206,7 @@ namespace MediaBrowser.Controller.Providers.Music
Logger.Debug("FanArtProvider getting ClearArt for " + artist.Name);
try
{
artist.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, ART_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
artist.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(artist, path, ART_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -226,7 +229,7 @@ namespace MediaBrowser.Controller.Providers.Music
Logger.Debug("FanArtProvider getting Banner for " + artist.Name);
try
{
artist.SetImage(ImageType.Banner, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, BANNER_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
artist.SetImage(ImageType.Banner, await _providerManager.DownloadAndSaveImage(artist, path, BANNER_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -250,7 +253,7 @@ namespace MediaBrowser.Controller.Providers.Music
Logger.Debug("FanArtProvider getting Primary image for " + artist.Name);
try
{
artist.SetImage(ImageType.Primary, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(artist, path, PRIMARY_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
artist.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(artist, path, PRIMARY_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{

View File

@@ -16,9 +16,12 @@ namespace MediaBrowser.Controller.Providers.Music
{
private static readonly Task<string> BlankId = Task.FromResult("0000");
public LastfmAlbumProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
private readonly IProviderManager _providerManager;
public LastfmAlbumProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(jsonSerializer, httpClient, logManager, configurationManager)
{
_providerManager = providerManager;
LocalMetaFileName = LastfmHelper.LocalAlbumMetaFileName;
}
@@ -62,7 +65,7 @@ namespace MediaBrowser.Controller.Providers.Music
cancellationToken.ThrowIfCancellationRequested();
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LocalMetaFileName), ms, cancellationToken).ConfigureAwait(false);
await _providerManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LocalMetaFileName), ms, cancellationToken).ConfigureAwait(false);
}
}

View File

@@ -19,10 +19,12 @@ namespace MediaBrowser.Controller.Providers.Music
{
public class LastfmArtistProvider : LastfmBaseProvider
{
public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
private readonly IProviderManager _providerManager;
public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(jsonSerializer, httpClient, logManager, configurationManager)
{
_providerManager = providerManager;
LocalMetaFileName = LastfmHelper.LocalArtistMetaFileName;
}
@@ -91,7 +93,7 @@ namespace MediaBrowser.Controller.Providers.Music
cancellationToken.ThrowIfCancellationRequested();
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LocalMetaFileName), ms, cancellationToken).ConfigureAwait(false);
await _providerManager.SaveToLibraryFilesystem(item, Path.Combine(item.MetaLocation, LocalMetaFileName), ms, cancellationToken).ConfigureAwait(false);
}
}

View File

@@ -196,7 +196,7 @@ namespace MediaBrowser.Controller.Providers.Music
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
if (item.DontFetchMeta)
{

View File

@@ -34,7 +34,7 @@ namespace MediaBrowser.Controller.Providers.Music
}
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() =>
{

View File

@@ -1,372 +0,0 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers
{
/// <summary>
/// Class ProviderManager
/// </summary>
public class ProviderManager : IDisposable
{
/// <summary>
/// The remote image cache
/// </summary>
private readonly FileSystemRepository _remoteImageCache;
/// <summary>
/// The currently running metadata providers
/// </summary>
private readonly ConcurrentDictionary<string, Tuple<BaseMetadataProvider, BaseItem, CancellationTokenSource>> _currentlyRunningProviders =
new ConcurrentDictionary<string, Tuple<BaseMetadataProvider, BaseItem, CancellationTokenSource>>();
/// <summary>
/// The _logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// The _HTTP client
/// </summary>
private readonly IHttpClient _httpClient;
private IServerConfigurationManager ConfigurationManager { get; set; }
private Kernel Kernel { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ProviderManager" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="httpClient">The HTTP client.</param>
/// <param name="logger">The logger.</param>
public ProviderManager(Kernel kernel, IHttpClient httpClient, ILogger logger, IServerConfigurationManager configurationManager)
{
_logger = logger;
Kernel = kernel;
_httpClient = httpClient;
ConfigurationManager = configurationManager;
_remoteImageCache = new FileSystemRepository(ImagesDataPath);
configurationManager.ConfigurationUpdated += configurationManager_ConfigurationUpdated;
}
/// <summary>
/// Handles the ConfigurationUpdated event of the configurationManager control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
void configurationManager_ConfigurationUpdated(object sender, EventArgs e)
{
// Validate currently executing providers, in the background
Task.Run(() =>
{
ValidateCurrentlyRunningProviders();
});
}
/// <summary>
/// The _images data path
/// </summary>
private string _imagesDataPath;
/// <summary>
/// Gets the images data path.
/// </summary>
/// <value>The images data path.</value>
public string ImagesDataPath
{
get
{
if (_imagesDataPath == null)
{
_imagesDataPath = Path.Combine(ConfigurationManager.ApplicationPaths.DataPath, "remote-images");
if (!Directory.Exists(_imagesDataPath))
{
Directory.CreateDirectory(_imagesDataPath);
}
}
return _imagesDataPath;
}
}
/// <summary>
/// Gets or sets the supported providers key.
/// </summary>
/// <value>The supported providers key.</value>
private Guid SupportedProvidersKey { get; set; }
/// <summary>
/// Runs all metadata providers for an entity, and returns true or false indicating if at least one was refreshed and requires persistence
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
/// <returns>Task{System.Boolean}.</returns>
internal async Task<bool> ExecuteMetadataProviders(BaseItem item, CancellationToken cancellationToken, bool force = false, bool allowSlowProviders = true)
{
// Allow providers of the same priority to execute in parallel
MetadataProviderPriority? currentPriority = null;
var currentTasks = new List<Task<bool>>();
var result = false;
cancellationToken.ThrowIfCancellationRequested();
// Determine if supported providers have changed
var supportedProviders = Kernel.MetadataProviders.Where(p => p.Supports(item)).ToList();
BaseProviderInfo supportedProvidersInfo;
if (SupportedProvidersKey == Guid.Empty)
{
SupportedProvidersKey = "SupportedProviders".GetMD5();
}
var supportedProvidersHash = string.Join("+", supportedProviders.Select(i => i.GetType().Name)).GetMD5();
bool providersChanged;
item.ProviderData.TryGetValue(SupportedProvidersKey, out supportedProvidersInfo);
if (supportedProvidersInfo == null)
{
// First time
supportedProvidersInfo = new BaseProviderInfo { ProviderId = SupportedProvidersKey, FileSystemStamp = supportedProvidersHash };
providersChanged = force = true;
}
else
{
// Force refresh if the supported providers have changed
providersChanged = force = force || supportedProvidersInfo.FileSystemStamp != supportedProvidersHash;
}
// If providers have changed, clear provider info and update the supported providers hash
if (providersChanged)
{
_logger.Debug("Providers changed for {0}. Clearing and forcing refresh.", item.Name);
item.ProviderData.Clear();
supportedProvidersInfo.FileSystemStamp = supportedProvidersHash;
}
if (force) item.ClearMetaValues();
// Run the normal providers sequentially in order of priority
foreach (var provider in supportedProviders)
{
cancellationToken.ThrowIfCancellationRequested();
// Skip if internet providers are currently disabled
if (provider.RequiresInternet && !ConfigurationManager.Configuration.EnableInternetProviders)
{
continue;
}
// Skip if is slow and we aren't allowing slow ones
if (provider.IsSlow && !allowSlowProviders)
{
continue;
}
// Skip if internet provider and this type is not allowed
if (provider.RequiresInternet && ConfigurationManager.Configuration.EnableInternetProviders && ConfigurationManager.Configuration.InternetProviderExcludeTypes.Contains(item.GetType().Name, StringComparer.OrdinalIgnoreCase))
{
continue;
}
// When a new priority is reached, await the ones that are currently running and clear the list
if (currentPriority.HasValue && currentPriority.Value != provider.Priority && currentTasks.Count > 0)
{
var results = await Task.WhenAll(currentTasks).ConfigureAwait(false);
result |= results.Contains(true);
currentTasks.Clear();
}
// Put this check below the await because the needs refresh of the next tier of providers may depend on the previous ones running
// This is the case for the fan art provider which depends on the movie and tv providers having run before them
if (!force && !provider.NeedsRefresh(item))
{
continue;
}
currentTasks.Add(provider.FetchAsync(item, force, cancellationToken));
currentPriority = provider.Priority;
}
if (currentTasks.Count > 0)
{
var results = await Task.WhenAll(currentTasks).ConfigureAwait(false);
result |= results.Contains(true);
}
if (providersChanged)
{
item.ProviderData[SupportedProvidersKey] = supportedProvidersInfo;
}
return result || providersChanged;
}
/// <summary>
/// Notifies the kernal that a provider has begun refreshing
/// </summary>
/// <param name="provider">The provider.</param>
/// <param name="item">The item.</param>
/// <param name="cancellationTokenSource">The cancellation token source.</param>
internal void OnProviderRefreshBeginning(BaseMetadataProvider provider, BaseItem item, CancellationTokenSource cancellationTokenSource)
{
var key = item.Id + provider.GetType().Name;
Tuple<BaseMetadataProvider, BaseItem, CancellationTokenSource> current;
if (_currentlyRunningProviders.TryGetValue(key, out current))
{
try
{
current.Item3.Cancel();
}
catch (ObjectDisposedException)
{
}
}
var tuple = new Tuple<BaseMetadataProvider, BaseItem, CancellationTokenSource>(provider, item, cancellationTokenSource);
_currentlyRunningProviders.AddOrUpdate(key, tuple, (k, v) => tuple);
}
/// <summary>
/// Notifies the kernal that a provider has completed refreshing
/// </summary>
/// <param name="provider">The provider.</param>
/// <param name="item">The item.</param>
internal void OnProviderRefreshCompleted(BaseMetadataProvider provider, BaseItem item)
{
var key = item.Id + provider.GetType().Name;
Tuple<BaseMetadataProvider, BaseItem, CancellationTokenSource> current;
if (_currentlyRunningProviders.TryRemove(key, out current))
{
current.Item3.Dispose();
}
}
/// <summary>
/// Validates the currently running providers and cancels any that should not be run due to configuration changes
/// </summary>
internal void ValidateCurrentlyRunningProviders()
{
_logger.Info("Validing currently running providers");
var enableInternetProviders = ConfigurationManager.Configuration.EnableInternetProviders;
var internetProviderExcludeTypes = ConfigurationManager.Configuration.InternetProviderExcludeTypes;
foreach (var tuple in _currentlyRunningProviders.Values
.Where(p => p.Item1.RequiresInternet && (!enableInternetProviders || internetProviderExcludeTypes.Contains(p.Item2.GetType().Name, StringComparer.OrdinalIgnoreCase)))
.ToList())
{
tuple.Item3.Cancel();
}
}
/// <summary>
/// Downloads the and save image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="source">The source.</param>
/// <param name="targetName">Name of the target.</param>
/// <param name="resourcePool">The resource pool.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.String}.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
public async Task<string> DownloadAndSaveImage(BaseItem item, string source, string targetName, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
if (string.IsNullOrEmpty(source))
{
throw new ArgumentNullException("source");
}
if (string.IsNullOrEmpty(targetName))
{
throw new ArgumentNullException("targetName");
}
if (resourcePool == null)
{
throw new ArgumentNullException("resourcePool");
}
//download and save locally
var localPath = ConfigurationManager.Configuration.SaveLocalMeta ?
Path.Combine(item.MetaLocation, targetName) :
_remoteImageCache.GetResourcePath(item.GetType().FullName + item.Path.ToLower(), targetName);
var img = await _httpClient.GetMemoryStream(source, resourcePool, cancellationToken).ConfigureAwait(false);
if (ConfigurationManager.Configuration.SaveLocalMeta) // queue to media directories
{
await Kernel.FileSystemManager.SaveToLibraryFilesystem(item, localPath, img, cancellationToken).ConfigureAwait(false);
}
else
{
// we can write directly here because it won't affect the watchers
try
{
using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
{
await img.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception e)
{
_logger.ErrorException("Error downloading and saving image " + localPath, e);
throw;
}
finally
{
img.Dispose();
}
}
return localPath;
}
/// <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 virtual void Dispose(bool dispose)
{
if (dispose)
{
_remoteImageCache.Dispose();
}
}
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -49,6 +49,17 @@ namespace MediaBrowser.Controller.Providers
return !string.IsNullOrEmpty(item.Name) && string.IsNullOrEmpty(item.SortName);
}
// Cache these since they will be used a lot
/// <summary>
/// The false task result
/// </summary>
protected static readonly Task<bool> FalseTaskResult = Task.FromResult(false);
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
@@ -56,7 +67,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return SetSortName(item, cancellationToken) ? TrueTaskResult : FalseTaskResult;
}

View File

@@ -50,6 +50,11 @@ namespace MediaBrowser.Controller.Providers.TV
}
}
/// <summary>
/// The true task result
/// </summary>
protected static readonly Task<bool> TrueTaskResult = Task.FromResult(true);
/// <summary>
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
@@ -57,7 +62,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

View File

@@ -53,7 +53,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() => Fetch(item, cancellationToken));
}

View File

@@ -25,7 +25,9 @@ namespace MediaBrowser.Controller.Providers.TV
/// <value>The HTTP client.</value>
protected IHttpClient HttpClient { get; private set; }
public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
private readonly IProviderManager _providerManager;
public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (httpClient == null)
@@ -33,6 +35,7 @@ namespace MediaBrowser.Controller.Providers.TV
throw new ArgumentNullException("httpClient");
}
HttpClient = httpClient;
_providerManager = providerManager;
}
public override bool Supports(BaseItem item)
@@ -53,7 +56,7 @@ namespace MediaBrowser.Controller.Providers.TV
|| (!thumbExists && ConfigurationManager.Configuration.DownloadSeriesImages.Thumb);
}
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -90,7 +93,7 @@ namespace MediaBrowser.Controller.Providers.TV
Logger.Debug("FanArtProvider getting ClearLogo for " + series.Name);
try
{
series.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, LOGO_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Logo, await _providerManager.DownloadAndSaveImage(series, path, LOGO_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -114,7 +117,7 @@ namespace MediaBrowser.Controller.Providers.TV
Logger.Debug("FanArtProvider getting ClearArt for " + series.Name);
try
{
series.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, ART_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Art, await _providerManager.DownloadAndSaveImage(series, path, ART_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -138,7 +141,7 @@ namespace MediaBrowser.Controller.Providers.TV
Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name);
try
{
series.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, THUMB_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
series.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(series, path, THUMB_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{

View File

@@ -22,6 +22,8 @@ namespace MediaBrowser.Controller.Providers.TV
/// </summary>
class RemoteEpisodeProvider : BaseMetadataProvider
{
private readonly IProviderManager _providerManager;
/// <summary>
/// Gets the HTTP client.
/// </summary>
@@ -34,10 +36,11 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="httpClient">The HTTP client.</param>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
public RemoteEpisodeProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
public RemoteEpisodeProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
HttpClient = httpClient;
_providerManager = providerManager;
}
/// <summary>
@@ -117,7 +120,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="item">The item.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -229,7 +232,7 @@ namespace MediaBrowser.Controller.Providers.TV
try
{
episode.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(episode, TVUtils.BannerUrl + p, Path.GetFileName(p), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken);
episode.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(episode, TVUtils.BannerUrl + p, Path.GetFileName(p), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken);
}
catch (HttpException)
{
@@ -282,7 +285,7 @@ namespace MediaBrowser.Controller.Providers.TV
var ms = new MemoryStream();
doc.Save(ms);
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(episode, Path.Combine(episode.MetaLocation, Path.GetFileNameWithoutExtension(episode.Path) + ".xml"), ms, cancellationToken).ConfigureAwait(false);
await _providerManager.SaveToLibraryFilesystem(episode, Path.Combine(episode.MetaLocation, Path.GetFileNameWithoutExtension(episode.Path) + ".xml"), ms, cancellationToken).ConfigureAwait(false);
}
return true;

View File

@@ -25,8 +25,10 @@ namespace MediaBrowser.Controller.Providers.TV
/// </summary>
/// <value>The HTTP client.</value>
protected IHttpClient HttpClient { get; private set; }
private readonly IProviderManager _providerManager;
public RemoteSeasonProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
public RemoteSeasonProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (httpClient == null)
@@ -34,6 +36,7 @@ namespace MediaBrowser.Controller.Providers.TV
throw new ArgumentNullException("httpClient");
}
HttpClient = httpClient;
_providerManager = providerManager;
}
/// <summary>
@@ -97,7 +100,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -174,7 +177,7 @@ namespace MediaBrowser.Controller.Providers.TV
try
{
if (n != null)
season.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false);
season.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false);
}
catch (HttpException)
{
@@ -197,8 +200,7 @@ namespace MediaBrowser.Controller.Providers.TV
try
{
var bannerImagePath =
await
Kernel.Instance.ProviderManager.DownloadAndSaveImage(season,
await _providerManager.DownloadAndSaveImage(season,
TVUtils.BannerUrl + n.InnerText,
"banner" +
Path.GetExtension(n.InnerText),
@@ -229,7 +231,7 @@ namespace MediaBrowser.Controller.Providers.TV
try
{
if (season.BackdropImagePaths == null) season.BackdropImagePaths = new List<string>();
season.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "backdrop" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false));
season.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "backdrop" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -257,8 +259,7 @@ namespace MediaBrowser.Controller.Providers.TV
try
{
season.BackdropImagePaths.Add(
await
Kernel.Instance.ProviderManager.DownloadAndSaveImage(season,
await _providerManager.DownloadAndSaveImage(season,
TVUtils.BannerUrl +
n.InnerText,
"backdrop" +

View File

@@ -22,8 +22,10 @@ namespace MediaBrowser.Controller.Providers.TV
/// <summary>
/// Class RemoteSeriesProvider
/// </summary>
class RemoteSeriesProvider : BaseMetadataProvider
class RemoteSeriesProvider : BaseMetadataProvider, IDisposable
{
private readonly IProviderManager _providerManager;
/// <summary>
/// The tv db
/// </summary>
@@ -44,7 +46,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <exception cref="System.ArgumentNullException">httpClient</exception>
public RemoteSeriesProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager)
public RemoteSeriesProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
: base(logManager, configurationManager)
{
if (httpClient == null)
@@ -52,6 +54,7 @@ namespace MediaBrowser.Controller.Providers.TV
throw new ArgumentNullException("httpClient");
}
HttpClient = httpClient;
_providerManager = providerManager;
Current = this;
}
@@ -59,13 +62,12 @@ namespace MediaBrowser.Controller.Providers.TV
/// 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 virtual void Dispose(bool dispose)
{
if (dispose)
{
TvDbResourcePool.Dispose();
}
base.Dispose(dispose);
}
/// <summary>
@@ -149,7 +151,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -252,8 +254,8 @@ namespace MediaBrowser.Controller.Providers.TV
{
var ms = new MemoryStream();
doc.Save(ms);
await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(series, Path.Combine(series.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
await _providerManager.SaveToLibraryFilesystem(series, Path.Combine(series.MetaLocation, LOCAL_META_FILE_NAME), ms, cancellationToken).ConfigureAwait(false);
}
}
}
@@ -366,7 +368,7 @@ namespace MediaBrowser.Controller.Providers.TV
{
try
{
series.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false);
series.PrimaryImagePath = await _providerManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false);
}
catch (HttpException)
{
@@ -389,7 +391,7 @@ namespace MediaBrowser.Controller.Providers.TV
{
try
{
var bannerImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "banner" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken);
var bannerImagePath = await _providerManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "banner" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken);
series.SetImage(ImageType.Banner, bannerImagePath);
}
@@ -418,7 +420,7 @@ namespace MediaBrowser.Controller.Providers.TV
{
try
{
series.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + p.InnerText, bdName + Path.GetExtension(p.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false));
series.BackdropImagePaths.Add(await _providerManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + p.InnerText, bdName + Path.GetExtension(p.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false));
}
catch (HttpException)
{
@@ -584,7 +586,9 @@ namespace MediaBrowser.Controller.Providers.TV
return name.Trim();
}
public void Dispose()
{
Dispose(true);
}
}
}

View File

@@ -57,7 +57,7 @@ namespace MediaBrowser.Controller.Providers.TV
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
return Task.Run(() => Fetch(item, cancellationToken));
}