jellyfin/MediaBrowser.Server.Implementations/Library/Validators/YearsPostScanTask.cs

57 lines
1.6 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Logging;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Library.Validators
{
public class YearsPostScanTask : ILibraryPostScanTask
{
private readonly ILibraryManager _libraryManager;
private readonly ILogger _logger;
public YearsPostScanTask(ILibraryManager libraryManager, ILogger logger)
{
_libraryManager = libraryManager;
_logger = logger;
}
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
2016-05-10 19:20:17 +00:00
var yearNumber = 1900;
var maxYear = DateTime.UtcNow.Year + 3;
var count = maxYear - yearNumber + 1;
var numComplete = 0;
2016-05-11 02:21:28 +00:00
while (yearNumber < maxYear)
{
try
{
2015-01-17 18:15:09 +00:00
var year = _libraryManager.GetYear(yearNumber);
await year.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Don't clutter the log
break;
}
catch (Exception ex)
{
2015-01-17 18:15:09 +00:00
_logger.ErrorException("Error refreshing year {0}", ex, yearNumber);
}
numComplete++;
double percent = numComplete;
percent /= count;
2015-01-17 18:15:09 +00:00
percent *= 100;
2015-01-17 18:15:09 +00:00
progress.Report(percent);
2016-05-10 19:30:20 +00:00
yearNumber++;
}
}
}
}