get album images from songs before internet

This commit is contained in:
Luke Pulverenti 2014-02-06 19:43:45 -05:00
parent 4462323948
commit 65903c56de
13 changed files with 144 additions and 18 deletions

View File

@ -63,18 +63,24 @@ namespace MediaBrowser.Providers.Manager
var backdropLimit = item.HasImage(ImageType.Backdrop) ? 0 : savedOptions.GetLimit(ImageType.Backdrop);
var screenshotLimit = item.HasImage(ImageType.Screenshot) ? 0 : savedOptions.GetLimit(ImageType.Screenshot);
foreach (var provider in providers.OfType<IRemoteImageProvider>())
foreach (var provider in providers)
{
await RefreshFromProvider(item, provider, refreshOptions, savedOptions, backdropLimit, screenshotLimit, result, cancellationToken).ConfigureAwait(false);
var remoteProvider = provider as IRemoteImageProvider;
providerIds.Add(provider.GetType().FullName.GetMD5());
}
if (remoteProvider != null)
{
await RefreshFromProvider(item, remoteProvider, refreshOptions, savedOptions, backdropLimit, screenshotLimit, result, cancellationToken).ConfigureAwait(false);
providerIds.Add(provider.GetType().FullName.GetMD5());
continue;
}
foreach (var provider in providers.OfType<IDynamicImageProvider>())
{
await RefreshFromProvider(item, provider, savedOptions, result, cancellationToken).ConfigureAwait(false);
var dynamicImageProvider = provider as IDynamicImageProvider;
providerIds.Add(provider.GetType().FullName.GetMD5());
if (dynamicImageProvider != null)
{
await RefreshFromProvider(item, dynamicImageProvider, savedOptions, result, cancellationToken).ConfigureAwait(false);
providerIds.Add(provider.GetType().FullName.GetMD5());
}
}
result.Providers = providerIds;

View File

@ -110,6 +110,7 @@
<Compile Include="Movies\MovieDbImageProvider.cs" />
<Compile Include="Movies\FanartMovieImageProvider.cs" />
<Compile Include="MusicGenres\MusicGenreMetadataService.cs" />
<Compile Include="Music\AlbumImageFromSongProvider.cs" />
<Compile Include="Music\AlbumMetadataService.cs" />
<Compile Include="Music\ArtistMetadataService.cs" />
<Compile Include="Music\AudioMetadataService.cs" />

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace MediaBrowser.Providers.MediaInfo
{
public class VideoImageProvider : IDynamicImageProvider, IHasChangeMonitor
public class VideoImageProvider : IDynamicImageProvider, IHasChangeMonitor, IHasOrder
{
private readonly IIsoManager _isoManager;
private readonly IMediaEncoder _mediaEncoder;
@ -130,5 +130,14 @@ namespace MediaBrowser.Providers.MediaInfo
{
return item.DateModified > date;
}
public int Order
{
get
{
// Make sure this comes after internet image providers
return 100;
}
}
}
}

View File

