You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
using MediaBrowser.Controller.Entities.TV;
|
|
using MediaBrowser.Controller.Library;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MediaBrowser.Providers.TV
|
|
{
|
|
class SeriesPostScanTask : ILibraryPostScanTask
|
|
{
|
|
/// <summary>
|
|
/// The _library manager
|
|
/// </summary>
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
public SeriesPostScanTask(ILibraryManager libraryManager)
|
|
{
|
|
_libraryManager = libraryManager;
|
|
}
|
|
|
|
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
|
{
|
|
return Task.Run(() => RunInternal(progress, cancellationToken));
|
|
}
|
|
|
|
private void RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
|
{
|
|
var seriesList = _libraryManager.RootFolder
|
|
.RecursiveChildren
|
|
.OfType<Series>()
|
|
.ToList();
|
|
|
|
var numComplete = 0;
|
|
|
|
foreach (var series in seriesList)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var episodes = series.RecursiveChildren
|
|
.OfType<Episode>()
|
|
.ToList();
|
|
|
|
series.SpecialFeatureIds = episodes
|
|
.Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
|
|
.Select(i => i.Id)
|
|
.ToList();
|
|
|
|
series.SeasonCount = episodes
|
|
.Select(i => i.ParentIndexNumber ?? 0)
|
|
.Where(i => i != 0)
|
|
.Distinct()
|
|
.Count();
|
|
|
|
numComplete++;
|
|
double percent = numComplete;
|
|
percent /= seriesList.Count;
|
|
percent *= 100;
|
|
|
|
progress.Report(percent);
|
|
}
|
|
}
|
|
}
|
|
}
|