2
0

RefreshGuideScheduledTask.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Controller.LiveTv;
  7. using MediaBrowser.Model.LiveTv;
  8. using MediaBrowser.Model.Tasks;
  9. namespace Emby.Server.Implementations.LiveTv
  10. {
  11. /// <summary>
  12. /// The "Refresh Guide" scheduled task.
  13. /// </summary>
  14. public class RefreshGuideScheduledTask : IScheduledTask, IConfigurableScheduledTask
  15. {
  16. private readonly ILiveTvManager _liveTvManager;
  17. private readonly IConfigurationManager _config;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="RefreshGuideScheduledTask"/> class.
  20. /// </summary>
  21. /// <param name="liveTvManager">The live tv manager.</param>
  22. /// <param name="config">The configuration manager.</param>
  23. public RefreshGuideScheduledTask(ILiveTvManager liveTvManager, IConfigurationManager config)
  24. {
  25. _liveTvManager = liveTvManager;
  26. _config = config;
  27. }
  28. /// <inheritdoc />
  29. public string Name => "Refresh Guide";
  30. /// <inheritdoc />
  31. public string Description => "Downloads channel information from live tv services.";
  32. /// <inheritdoc />
  33. public string Category => "Live TV";
  34. /// <inheritdoc />
  35. public bool IsHidden => _liveTvManager.Services.Count == 1 && GetConfiguration().TunerHosts.Length == 0;
  36. /// <inheritdoc />
  37. public bool IsEnabled => true;
  38. /// <inheritdoc />
  39. public bool IsLogged => true;
  40. /// <inheritdoc />
  41. public string Key => "RefreshGuide";
  42. /// <inheritdoc />
  43. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  44. {
  45. var manager = (LiveTvManager)_liveTvManager;
  46. return manager.RefreshChannels(progress, cancellationToken);
  47. }
  48. /// <inheritdoc />
  49. public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
  50. {
  51. return new[]
  52. {
  53. // Every so often
  54. new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
  55. };
  56. }
  57. private LiveTvOptions GetConfiguration()
  58. {
  59. return _config.GetConfiguration<LiveTvOptions>("livetv");
  60. }
  61. }
  62. }