@ -346,6 +346,11 @@ namespace MediaBrowser.Providers.Movies
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableFanArtUpdates)
{
return false;
}
var id = item.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrEmpty(id))
@ -355,7 +360,7 @@ namespace MediaBrowser.Providers.Movies
var fileInfo = new FileInfo(xmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;

View File

@ -5,6 +5,7 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
@ -18,7 +19,7 @@ namespace MediaBrowser.Providers.Movies
/// <summary>
/// Class MovieDbProvider
/// </summary>
public class MovieDbProvider : IRemoteMetadataProvider<Movie>, IDisposable
public class MovieDbProvider : IRemoteMetadataProvider<Movie>, IDisposable, IHasChangeMonitor
{
internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(1, 1);
@ -314,6 +315,28 @@ namespace MediaBrowser.Providers.Movies
}
}
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_configurationManager.Configuration.EnableTmdbUpdates)
{
return false;
}
var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);
if (!String.IsNullOrEmpty(tmdbId))
{
// Process images
var dataFilePath = GetDataFilePath(tmdbId, item.GetPreferredMetadataLanguage());
var fileInfo = new FileInfo(dataFilePath);
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;
}
public void Dispose()
{
Dispose(true);

View File

@ -0,0 +1,44 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
public class AlbumImageFromSongProvider : IDynamicImageProvider
{
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
{
return new List<ImageType> { ImageType.Primary };
}
public Task<DynamicImageResponse> GetImage(IHasImages item, ImageType type, CancellationToken cancellationToken)
{
var album = (MusicAlbum)item;
var image = album.RecursiveChildren.OfType<Audio>()
.Select(i => i.GetImagePath(type))
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
return Task.FromResult(new DynamicImageResponse
{
Path = image,
HasImage = !string.IsNullOrEmpty(image)
});
}
public string Name
{
get { return "Embedded Image"; }
}
public bool Supports(IHasImages item)
{
return item is MusicAlbum;
}
}
}

View File

@ -340,7 +340,11 @@ namespace MediaBrowser.Providers.Music
public int Order
{
get { return 0; }
get
{
// After embedded provider
return 1;
}
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
@ -355,6 +359,11 @@ namespace MediaBrowser.Providers.Music
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableFanArtUpdates)
{
return false;
}
var album = (MusicAlbum)item;
var artistMusicBrainzId = album.Parent.GetProviderId(MetadataProviders.Musicbrainz);
@ -366,7 +375,7 @@ namespace MediaBrowser.Providers.Music
var fileInfo = new FileInfo(artistXmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;

View File

@ -376,6 +376,11 @@ namespace MediaBrowser.Providers.Music
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableFanArtUpdates)
{
return false;
}
var id = item.GetProviderId(MetadataProviders.Musicbrainz);
if (!String.IsNullOrEmpty(id))
@ -385,7 +390,7 @@ namespace MediaBrowser.Providers.Music
var fileInfo = new FileInfo(artistXmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;

View File

@ -189,7 +189,11 @@ namespace MediaBrowser.Providers.Music
public int Order
{
get { return 1; }
get
{
// After embedded provider and fanart
return 2;
}
}
}

View File

@ -277,6 +277,11 @@ namespace MediaBrowser.Providers.TV
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableFanArtUpdates)
{
return false;
}
var season = (Season)item;
var series = season.Series;
@ -294,7 +299,7 @@ namespace MediaBrowser.Providers.TV
var fileInfo = new FileInfo(imagesXmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;

View File

@ -425,6 +425,11 @@ namespace MediaBrowser.Providers.TV
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableFanArtUpdates)
{
return false;
}
var tvdbId = item.GetProviderId(MetadataProviders.Tvdb);
if (!String.IsNullOrEmpty(tvdbId))
@ -434,7 +439,7 @@ namespace MediaBrowser.Providers.TV
var fileInfo = new FileInfo(imagesXmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > date;
}
return false;

View File

@ -70,6 +70,11 @@ namespace MediaBrowser.Providers.TV
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableTvDbUpdates)
{
return false;
}
var episode = (Episode)item;
var series = episode.Series;

View File

@ -1082,6 +1082,11 @@ namespace MediaBrowser.Providers.TV
public bool HasChanged(IHasMetadata item, DateTime date)
{
if (!_config.Configuration.EnableTvDbUpdates)
{
return false;
}
var seriesId = item.GetProviderId(MetadataProviders.Tvdb);
if (!string.IsNullOrEmpty(seriesId))
@ -1094,7 +1099,7 @@ namespace MediaBrowser.Providers.TV
var seriesFile = new FileInfo(filePath);
if (seriesFile.Exists && _fileSystem.GetLastWriteTimeUtc(seriesFile) > date)
if (!seriesFile.Exists || _fileSystem.GetLastWriteTimeUtc(seriesFile) > date)
{
return true;
}