RefreshMediaLibraryTask.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System.Linq;
  2. using MediaBrowser.Common.ScheduledTasks;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Server.Implementations.Library;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Server.Implementations.ScheduledTasks
  11. {
  12. /// <summary>
  13. /// Class RefreshMediaLibraryTask
  14. /// </summary>
  15. public class RefreshMediaLibraryTask : IScheduledTask, IHasKey
  16. {
  17. /// <summary>
  18. /// The _library manager
  19. /// </summary>
  20. private readonly ILibraryManager _libraryManager;
  21. private readonly IServerConfigurationManager _config;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="RefreshMediaLibraryTask" /> class.
  24. /// </summary>
  25. /// <param name="libraryManager">The library manager.</param>
  26. public RefreshMediaLibraryTask(ILibraryManager libraryManager, IServerConfigurationManager config)
  27. {
  28. _libraryManager = libraryManager;
  29. _config = config;
  30. }
  31. /// <summary>
  32. /// Gets the default triggers.
  33. /// </summary>
  34. /// <returns>IEnumerable{BaseTaskTrigger}.</returns>
  35. public IEnumerable<ITaskTrigger> GetDefaultTriggers()
  36. {
  37. var list = new ITaskTrigger[] {
  38. new IntervalTrigger{ Interval = TimeSpan.FromHours(8)}
  39. }.ToList();
  40. if (!_config.Configuration.DisableStartupScan)
  41. {
  42. list.Add(new StartupTrigger());
  43. }
  44. return list;
  45. }
  46. /// <summary>
  47. /// Executes the internal.
  48. /// </summary>
  49. /// <param name="cancellationToken">The cancellation token.</param>
  50. /// <param name="progress">The progress.</param>
  51. /// <returns>Task.</returns>
  52. public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
  53. {
  54. cancellationToken.ThrowIfCancellationRequested();
  55. progress.Report(0);
  56. return ((LibraryManager)_libraryManager).ValidateMediaLibraryInternal(progress, cancellationToken);
  57. }
  58. /// <summary>
  59. /// Gets the name.
  60. /// </summary>
  61. /// <value>The name.</value>
  62. public string Name
  63. {
  64. get { return "Scan media library"; }
  65. }
  66. /// <summary>
  67. /// Gets the description.
  68. /// </summary>
  69. /// <value>The description.</value>
  70. public string Description
  71. {
  72. get { return "Scans your media library and refreshes metatata based on configuration."; }
  73. }
  74. /// <summary>
  75. /// Gets the category.
  76. /// </summary>
  77. /// <value>The category.</value>
  78. public string Category
  79. {
  80. get
  81. {
  82. return "Library";
  83. }
  84. }
  85. public string Key
  86. {
  87. get { return "RefreshLibrary"; }
  88. }
  89. }
  90. }