jellyfin/Emby.Server.Implementations/LiveTv/RefreshGuideScheduledTask.cs

76 lines
2.4 KiB
C#
Raw Normal View History

using System;
2013-11-24 21:51:45 +01:00
using System.Collections.Generic;
2021-05-28 14:33:54 +02:00
using System.Threading;
2013-11-24 21:51:45 +01:00
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Tasks;
2013-11-24 21:51:45 +01:00
2016-11-04 00:35:19 +01:00
namespace Emby.Server.Implementations.LiveTv
2013-11-24 21:51:45 +01:00
{
2021-05-28 14:33:54 +02:00
/// <summary>
/// The "Refresh Guide" scheduled task.
/// </summary>
public class RefreshGuideScheduledTask : IScheduledTask, IConfigurableScheduledTask
2013-11-24 21:51:45 +01:00
{
private readonly ILiveTvManager _liveTvManager;
2015-07-23 19:58:20 +02:00
private readonly IConfigurationManager _config;
2013-11-24 21:51:45 +01:00
2021-05-28 14:33:54 +02:00
/// <summary>
/// Initializes a new instance of the <see cref="RefreshGuideScheduledTask"/> class.
/// </summary>
/// <param name="liveTvManager">The live tv manager.</param>
/// <param name="config">The configuration manager.</param>
public RefreshGuideScheduledTask(ILiveTvManager liveTvManager, IConfigurationManager config)
2013-11-24 21:51:45 +01:00
{
_liveTvManager = liveTvManager;
2015-07-23 19:58:20 +02:00
_config = config;
2013-11-24 21:51:45 +01:00
}
2021-05-28 14:33:54 +02:00
/// <inheritdoc />
public string Name => "Refresh Guide";
2013-11-24 21:51:45 +01:00
2021-05-28 14:33:54 +02:00
/// <inheritdoc />
public string Description => "Downloads channel information from live tv services.";
2013-11-24 21:51:45 +01:00
2021-05-28 14:33:54 +02:00
/// <inheritdoc />
public string Category => "Live TV";
2013-11-24 21:51:45 +01:00
2021-05-28 14:33:54 +02:00
/// <inheritdoc />
public bool IsHidden => _liveTvManager.Services.Count == 1 && GetConfiguration().TunerHosts.Length == 0;
/// <inheritdoc />
public bool IsEnabled => true;
/// <inheritdoc />
public bool IsLogged => true;
/// <inheritdoc />
public string Key => "RefreshGuide";
/// <inheritdoc />
2022-02-15 18:59:46 +01:00
public Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
2013-11-24 21:51:45 +01:00
{
var manager = (LiveTvManager)_liveTvManager;
2013-11-24 21:51:45 +01:00
return manager.RefreshChannels(progress, cancellationToken);
}
2021-05-28 14:33:54 +02:00
/// <inheritdoc />
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
2013-11-24 21:51:45 +01:00
{
2019-10-25 12:47:20 +02:00
return new[]
{
// Every so often
2020-10-12 19:22:33 +02:00
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
2013-11-24 21:51:45 +01:00
};
}
2015-07-23 19:58:20 +02:00
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
2013-11-24 21:51:45 +01:00
}
}