mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-06 18:26:33 +00:00
fixes #585 - Use tmdb updates api for people
This commit is contained in:
@@ -15,7 +15,6 @@ using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations.Library.Validators;
|
||||
using MediaBrowser.Server.Implementations.ScheduledTasks;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -44,6 +43,12 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <value>The prescan tasks.</value>
|
||||
private IEnumerable<ILibraryPrescanTask> PrescanTasks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the people prescan tasks.
|
||||
/// </summary>
|
||||
/// <value>The people prescan tasks.</value>
|
||||
private IEnumerable<IPeoplePrescanTask> PeoplePrescanTasks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the intro providers.
|
||||
/// </summary>
|
||||
@@ -197,6 +202,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <param name="itemComparers">The item comparers.</param>
|
||||
/// <param name="prescanTasks">The prescan tasks.</param>
|
||||
/// <param name="postscanTasks">The postscan tasks.</param>
|
||||
/// <param name="peoplePrescanTasks">The people prescan tasks.</param>
|
||||
/// <param name="savers">The savers.</param>
|
||||
public void AddParts(IEnumerable<IResolverIgnoreRule> rules,
|
||||
IEnumerable<IVirtualFolderCreator> pluginFolders,
|
||||
@@ -205,6 +211,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
IEnumerable<IBaseItemComparer> itemComparers,
|
||||
IEnumerable<ILibraryPrescanTask> prescanTasks,
|
||||
IEnumerable<ILibraryPostScanTask> postscanTasks,
|
||||
IEnumerable<IPeoplePrescanTask> peoplePrescanTasks,
|
||||
IEnumerable<IMetadataSaver> savers)
|
||||
{
|
||||
EntityResolutionIgnoreRules = rules;
|
||||
@@ -214,6 +221,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
Comparers = itemComparers;
|
||||
PrescanTasks = prescanTasks;
|
||||
PostscanTasks = postscanTasks;
|
||||
PeoplePrescanTasks = peoplePrescanTasks;
|
||||
_savers = savers;
|
||||
}
|
||||
|
||||
@@ -771,45 +779,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
public Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var people = RootFolder.GetRecursiveChildren()
|
||||
.SelectMany(c => c.People)
|
||||
.DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
foreach (var person in people)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
var item = GetPerson(person.Name);
|
||||
|
||||
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error validating IBN entry {0}", ex, person.Name);
|
||||
}
|
||||
|
||||
// Update progress
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= people.Count;
|
||||
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
|
||||
_logger.Info("People validation complete");
|
||||
|
||||
// Bad practice, i know. But we keep a lot in memory, unfortunately.
|
||||
GC.Collect(2, GCCollectionMode.Forced, true);
|
||||
GC.Collect(2, GCCollectionMode.Forced, true);
|
||||
return new PeopleValidator(this, PeoplePrescanTasks, _logger).ValidatePeople(cancellationToken, progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1153,7 +1125,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
private Video ResolveIntro(IntroInfo info)
|
||||
{
|
||||
Video video = null;
|
||||
|
||||
|
||||
if (info.ItemId.HasValue)
|
||||
{
|
||||
// Get an existing item by Id
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PeopleValidator
|
||||
/// </summary>
|
||||
public class PeopleValidator
|
||||
{
|
||||
/// <summary>
|
||||
/// The _library manager
|
||||
/// </summary>
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
/// <summary>
|
||||
/// The _logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IEnumerable<IPeoplePrescanTask> _prescanTasks;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PeopleValidator" /> class.
|
||||
/// </summary>
|
||||
/// <param name="libraryManager">The library manager.</param>
|
||||
/// <param name="prescanTasks">The prescan tasks.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
public PeopleValidator(ILibraryManager libraryManager, IEnumerable<IPeoplePrescanTask> prescanTasks, ILogger logger)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_logger = logger;
|
||||
_prescanTasks = prescanTasks;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the people.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
var innerProgress = new ActionableProgress<double>();
|
||||
|
||||
innerProgress.RegisterAction(pct => progress.Report(pct * .15));
|
||||
|
||||
// Run prescan tasks
|
||||
await RunPrescanTasks(innerProgress, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
progress.Report(15);
|
||||
|
||||
var people = _libraryManager.RootFolder.GetRecursiveChildren()
|
||||
.SelectMany(c => c.People)
|
||||
.DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
var numComplete = 0;
|
||||
|
||||
foreach (var person in people)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
var item = _libraryManager.GetPerson(person.Name);
|
||||
|
||||
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error validating IBN entry {0}", ex, person.Name);
|
||||
}
|
||||
|
||||
// Update progress
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= people.Count;
|
||||
|
||||
progress.Report(15 + 85 * percent);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
|
||||
_logger.Info("People validation complete");
|
||||
|
||||
// Bad practice, i know. But we keep a lot in memory, unfortunately.
|
||||
GC.Collect(2, GCCollectionMode.Forced, true);
|
||||
GC.Collect(2, GCCollectionMode.Forced, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the prescan tasks.
|
||||
/// </summary>
|
||||
/// <param name="progress">The progress.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task RunPrescanTasks(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var tasks = _prescanTasks.ToList();
|
||||
|
||||
var numComplete = 0;
|
||||
var numTasks = tasks.Count;
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
var innerProgress = new ActionableProgress<double>();
|
||||
|
||||
// Prevent access to modified closure
|
||||
var currentNumComplete = numComplete;
|
||||
|
||||
innerProgress.RegisterAction(pct =>
|
||||
{
|
||||
double innerPercent = (currentNumComplete * 100) + pct;
|
||||
innerPercent /= numTasks;
|
||||
progress.Report(innerPercent);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
await task.Run(innerProgress, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_logger.Info("Pre-scan task cancelled: {0}", task.GetType().Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error running pre-scan task", ex);
|
||||
}
|
||||
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= numTasks;
|
||||
progress.Report(percent * 100);
|
||||
}
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,7 @@
|
||||
<Compile Include="Library\Validators\MusicGenresPostScanTask.cs" />
|
||||
<Compile Include="Library\Validators\MusicGenresValidator.cs" />
|
||||
<Compile Include="Library\Validators\PeoplePostScanTask.cs" />
|
||||
<Compile Include="Library\Validators\PeopleValidator.cs" />
|
||||
<Compile Include="Library\Validators\StudiosPostScanTask.cs" />
|
||||
<Compile Include="Library\Validators\StudiosValidator.cs" />
|
||||
<Compile Include="LiveTv\LiveTvManager.cs" />
|
||||
|
||||
Reference in New Issue
Block a user