PeopleValidationTask.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using MediaBrowser.Common.ScheduledTasks;
  2. using MediaBrowser.Controller.Library;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using MediaBrowser.Controller;
  8. using MediaBrowser.Model.Tasks;
  9. namespace MediaBrowser.Server.Implementations.ScheduledTasks
  10. {
  11. /// <summary>
  12. /// Class PeopleValidationTask
  13. /// </summary>
  14. public class PeopleValidationTask : IScheduledTask
  15. {
  16. /// <summary>
  17. /// The _library manager
  18. /// </summary>
  19. private readonly ILibraryManager _libraryManager;
  20. private readonly IServerApplicationHost _appHost;
  21. /// <summary>
  22. /// Initializes a new instance of the <see cref="PeopleValidationTask" /> class.
  23. /// </summary>
  24. /// <param name="libraryManager">The library manager.</param>
  25. public PeopleValidationTask(ILibraryManager libraryManager, IServerApplicationHost appHost)
  26. {
  27. _libraryManager = libraryManager;
  28. _appHost = appHost;
  29. }
  30. /// <summary>
  31. /// Creates the triggers that define when the task will run
  32. /// </summary>
  33. public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
  34. {
  35. // Randomize the default start hour because this operation can really hammer internet metadata providers
  36. var startHour = new Random(_appHost.SystemId.GetHashCode()).Next(0, 8);
  37. return new[] {
  38. // Every so often
  39. new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(startHour).Ticks}
  40. };
  41. }
  42. public string Key
  43. {
  44. get { return "RefreshPeople"; }
  45. }
  46. /// <summary>
  47. /// Returns the task to be executed
  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. return _libraryManager.ValidatePeople(cancellationToken, progress);
  55. }
  56. /// <summary>
  57. /// Gets the name of the task
  58. /// </summary>
  59. /// <value>The name.</value>
  60. public string Name
  61. {
  62. get { return "Refresh people"; }
  63. }
  64. /// <summary>
  65. /// Gets the description.
  66. /// </summary>
  67. /// <value>The description.</value>
  68. public string Description
  69. {
  70. get { return "Updates metadata for actors and directors in your media library."; }
  71. }
  72. /// <summary>
  73. /// Gets the category.
  74. /// </summary>
  75. /// <value>The category.</value>
  76. public string Category
  77. {
  78. get
  79. {
  80. return "Library";
  81. }
  82. }
  83. }
  84. }