2013-08-31 01:08:32 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2013-09-24 15:08:51 +00:00
|
|
|
|
RunInternal(progress, cancellationToken);
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(true);
|
2013-08-31 01:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2013-09-30 00:51:04 +00:00
|
|
|
|
series.DateLastEpisodeAdded = episodes.Select(i => i.DateCreated)
|
|
|
|
|
.OrderByDescending(i => i)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
2013-08-31 01:08:32 +00:00
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= seriesList.Count;
|
|
|
|
|
percent *= 100;
|
|
|
|
|
|
|
|
|
|
progress.Report(percent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|