2013-10-18 19:08:48 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2015-01-25 06:34:50 +00:00
|
|
|
|
var allYears = _libraryManager.RootFolder.GetRecursiveChildren(i => i.ProductionYear.HasValue)
|
2013-10-18 19:08:48 +00:00
|
|
|
|
.Select(i => i.ProductionYear ?? -1)
|
2013-10-18 19:47:57 +00:00
|
|
|
|
.Where(i => i > 0)
|
2013-10-18 19:08:48 +00:00
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var count = allYears.Count;
|
|
|
|
|
var numComplete = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var yearNumber in allYears)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-01-17 18:15:09 +00:00
|
|
|
|
var year = _libraryManager.GetYear(yearNumber);
|
|
|
|
|
|
2013-10-18 19:08:48 +00:00
|
|
|
|
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);
|
2013-10-18 19:08:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= count;
|
2015-01-17 18:15:09 +00:00
|
|
|
|
percent *= 100;
|
2013-10-18 19:08:48 +00:00
|
|
|
|
|
2015-01-17 18:15:09 +00:00
|
|
|
|
progress.Report(percent);
|
2013-10-18 19:08:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|