2016-10-29 18:46:56 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-28 19:32:41 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-03 06:37:52 +00:00
|
|
|
|
using Emby.Server.Implementations.Library;
|
2016-10-23 19:14:57 +00:00
|
|
|
|
using MediaBrowser.Model.Tasks;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
|
namespace Emby.Server.Implementations.ScheduledTasks
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class RefreshMediaLibraryTask
|
|
|
|
|
/// </summary>
|
2016-10-23 19:14:57 +00:00
|
|
|
|
public class RefreshMediaLibraryTask : IScheduledTask
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-02-26 03:43:04 +00:00
|
|
|
|
/// <summary>
|
2013-02-28 19:32:41 +00:00
|
|
|
|
/// The _library manager
|
2013-02-26 03:43:04 +00:00
|
|
|
|
/// </summary>
|
2013-02-28 19:32:41 +00:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2015-08-27 01:31:54 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2013-02-26 03:43:04 +00:00
|
|
|
|
|
2013-02-23 07:57:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
|
|
|
|
|
/// </summary>
|
2013-02-28 19:32:41 +00:00
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
2015-08-27 01:31:54 +00:00
|
|
|
|
public RefreshMediaLibraryTask(ILibraryManager libraryManager, IServerConfigurationManager config)
|
2013-02-23 07:57:11 +00:00
|
|
|
|
{
|
2013-02-28 19:32:41 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2015-08-27 01:31:54 +00:00
|
|
|
|
_config = config;
|
2013-02-23 07:57:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
2016-10-23 19:14:57 +00:00
|
|
|
|
/// Creates the triggers that define when the task will run
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
|
2016-10-23 19:14:57 +00:00
|
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2016-10-23 19:14:57 +00:00
|
|
|
|
return new[] {
|
|
|
|
|
|
|
|
|
|
// Every so often
|
|
|
|
|
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(12).Ticks}
|
|
|
|
|
};
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Executes the internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <param name="progress">The progress.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
2013-02-26 03:43:04 +00:00
|
|
|
|
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2013-02-22 04:23:06 +00:00
|
|
|
|
progress.Report(0);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-04-14 19:39:25 +00:00
|
|
|
|
return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The name.</value>
|
2013-02-26 03:43:04 +00:00
|
|
|
|
public string Name
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
get { return "Scan media library"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the description.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The description.</value>
|
2013-02-26 03:43:04 +00:00
|
|
|
|
public string Description
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
get { return "Scans your media library and refreshes metatata based on configuration."; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the category.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The category.</value>
|
2013-02-26 03:43:04 +00:00
|
|
|
|
public string Category
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "Library";
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-13 21:26:04 +00:00
|
|
|
|
|
|
|
|
|
public string Key
|
|
|
|
|
{
|
|
|
|
|
get { return "RefreshLibrary"; }
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|