have manual person image provider download data if not already present

This commit is contained in:
Luke Pulverenti 2013-12-02 10:47:24 -05:00
parent ad52d8b5d9
commit 81c23ed183
4 changed files with 46 additions and 111 deletions

View File

@ -89,7 +89,6 @@
<Compile Include="Music\LastfmArtistProvider.cs" /> <Compile Include="Music\LastfmArtistProvider.cs" />
<Compile Include="Music\LastfmBaseProvider.cs" /> <Compile Include="Music\LastfmBaseProvider.cs" />
<Compile Include="Music\LastfmHelper.cs" /> <Compile Include="Music\LastfmHelper.cs" />
<Compile Include="Music\AlbumDynamicInfoProvider.cs" />
<Compile Include="Music\ManualFanartAlbumProvider.cs" /> <Compile Include="Music\ManualFanartAlbumProvider.cs" />
<Compile Include="Music\ManualFanartArtistProvider.cs" /> <Compile Include="Music\ManualFanartArtistProvider.cs" />
<Compile Include="Music\ManualLastFmImageProvider.cs" /> <Compile Include="Music\ManualLastFmImageProvider.cs" />

View File

@ -46,7 +46,12 @@ namespace MediaBrowser.Providers.Movies
return images.Where(i => i.Type == imageType); return images.Where(i => i.Type == imageType);
} }
public async Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken) public Task<IEnumerable<RemoteImageInfo>> GetAllImages(BaseItem item, CancellationToken cancellationToken)
{
return GetAllImagesInternal(item, true, cancellationToken);
}
public async Task<IEnumerable<RemoteImageInfo>> GetAllImagesInternal(BaseItem item, bool retryOnMissingData, CancellationToken cancellationToken)
{ {
var id = item.GetProviderId(MetadataProviders.Tmdb); var id = item.GetProviderId(MetadataProviders.Tmdb);
@ -70,11 +75,18 @@ namespace MediaBrowser.Providers.Movies
{ {
} }
if (retryOnMissingData)
{
await MovieDbPersonProvider.Current.DownloadPersonInfo(id, cancellationToken).ConfigureAwait(false);
return await GetAllImagesInternal(item, false, cancellationToken).ConfigureAwait(false);
}
} }
return new List<RemoteImageInfo>(); return new List<RemoteImageInfo>();
} }
private IEnumerable<RemoteImageInfo> GetImages(MovieDbPersonProvider.Images images, string baseImageUrl) private IEnumerable<RemoteImageInfo> GetImages(MovieDbPersonProvider.Images images, string baseImageUrl)
{ {
var list = new List<RemoteImageInfo>(); var list = new List<RemoteImageInfo>();

View File

@ -1,103 +0,0 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
/// <summary>
/// Class MusicAlbumDynamicInfoProvider
/// </summary>
public class AlbumDynamicInfoProvider : BaseMetadataProvider, IDynamicInfoProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="BaseMetadataProvider" /> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
public AlbumDynamicInfoProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
: base(logManager, configurationManager)
{
}
/// <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 MusicAlbum;
}
/// <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)
{
return true;
}
/// <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 Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
var album = (MusicAlbum)item;
var songs = album.RecursiveChildren
.OfType<Audio>()
.ToList();
album.AlbumArtist = songs
.Select(i => i.AlbumArtist)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
album.Artists = songs.SelectMany(i => i.Artists)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
var date = songs.Select(i => i.PremiereDate)
.FirstOrDefault(i => i.HasValue);
if (date.HasValue)
{
album.PremiereDate = date.Value;
album.ProductionYear = date.Value.Year;
}
else
{
var year = songs.Select(i => i.ProductionYear ?? 1800).FirstOrDefault(i => i != 1800);
if (year != 1800)
{
album.ProductionYear = year;
}
}
// Don't save to the db
return FalseTaskResult;
}
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.Last; }
}
}
}

View File

@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Music
{ {
get get
{ {
return "1"; return "2";
} }
} }
@ -65,7 +65,7 @@ namespace MediaBrowser.Providers.Music
private Guid GetComparisonData(List<Audio> songs) private Guid GetComparisonData(List<Audio> songs)
{ {
var albumNames = songs.Select(i => i.AlbumArtist) var albumArtistNames = songs.Select(i => i.AlbumArtist)
.Where(i => !string.IsNullOrEmpty(i)) .Where(i => !string.IsNullOrEmpty(i))
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
@ -78,10 +78,10 @@ namespace MediaBrowser.Providers.Music
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
albumNames.AddRange(studios); albumArtistNames.AddRange(studios);
albumNames.AddRange(genres); albumArtistNames.AddRange(genres);
return string.Join(string.Empty, albumNames.OrderBy(i => i).ToArray()).GetMD5(); return string.Join(string.Empty, albumArtistNames.OrderBy(i => i).ToArray()).GetMD5();
} }
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
@ -119,7 +119,34 @@ namespace MediaBrowser.Providers.Music
album.Genres = songs.SelectMany(i => i.Genres) album.Genres = songs.SelectMany(i => i.Genres)
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.ToList(); .ToList();
}
album.AlbumArtist = songs
.Select(i => i.AlbumArtist)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
album.Artists = songs.SelectMany(i => i.Artists)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
var date = songs.Select(i => i.PremiereDate)
.FirstOrDefault(i => i.HasValue);
if (date.HasValue)
{
album.PremiereDate = date.Value;
album.ProductionYear = date.Value.Year;
} }
else
{
var year = songs.Select(i => i.ProductionYear ?? 1800).FirstOrDefault(i => i != 1800);
if (year != 1800)
{
album.ProductionYear = year;
}
}
data.FileStamp = GetComparisonData(songs); data.FileStamp = GetComparisonData(songs);