using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Channels
{
///
/// The "Refresh Channels" scheduled task.
///
public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly IChannelManager _channelManager;
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
///
/// Initializes a new instance of the class.
///
/// The channel manager.
/// The logger.
/// The library manager.
/// The localization manager.
public RefreshChannelsScheduledTask(
IChannelManager channelManager,
ILogger logger,
ILibraryManager libraryManager,
ILocalizationManager localization)
{
_channelManager = channelManager;
_logger = logger;
_libraryManager = libraryManager;
_localization = localization;
}
///
public string Name => _localization.GetLocalizedString("TasksRefreshChannels");
///
public string Description => _localization.GetLocalizedString("TasksRefreshChannelsDescription");
///
public string Category => _localization.GetLocalizedString("TasksChannelsCategory");
///
public bool IsHidden => ((ChannelManager)_channelManager).Channels.Length == 0;
///
public bool IsEnabled => true;
///
public bool IsLogged => true;
///
public string Key => "RefreshInternetChannels";
///
public async Task Execute(CancellationToken cancellationToken, IProgress progress)
{
var manager = (ChannelManager)_channelManager;
await manager.RefreshChannels(new SimpleProgress(), cancellationToken).ConfigureAwait(false);
await new ChannelPostScanTask(_channelManager, _logger, _libraryManager).Run(progress, cancellationToken)
.ConfigureAwait(false);
}
///
public IEnumerable GetDefaultTriggers()
{
return new[]
{
// Every so often
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks
}
};
}
}
}