jellyfin-server/Emby.Server.Implementations/Channels/RefreshChannelsScheduledTask.cs

89 lines
3.1 KiB
C#
Raw Normal View History

using System;
2014-03-18 17:05:57 +00:00
using System.Collections.Generic;
2018-12-30 17:30:29 +00:00
using System.Threading;
2014-03-18 17:05:57 +00:00
using System.Threading.Tasks;
2017-06-23 16:04:45 +00:00
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
2014-03-18 17:05:57 +00:00
namespace Emby.Server.Implementations.Channels
2014-03-18 17:05:57 +00:00
{
/// <summary>
/// The "Refresh Channels" scheduled task.
/// </summary>
public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
2014-03-18 17:05:57 +00:00
{
2015-07-29 03:42:03 +00:00
private readonly IChannelManager _channelManager;
2020-06-06 00:15:56 +00:00
private readonly ILogger<RefreshChannelsScheduledTask> _logger;
2015-08-22 17:50:37 +00:00
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
2014-03-18 17:05:57 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="RefreshChannelsScheduledTask"/> class.
/// </summary>
/// <param name="channelManager">The channel manager.</param>
/// <param name="logger">The logger.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="localization">The localization manager.</param>
public RefreshChannelsScheduledTask(
IChannelManager channelManager,
ILogger<RefreshChannelsScheduledTask> logger,
ILibraryManager libraryManager,
ILocalizationManager localization)
2014-03-18 17:05:57 +00:00
{
2015-07-29 03:42:03 +00:00
_channelManager = channelManager;
_logger = logger;
2015-08-22 17:50:37 +00:00
_libraryManager = libraryManager;
_localization = localization;
2014-03-18 17:05:57 +00:00
}
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Name => _localization.GetLocalizedString("TasksRefreshChannels");
2014-03-18 17:05:57 +00:00
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Description => _localization.GetLocalizedString("TasksRefreshChannelsDescription");
2014-03-18 17:05:57 +00:00
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
2020-03-29 21:46:19 +00:00
public string Category => _localization.GetLocalizedString("TasksChannelsCategory");
2014-03-18 17:05:57 +00:00
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public bool IsHidden => ((ChannelManager)_channelManager).Channels.Length == 0;
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public bool IsEnabled => true;
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public bool IsLogged => true;
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Key => "RefreshInternetChannels";
/// <inheritdoc />
2022-02-15 17:59:46 +00:00
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
2014-03-18 17:05:57 +00:00
{
2015-07-29 03:42:03 +00:00
var manager = (ChannelManager)_channelManager;
2014-03-18 17:05:57 +00:00
2017-06-23 16:04:45 +00:00
await manager.RefreshChannels(new SimpleProgress<double>(), cancellationToken).ConfigureAwait(false);
2015-07-29 03:42:03 +00:00
2020-04-14 19:36:29 +00:00
await new ChannelPostScanTask(_channelManager, _logger, _libraryManager).Run(progress, cancellationToken)
2015-07-29 03:42:03 +00:00
.ConfigureAwait(false);
2014-03-18 17:05:57 +00:00
}
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
2014-03-18 17:05:57 +00:00
{
2020-01-31 21:23:46 +00:00
return new[]
{
// Every so often
2020-01-31 21:23:46 +00:00
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks
}
2014-03-18 17:05:57 +00:00
};
}
}
}