jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/RefreshMediaLibraryTask.cs

75 lines
2.4 KiB
C#
Raw Normal View History

using System;
2013-02-20 20:33:05 -05:00
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Emby.Server.Implementations.Library;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Tasks;
2013-02-20 20:33:05 -05:00
namespace Emby.Server.Implementations.ScheduledTasks
2013-02-20 20:33:05 -05:00
{
/// <summary>
2019-08-29 03:14:50 -04:00
/// Class RefreshMediaLibraryTask.
2013-02-20 20:33:05 -05:00
/// </summary>
public class RefreshMediaLibraryTask : IScheduledTask
2013-02-20 20:33:05 -05:00
{
/// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
2015-08-26 21:31:54 -04:00
private readonly IServerConfigurationManager _config;
2013-02-23 02:57:11 -05:00
/// <summary>
/// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
2015-08-26 21:31:54 -04:00
public RefreshMediaLibraryTask(ILibraryManager libraryManager, IServerConfigurationManager config)
2013-02-23 02:57:11 -05:00
{
_libraryManager = libraryManager;
2015-08-26 21:31:54 -04:00
_config = config;
2013-02-23 02:57:11 -05:00
}
2013-02-20 20:33:05 -05:00
/// <summary>
2019-08-29 03:14:50 -04:00
/// Creates the triggers that define when the task will run.
2013-02-20 20:33:05 -05:00
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
2013-02-20 20:33:05 -05:00
{
2019-08-29 03:14:50 -04:00
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(12).Ticks
};
2013-02-20 20:33:05 -05:00
}
/// <summary>
/// Executes the internal.
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress.</param>
/// <returns>Task.</returns>
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
2013-02-20 20:33:05 -05:00
{
cancellationToken.ThrowIfCancellationRequested();
2013-02-21 23:23:06 -05:00
progress.Report(0);
2013-02-20 20:33:05 -05:00
return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
2013-02-20 20:33:05 -05:00
}
2020-02-01 08:27:25 -05:00
public string Name => "Scan Media Library";
2013-02-20 20:33:05 -05:00
2019-08-29 03:14:50 -04:00
public string Description => "Scans your media library for new files and refreshes metadata.";
2013-02-20 20:33:05 -05:00
public string Category => "Library";
2014-12-13 16:26:04 -05:00
public string Key => "RefreshLibrary";
public bool IsHidden => false;
public bool IsEnabled => true;
public bool IsLogged => true;
2013-02-20 20:33:05 -05:00
}
}