PeopleValidator.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using MediaBrowser.Common.Progress;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Entities;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.Providers;
  6. using MediaBrowser.Model.Configuration;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.Logging;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using MediaBrowser.Controller.IO;
  15. using MediaBrowser.Model.IO;
  16. namespace Emby.Server.Implementations.Library.Validators
  17. {
  18. /// <summary>
  19. /// Class PeopleValidator
  20. /// </summary>
  21. public class PeopleValidator
  22. {
  23. /// <summary>
  24. /// The _library manager
  25. /// </summary>
  26. private readonly ILibraryManager _libraryManager;
  27. /// <summary>
  28. /// The _logger
  29. /// </summary>
  30. private readonly ILogger _logger;
  31. private readonly IServerConfigurationManager _config;
  32. private readonly IFileSystem _fileSystem;
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="PeopleValidator" /> class.
  35. /// </summary>
  36. /// <param name="libraryManager">The library manager.</param>
  37. /// <param name="logger">The logger.</param>
  38. public PeopleValidator(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem)
  39. {
  40. _libraryManager = libraryManager;
  41. _logger = logger;
  42. _config = config;
  43. _fileSystem = fileSystem;
  44. }
  45. /// <summary>
  46. /// Validates the people.
  47. /// </summary>
  48. /// <param name="cancellationToken">The cancellation token.</param>
  49. /// <param name="progress">The progress.</param>
  50. /// <returns>Task.</returns>
  51. public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
  52. {
  53. var people = _libraryManager.GetPeopleNames(new InternalPeopleQuery());
  54. var numComplete = 0;
  55. var numPeople = people.Count;
  56. _logger.Debug("Will refresh {0} people", numPeople);
  57. foreach (var person in people)
  58. {
  59. cancellationToken.ThrowIfCancellationRequested();
  60. try
  61. {
  62. var item = _libraryManager.GetPerson(person);
  63. var options = new MetadataRefreshOptions(_fileSystem)
  64. {
  65. ImageRefreshMode = ImageRefreshMode.ValidationOnly,
  66. MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
  67. };
  68. await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
  69. }
  70. catch (OperationCanceledException)
  71. {
  72. throw;
  73. }
  74. catch (Exception ex)
  75. {
  76. _logger.ErrorException("Error validating IBN entry {0}", ex, person);
  77. }
  78. // Update progress
  79. numComplete++;
  80. double percent = numComplete;
  81. percent /= numPeople;
  82. progress.Report(100 * percent);
  83. }
  84. progress.Report(100);
  85. _logger.Info("People validation complete");
  86. }
  87. }
  88. }