2014-02-17 21:35:08 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-10-16 23:35:11 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-08-31 01:08:32 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-06 04:39:16 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-10-16 23:35:11 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-08-31 01:08:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.TV
|
|
|
|
|
{
|
2014-02-09 23:08:01 +00:00
|
|
|
|
class SeriesPostScanTask : ILibraryPostScanTask, IHasOrder
|
2013-08-31 01:08:32 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _library manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-10-16 23:35:11 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ILogger _logger;
|
2013-08-31 01:08:32 +00:00
|
|
|
|
|
2013-10-24 17:49:24 +00:00
|
|
|
|
public SeriesPostScanTask(ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config)
|
2013-08-31 01:08:32 +00:00
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
2013-10-16 23:35:11 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_config = config;
|
2013-08-31 01:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2013-10-16 23:35:11 +00:00
|
|
|
|
return RunInternal(progress, cancellationToken);
|
2013-08-31 01:08:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 23:35:11 +00:00
|
|
|
|
private async Task RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
2013-08-31 01:08:32 +00:00
|
|
|
|
{
|
|
|
|
|
var seriesList = _libraryManager.RootFolder
|
|
|
|
|
.RecursiveChildren
|
|
|
|
|
.OfType<Series>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-12-08 22:07:57 +00:00
|
|
|
|
var seriesGroups = from series in seriesList
|
|
|
|
|
let tvdbId = series.GetProviderId(MetadataProviders.Tvdb)
|
|
|
|
|
where !string.IsNullOrEmpty(tvdbId)
|
|
|
|
|
group series by tvdbId into g
|
|
|
|
|
select g;
|
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
await new MissingEpisodeProvider(_logger, _config, _libraryManager).Run(seriesGroups, cancellationToken).ConfigureAwait(false);
|
2013-12-08 22:07:57 +00:00
|
|
|
|
|
2013-08-31 01:08:32 +00:00
|
|
|
|
var numComplete = 0;
|
2014-02-06 04:39:16 +00:00
|
|
|
|
|
2013-08-31 01:08:32 +00:00
|
|
|
|
foreach (var series in seriesList)
|
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
var episodes = series.RecursiveChildren
|
|
|
|
|
.OfType<Episode>()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2014-01-20 18:46:08 +00:00
|
|
|
|
var physicalEpisodes = episodes.Where(i => i.LocationType != LocationType.Virtual)
|
2013-08-31 01:08:32 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
series.SeasonCount = episodes
|
|
|
|
|
.Select(i => i.ParentIndexNumber ?? 0)
|
|
|
|
|
.Where(i => i != 0)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.Count();
|
|
|
|
|
|
2014-01-20 18:46:08 +00:00
|
|
|
|
series.SpecialFeatureIds = physicalEpisodes
|
|
|
|
|
.Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
|
|
|
|
|
.Select(i => i.Id)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
series.DateLastEpisodeAdded = physicalEpisodes.Select(i => i.DateCreated)
|
2013-09-30 00:51:04 +00:00
|
|
|
|
.OrderByDescending(i => i)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
2013-08-31 01:08:32 +00:00
|
|
|
|
numComplete++;
|
|
|
|
|
double percent = numComplete;
|
|
|
|
|
percent /= seriesList.Count;
|
|
|
|
|
percent *= 100;
|
|
|
|
|
|
|
|
|
|
progress.Report(percent);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-09 23:08:01 +00:00
|
|
|
|
|
|
|
|
|
public int Order
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// Run after tvdb update task
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-31 01:08:32 +00:00
|
|
|
|
}
|
2013-10-16 23:35:11 +00:00
|
|
|
|
|
2013-08-31 01:08:32 +00:00
|
|
|
|
}
|