RefreshMediaLibraryTask.cs 2.9 KB

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