save person.xml
This commit is contained in:
parent
d6cf7b51ac
commit
41f84fc6b2
|
@ -62,7 +62,7 @@
|
|||
<Compile Include="Movies\MovieDbProvider.cs" />
|
||||
<Compile Include="Movies\MovieProviderFromXml.cs" />
|
||||
<Compile Include="Movies\OpenMovieDatabaseProvider.cs" />
|
||||
<Compile Include="Movies\PersonProviderFromJson.cs" />
|
||||
<Compile Include="Movies\PersonProviderFromXml.cs" />
|
||||
<Compile Include="Movies\TmdbPersonProvider.cs" />
|
||||
<Compile Include="Music\ArtistsPostScanTask.cs" />
|
||||
<Compile Include="Music\FanArtAlbumProvider.cs" />
|
||||
|
@ -79,6 +79,7 @@
|
|||
<Compile Include="Savers\EpisodeXmlSaver.cs" />
|
||||
<Compile Include="Savers\FolderXmlSaver.cs" />
|
||||
<Compile Include="Savers\MovieXmlSaver.cs" />
|
||||
<Compile Include="Savers\PersonXmlSaver.cs" />
|
||||
<Compile Include="Savers\SeriesXmlSaver.cs" />
|
||||
<Compile Include="Savers\XmlHelpers.cs" />
|
||||
<Compile Include="TV\EpisodeImageFromMediaLocationProvider.cs" />
|
||||
|
|
|
@ -199,7 +199,7 @@ namespace MediaBrowser.Providers.Movies
|
|||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (HasAltMeta(item))
|
||||
return false; //never refresh if has meta from other source
|
||||
return false;
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
@ -10,14 +9,14 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MediaBrowser.Providers.Movies
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PersonProviderFromJson
|
||||
/// </summary>
|
||||
class PersonProviderFromJson : TmdbPersonProvider
|
||||
class PersonProviderFromXml : BaseMetadataProvider
|
||||
{
|
||||
public PersonProviderFromJson(IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
|
||||
: base(jsonSerializer, logManager, configurationManager, providerManager)
|
||||
internal static PersonProviderFromXml Current { get; private set; }
|
||||
|
||||
public PersonProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager)
|
||||
: base(logManager, configurationManager)
|
||||
{
|
||||
Current = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -31,32 +30,12 @@ namespace MediaBrowser.Providers.Movies
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [requires internet].
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
||||
public override bool RequiresInternet
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Need to re-override to jump over intermediate implementation
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (!item.ResolveArgs.ContainsMetaFileByName(MetaFileName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return CompareDate(item) > providerInfo.LastRefreshed;
|
||||
get { return MetadataProviderPriority.Second; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -67,22 +46,10 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <returns>DateTime.</returns>
|
||||
protected override DateTime CompareDate(BaseItem item)
|
||||
{
|
||||
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation,MetaFileName));
|
||||
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, "person.xml"));
|
||||
return entry != null ? entry.LastWriteTimeUtc : DateTime.MinValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public override MetadataProviderPriority Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return MetadataProviderPriority.Third;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
|
@ -91,25 +58,42 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
return Fetch(item, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
private async Task<bool> Fetch(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
var metadataFile = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, "person.xml"));
|
||||
|
||||
if (metadataFile != null)
|
||||
{
|
||||
var personInfo = JsonSerializer.DeserializeFromFile<PersonResult>(Path.Combine(item.MetaLocation, MetaFileName));
|
||||
var path = metadataFile.FullName;
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
ProcessInfo((Person)item, personInfo);
|
||||
try
|
||||
{
|
||||
new BaseItemXmlParser<Person>(Logger).Fetch((Person)item, path, cancellationToken);
|
||||
}
|
||||
finally
|
||||
{
|
||||
XmlParsingResourcePool.Release();
|
||||
}
|
||||
|
||||
SetLastRefreshed(item, DateTime.UtcNow);
|
||||
return TrueTaskResult;
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// This is okay - just means we force refreshed and there isn't a json file
|
||||
return FalseTaskResult;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,11 +21,6 @@ namespace MediaBrowser.Providers.Movies
|
|||
/// </summary>
|
||||
public class TmdbPersonProvider : BaseMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// The meta file name
|
||||
/// </summary>
|
||||
protected const string MetaFileName = "tmdb3.json";
|
||||
|
||||
protected readonly IProviderManager ProviderManager;
|
||||
|
||||
public TmdbPersonProvider(IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
|
||||
|
@ -71,6 +66,19 @@ namespace MediaBrowser.Providers.Movies
|
|||
}
|
||||
}
|
||||
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
if (HasAltMeta(item))
|
||||
return false;
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
private bool HasAltMeta(BaseItem item)
|
||||
{
|
||||
return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName("person.xml");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
|
@ -184,13 +192,6 @@ namespace MediaBrowser.Providers.Movies
|
|||
{
|
||||
ProcessInfo(person, searchResult);
|
||||
|
||||
//save locally
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
JsonSerializer.SerializeToStream(searchResult, memoryStream);
|
||||
|
||||
await ProviderManager.SaveToLibraryFilesystem(person, Path.Combine(person.MetaLocation, MetaFileName), memoryStream, cancellationToken);
|
||||
|
||||
Logger.Debug("TmdbPersonProvider downloaded and saved information for {0}", person.Name);
|
||||
|
||||
await FetchImages(person, searchResult.images, cancellationToken).ConfigureAwait(false);
|
||||
|
|
66
MediaBrowser.Providers/Savers/PersonXmlSaver.cs
Normal file
66
MediaBrowser.Providers/Savers/PersonXmlSaver.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Providers.Movies;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.Providers.Savers
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PersonXmlSaver
|
||||
/// </summary>
|
||||
public class PersonXmlSaver : IMetadataSaver
|
||||
{
|
||||
/// <summary>
|
||||
/// Supportses the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
public bool Supports(BaseItem item)
|
||||
{
|
||||
if (item.LocationType != LocationType.FileSystem)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return item is Person;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the specified item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public void Save(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder.Append("<Item>");
|
||||
|
||||
XmlHelpers.AddCommonNodes(item, builder);
|
||||
|
||||
builder.Append("</Item>");
|
||||
|
||||
var xmlFilePath = GetSavePath(item);
|
||||
|
||||
XmlHelpers.Save(builder, xmlFilePath);
|
||||
|
||||
// Set last refreshed so that the provider doesn't trigger after the file save
|
||||
PersonProviderFromXml.Current.SetLastRefreshed(item, DateTime.UtcNow);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the save path.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string GetSavePath(BaseItem item)
|
||||
{
|
||||
return Path.Combine(item.Path, "person.xml");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,12 +83,22 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
libraryManager.ItemUpdated += libraryManager_ItemUpdated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the ItemUpdated event of the libraryManager control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="ItemChangeEventArgs"/> instance containing the event data.</param>
|
||||
void libraryManager_ItemUpdated(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
var item = e.Item;
|
||||
|
||||
if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
|
||||
if (ConfigurationManager.Configuration.SaveLocalMeta)
|
||||
{
|
||||
if (item.LocationType != LocationType.FileSystem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var saver in _savers.Where(i => i.Supports(item)))
|
||||
{
|
||||
var path = saver.GetSavePath(item);
|
||||
|
@ -109,7 +119,6 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user