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

105 lines
3.5 KiB

using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
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
{
12 years ago
internal static PersonProviderFromXml Current { get; private set; }
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
Current = this;
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) > providerInfo.LastRefreshed;
}
/// <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 Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
12 years ago
return Fetch(item, cancellationToken);
}
/// <summary>
12 years ago
/// Fetches the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
12 years ago
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private async Task<bool> Fetch(BaseItem item, 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);
12 years ago
return true;
}
12 years ago
return false;
}
}
}