2019-11-01 10:38:54 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2014-03-18 10:05:57 -07:00
|
|
|
using System.Collections.Generic;
|
2018-12-30 10:30:29 -07:00
|
|
|
using System.Threading;
|
2014-03-18 10:05:57 -07:00
|
|
|
using System.Threading.Tasks;
|
2017-06-23 09:04:45 -07:00
|
|
|
using MediaBrowser.Common.Progress;
|
2019-01-13 12:20:16 -07:00
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-10-23 12:14:57 -07:00
|
|
|
using MediaBrowser.Model.Tasks;
|
2019-01-13 12:20:16 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-03-26 14:36:11 -07:00
|
|
|
using MediaBrowser.Model.Globalization;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2016-11-02 13:53:50 -07:00
|
|
|
namespace Emby.Server.Implementations.Channels
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2019-02-15 15:05:14 -07:00
|
|
|
public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2015-07-28 20:42:03 -07:00
|
|
|
private readonly IChannelManager _channelManager;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly ILogger _logger;
|
2015-08-22 10:50:37 -07:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2020-03-26 14:36:11 -07:00
|
|
|
private readonly ILocalizationManager _localization;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2020-03-03 15:07:10 -07:00
|
|
|
public RefreshChannelsScheduledTask(
|
|
|
|
IChannelManager channelManager,
|
|
|
|
IUserManager userManager,
|
|
|
|
ILogger<RefreshChannelsScheduledTask> logger,
|
2020-03-26 14:36:11 -07:00
|
|
|
ILibraryManager libraryManager,
|
|
|
|
ILocalizationManager localization)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2015-07-28 20:42:03 -07:00
|
|
|
_channelManager = channelManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
_logger = logger;
|
2015-08-22 10:50:37 -07:00
|
|
|
_libraryManager = libraryManager;
|
2020-03-26 14:36:11 -07:00
|
|
|
_localization = localization;
|
2014-03-18 10:05:57 -07:00
|
|
|
}
|
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2020-03-26 14:36:11 -07:00
|
|
|
public string Name => _localization.GetLocalizedString("TasksRefreshChannels");
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2020-03-26 14:36:11 -07:00
|
|
|
public string Description => _localization.GetLocalizedString("TasksRefreshChannelsDescription");
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2020-03-29 14:46:19 -07:00
|
|
|
public string Category => _localization.GetLocalizedString("TasksChannelsCategory");
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-06 13:50:43 -07:00
|
|
|
public bool IsHidden => ((ChannelManager)_channelManager).Channels.Length == 0;
|
2017-10-27 21:19:38 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-06 13:50:43 -07:00
|
|
|
public bool IsEnabled => true;
|
2017-10-27 21:19:38 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-06 13:50:43 -07:00
|
|
|
public bool IsLogged => true;
|
2017-10-27 21:19:38 -07:00
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
public string Key => "RefreshInternetChannels";
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-12-30 10:30:29 -07:00
|
|
|
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2015-07-28 20:42:03 -07:00
|
|
|
var manager = (ChannelManager)_channelManager;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
2017-06-23 09:04:45 -07:00
|
|
|
await manager.RefreshChannels(new SimpleProgress<double>(), cancellationToken).ConfigureAwait(false);
|
2015-07-28 20:42:03 -07:00
|
|
|
|
2015-08-22 10:50:37 -07:00
|
|
|
await new ChannelPostScanTask(_channelManager, _userManager, _logger, _libraryManager).Run(progress, cancellationToken)
|
2015-07-28 20:42:03 -07:00
|
|
|
.ConfigureAwait(false);
|
2014-03-18 10:05:57 -07:00
|
|
|
}
|
|
|
|
|
2020-01-31 14:23:46 -07:00
|
|
|
/// <inheritdoc />
|
2016-10-23 12:14:57 -07:00
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
|
2014-03-18 10:05:57 -07:00
|
|
|
{
|
2020-01-31 14:23:46 -07:00
|
|
|
return new[]
|
|
|
|
{
|
2019-01-07 16:27:46 -07:00
|
|
|
|
2016-10-23 12:14:57 -07:00
|
|
|
// Every so often
|
2020-01-31 14:23:46 -07:00
|
|
|
new TaskTriggerInfo
|
|
|
|
{
|
|
|
|
Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks
|
|
|
|
}
|
2014-03-18 10:05:57 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|