mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-05 21:37:10 -04:00
Add FanArtAlbumProvider
This commit is contained in:
parent
09ec5670aa
commit
d433ea5bf9
@ -108,6 +108,7 @@
|
||||
<Compile Include="IServerApplicationPaths.cs" />
|
||||
<Compile Include="Library\ChildrenChangedEventArgs.cs" />
|
||||
<Compile Include="Library\DtoBuilder.cs" />
|
||||
<Compile Include="Providers\Music\FanArtAlbumProvider.cs" />
|
||||
<Compile Include="Providers\Music\FanArtArtistProvider.cs" />
|
||||
<Compile Include="Providers\Music\LastfmArtistProvider.cs" />
|
||||
<Compile Include="Providers\Music\LastfmHelper.cs" />
|
||||
|
@ -7,6 +7,14 @@ using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
class FanArtProviderException : ApplicationException
|
||||
{
|
||||
public FanArtProviderException(string msg)
|
||||
: base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Class FanartBaseProvider
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers.Music
|
||||
{
|
||||
public class FanArtAlbumProvider : FanartBaseProvider
|
||||
{
|
||||
public FanArtAlbumProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is MusicAlbum && item.Parent is MusicArtist;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if we need refreshing, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
//we fetch if image needed and haven't already tried recently
|
||||
return string.IsNullOrEmpty(item.PrimaryImagePath) &&
|
||||
DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays;
|
||||
}
|
||||
|
||||
protected override async Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
var mbid = item.GetProviderId(MetadataProviders.Musicbrainz);
|
||||
if (mbid == null)
|
||||
{
|
||||
Logger.Warn("No Musicbrainz id associated with album {0}", item.Name);
|
||||
SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.CompletedWithErrors);
|
||||
return false;
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
//Look at our parent for our album cover
|
||||
var artist = (MusicArtist)item.Parent;
|
||||
var cover = artist.AlbumCovers != null ? artist.AlbumCovers.GetValueOrDefault(mbid, null) : null;
|
||||
if (cover == null)
|
||||
{
|
||||
// Not there - maybe it is new since artist last refreshed so refresh it and try again
|
||||
await artist.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
cover = artist.AlbumCovers != null ? artist.AlbumCovers.GetValueOrDefault(mbid, null) : null;
|
||||
}
|
||||
if (cover == null)
|
||||
{
|
||||
Logger.Warn("Unable to find cover art for {0}", item.Name);
|
||||
SetLastRefreshed(item, DateTime.UtcNow, ProviderRefreshStatus.CompletedWithErrors);
|
||||
return false;
|
||||
}
|
||||
|
||||
item.SetImage(ImageType.Primary, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, cover, "folder.jpg", FanArtResourcePool, cancellationToken).ConfigureAwait(false));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user