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.
jellyfin/MediaBrowser.Providers/Movies/PersonProviderFromXml.cs

91 lines
3.0 KiB

using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Movies
{
12 years ago
class PersonProviderFromXml : BaseMetadataProvider
{
private readonly IFileSystem _fileSystem;
12 years ago
public PersonProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem)
12 years ago
: base(logManager, configurationManager)
12 years ago
{
_fileSystem = fileSystem;
12 years ago
}
/// <summary>
/// Supportses the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item)
{
return item is Person;
}
/// <summary>
12 years ago
/// Gets the priority.
/// </summary>
12 years ago
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
12 years ago
get { return MetadataProviderPriority.Second; }
}
private const string XmlFileName = "person.xml";
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
{
var xml = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, XmlFileName));
if (xml == null)
{
return false;
}
return _fileSystem.GetLastWriteTimeUtc(xml) > item.DateLastSaved;
}
/// <summary>
12 years ago
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
/// </summary>
12 years ago
/// <param name="item">The item.</param>
/// <param name="force">if set to <c>true</c> [force].</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{System.Boolean}.</returns>
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var metadataFile = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, XmlFileName));
12 years ago
if (metadataFile != null)
{
12 years ago
var path = metadataFile.FullName;
12 years ago
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
12 years ago
try
{
new BaseItemXmlParser<Person>(Logger).Fetch((Person)item, path, cancellationToken);
}
finally
{
XmlParsingResourcePool.Release();
}
SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
12 years ago
return true;
}
12 years ago
return false;
}
}
}