| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Threading; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using MediaBrowser.Controller.Channels; |
| | 6 | | using MediaBrowser.Controller.Library; |
| | 7 | | using MediaBrowser.Model.Globalization; |
| | 8 | | using MediaBrowser.Model.Tasks; |
| | 9 | | using Microsoft.Extensions.Logging; |
| | 10 | |
|
| | 11 | | namespace Jellyfin.LiveTv.Channels |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// The "Refresh Channels" scheduled task. |
| | 15 | | /// </summary> |
| | 16 | | public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask |
| | 17 | | { |
| | 18 | | private readonly IChannelManager _channelManager; |
| | 19 | | private readonly ILogger<RefreshChannelsScheduledTask> _logger; |
| | 20 | | private readonly ILibraryManager _libraryManager; |
| | 21 | | private readonly ILocalizationManager _localization; |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Initializes a new instance of the <see cref="RefreshChannelsScheduledTask"/> class. |
| | 25 | | /// </summary> |
| | 26 | | /// <param name="channelManager">The channel manager.</param> |
| | 27 | | /// <param name="logger">The logger.</param> |
| | 28 | | /// <param name="libraryManager">The library manager.</param> |
| | 29 | | /// <param name="localization">The localization manager.</param> |
| | 30 | | public RefreshChannelsScheduledTask( |
| | 31 | | IChannelManager channelManager, |
| | 32 | | ILogger<RefreshChannelsScheduledTask> logger, |
| | 33 | | ILibraryManager libraryManager, |
| | 34 | | ILocalizationManager localization) |
| | 35 | | { |
| 21 | 36 | | _channelManager = channelManager; |
| 21 | 37 | | _logger = logger; |
| 21 | 38 | | _libraryManager = libraryManager; |
| 21 | 39 | | _localization = localization; |
| 21 | 40 | | } |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| 21 | 43 | | public string Name => _localization.GetLocalizedString("TasksRefreshChannels"); |
| | 44 | |
|
| | 45 | | /// <inheritdoc /> |
| 0 | 46 | | public string Description => _localization.GetLocalizedString("TasksRefreshChannelsDescription"); |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| 0 | 49 | | public string Category => _localization.GetLocalizedString("TasksChannelsCategory"); |
| | 50 | |
|
| | 51 | | /// <inheritdoc /> |
| 0 | 52 | | public bool IsHidden => ((ChannelManager)_channelManager).Channels.Length == 0; |
| | 53 | |
|
| | 54 | | /// <inheritdoc /> |
| 0 | 55 | | public bool IsEnabled => true; |
| | 56 | |
|
| | 57 | | /// <inheritdoc /> |
| 0 | 58 | | public bool IsLogged => true; |
| | 59 | |
|
| | 60 | | /// <inheritdoc /> |
| 0 | 61 | | public string Key => "RefreshInternetChannels"; |
| | 62 | |
|
| | 63 | | /// <inheritdoc /> |
| | 64 | | public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken) |
| | 65 | | { |
| | 66 | | var manager = (ChannelManager)_channelManager; |
| | 67 | |
|
| | 68 | | await manager.RefreshChannels(new Progress<double>(), cancellationToken).ConfigureAwait(false); |
| | 69 | |
|
| | 70 | | await new ChannelPostScanTask(_channelManager, _logger, _libraryManager).Run(progress, cancellationToken) |
| | 71 | | .ConfigureAwait(false); |
| | 72 | | } |
| | 73 | |
|
| | 74 | | /// <inheritdoc /> |
| | 75 | | public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() |
| | 76 | | { |
| 21 | 77 | | return new[] |
| 21 | 78 | | { |
| 21 | 79 | | // Every so often |
| 21 | 80 | | new TaskTriggerInfo |
| 21 | 81 | | { |
| 21 | 82 | | Type = TaskTriggerInfoType.IntervalTrigger, IntervalTicks = TimeSpan.FromHours(24).Ticks |
| 21 | 83 | | } |
| 21 | 84 | | }; |
| | 85 | | } |
| | 86 | | } |
| | 87 | | } |