added a tvdb image provider for people
This commit is contained in:
parent
b02a1c7e76
commit
d5bfdd7988
|
@ -103,6 +103,7 @@
|
||||||
<Compile Include="TV\SeasonProviderFromXml.cs" />
|
<Compile Include="TV\SeasonProviderFromXml.cs" />
|
||||||
<Compile Include="TV\SeriesProviderFromXml.cs" />
|
<Compile Include="TV\SeriesProviderFromXml.cs" />
|
||||||
<Compile Include="TV\SeriesXmlParser.cs" />
|
<Compile Include="TV\SeriesXmlParser.cs" />
|
||||||
|
<Compile Include="TV\TvdbPersonImageProvider.cs" />
|
||||||
<Compile Include="TV\TvdbPrescanTask.cs" />
|
<Compile Include="TV\TvdbPrescanTask.cs" />
|
||||||
<Compile Include="TV\TvdbSeriesImageProvider.cs" />
|
<Compile Include="TV\TvdbSeriesImageProvider.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
127
MediaBrowser.Providers/TV/TvdbPersonImageProvider.cs
Normal file
127
MediaBrowser.Providers/TV/TvdbPersonImageProvider.cs
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Providers.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Providers.TV
|
||||||
|
{
|
||||||
|
public class TvdbPersonImageProvider : BaseMetadataProvider
|
||||||
|
{
|
||||||
|
private readonly ILibraryManager _library;
|
||||||
|
private readonly IProviderManager _providerManager;
|
||||||
|
|
||||||
|
public TvdbPersonImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, ILibraryManager library, IProviderManager providerManager)
|
||||||
|
: base(logManager, configurationManager)
|
||||||
|
{
|
||||||
|
_library = library;
|
||||||
|
_providerManager = providerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Supports(BaseItem item)
|
||||||
|
{
|
||||||
|
return item is Person;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||||
|
/// </summary>
|
||||||
|
/// <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, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(item.PrimaryImagePath))
|
||||||
|
{
|
||||||
|
var seriesWithPerson = _library.RootFolder
|
||||||
|
.RecursiveChildren
|
||||||
|
.OfType<Series>()
|
||||||
|
.Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)) && i.People.Any(p => string.Equals(p.Name, item.Name, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var series in seriesWithPerson)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await DownloadImageFromSeries(item, series, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
// No biggie
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// break once we have an image
|
||||||
|
if (!string.IsNullOrEmpty(item.PrimaryImagePath))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLastRefreshed(item, DateTime.UtcNow);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Downloads the image from series.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="item">The item.</param>
|
||||||
|
/// <param name="series">The series.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
private async Task DownloadImageFromSeries(BaseItem item, Series series, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var tvdbPath = RemoteSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, series.GetProviderId(MetadataProviders.Tvdb));
|
||||||
|
|
||||||
|
var actorXmlPath = Path.Combine(tvdbPath, "actors.xml");
|
||||||
|
|
||||||
|
var xmlDoc = new XmlDocument();
|
||||||
|
|
||||||
|
xmlDoc.Load(actorXmlPath);
|
||||||
|
|
||||||
|
var actorNodes = xmlDoc.SelectNodes("//Actor");
|
||||||
|
|
||||||
|
if (actorNodes == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var actorNode in actorNodes.OfType<XmlNode>())
|
||||||
|
{
|
||||||
|
var name = actorNode.SafeGetString("Name");
|
||||||
|
|
||||||
|
if (string.Equals(item.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var image = actorNode.SafeGetString("Image");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(image))
|
||||||
|
{
|
||||||
|
var url = TVUtils.BannerUrl + image;
|
||||||
|
|
||||||
|
await _providerManager.SaveImage(item, url, RemoteSeriesProvider.Current.TvDbResourcePool,
|
||||||
|
ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override MetadataProviderPriority Priority
|
||||||
|
{
|
||||||
|
get { return MetadataProviderPriority.Third; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -237,4 +237,7 @@ Global
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(Performance) = preSolution
|
||||||
|
HasPerformanceSessions = true
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
Loading…
Reference in New Issue
Block a user