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

78 lines
2.5 KiB
C#
Raw Normal View History

2019-11-01 17:38:54 +00:00
#pragma warning disable CS1591
2019-12-10 23:13:57 +00:00
#pragma warning disable SA1600
2019-11-01 17:38:54 +00:00
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.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
{
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;
private readonly IUserManager _userManager;
private readonly ILogger _logger;
2015-08-22 17:50:37 +00:00
private readonly ILibraryManager _libraryManager;
2014-03-18 17:05:57 +00:00
2015-08-22 17:50:37 +00:00
public RefreshChannelsScheduledTask(IChannelManager channelManager, IUserManager userManager, ILogger logger, ILibraryManager libraryManager)
2014-03-18 17:05:57 +00:00
{
2015-07-29 03:42:03 +00:00
_channelManager = channelManager;
_userManager = userManager;
_logger = logger;
2015-08-22 17:50:37 +00:00
_libraryManager = libraryManager;
2014-03-18 17:05:57 +00:00
}
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Name => "Refresh Channels";
2014-03-18 17:05:57 +00:00
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Description => "Refreshes internet channel information.";
2014-03-18 17:05:57 +00:00
2020-01-31 21:23:46 +00:00
/// <inheritdoc />
public string Category => "Internet Channels";
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 />
2018-12-30 17:30:29 +00:00
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
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
2015-08-22 17:50:37 +00:00
await new ChannelPostScanTask(_channelManager, _userManager, _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[]
{
2019-01-07 23:27:46 +00:00
// 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
};
}
}
}