update artist and album fields on song changes

This commit is contained in:
Luke Pulverenti 2015-03-10 22:07:07 -04:00
parent 359f90afd4
commit f39d460f04
8 changed files with 38 additions and 22 deletions

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Users;
@ -148,12 +149,15 @@ namespace MediaBrowser.Controller.Entities.Audio
var totalItems = songs.Count + others.Count;
var numComplete = 0;
var childUpdateType = ItemUpdateType.None;
// Refresh songs
foreach (var item in songs)
{
cancellationToken.ThrowIfCancellationRequested();
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
var updateType = await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
childUpdateType = childUpdateType | updateType;
numComplete++;
double percent = numComplete;
@ -161,15 +165,22 @@ namespace MediaBrowser.Controller.Entities.Audio
progress.Report(percent * 100);
}
var parentRefreshOptions = refreshOptions;
if (childUpdateType > ItemUpdateType.None)
{
parentRefreshOptions = new MetadataRefreshOptions(refreshOptions);
parentRefreshOptions.MetadataRefreshMode = MetadataRefreshMode.FullRefresh;
}
// Refresh current item
await RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
await RefreshMetadata(parentRefreshOptions, cancellationToken).ConfigureAwait(false);
// Refresh all non-songs
foreach (var item in others)
{
cancellationToken.ThrowIfCancellationRequested();
await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false);
var updateType = await item.RefreshMetadata(parentRefreshOptions, cancellationToken).ConfigureAwait(false);
numComplete++;
double percent = numComplete;

View File

@ -717,7 +717,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="options">The options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>true if a provider reports we changed</returns>
public async Task RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken)
public async Task<ItemUpdateType> RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken)
{
var locationType = LocationType;
@ -744,15 +744,16 @@ namespace MediaBrowser.Controller.Entities
}
}
var dateLastSaved = DateLastSaved;
var refreshOptions = requiresSave
? new MetadataRefreshOptions(options)
{
ForceSave = true
}
: options;
await ProviderManager.RefreshMetadata(this, options, cancellationToken).ConfigureAwait(false);
var result = await ProviderManager.RefreshMetadata(this, refreshOptions, cancellationToken).ConfigureAwait(false);
// If it wasn't saved by the provider process, save now
if (requiresSave && dateLastSaved == DateLastSaved)
{
await UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
}
return result;
}
[IgnoreDataMember]

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Library;
using System.Threading;
@ -22,7 +23,7 @@ namespace MediaBrowser.Controller.LiveTv
bool IsParentalAllowed(User user);
Task RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken);
Task<ItemUpdateType> RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken);
PlayAccess GetPlayAccess(User user);

View File

@ -1,6 +1,7 @@
using System.Threading;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
namespace MediaBrowser.Controller.Providers
{
@ -20,7 +21,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="refreshOptions">The options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken);
Task<ItemUpdateType> RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken);
/// <summary>
/// Gets the order.

View File

@ -23,7 +23,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="options">The options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken);
Task<ItemUpdateType> RefreshMetadata(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken);
/// <summary>
/// Saves the image.

View File

@ -12,7 +12,7 @@ namespace MediaBrowser.Controller.Providers
public bool ReplaceAllMetadata { get; set; }
public bool IsPostRecursiveRefresh { get; set; }
public MetadataRefreshMode MetadataRefreshMode { get; set; }
public bool ForceSave { get; set; }
@ -28,7 +28,7 @@ namespace MediaBrowser.Controller.Providers
MetadataRefreshMode = MetadataRefreshMode.Default;
}
public MetadataRefreshOptions( MetadataRefreshOptions copy)
public MetadataRefreshOptions(MetadataRefreshOptions copy)
: base(copy.DirectoryService)
{
MetadataRefreshMode = copy.MetadataRefreshMode;

View File

@ -87,7 +87,7 @@ namespace MediaBrowser.Providers.Manager
return ProviderRepo.GetMetadataStatus(item.Id) ?? new MetadataStatus { ItemId = item.Id };
}
public async Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
public async Task<ItemUpdateType> RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{
var itemOfType = (TItemType)item;
var config = ProviderManager.GetMetadataOptions(item);
@ -184,6 +184,8 @@ namespace MediaBrowser.Providers.Manager
}
await AfterMetadataRefresh(itemOfType, refreshOptions, cancellationToken).ConfigureAwait(false);
return updateType;
}
private readonly Task _cachedTask = Task.FromResult(true);

View File

@ -108,7 +108,7 @@ namespace MediaBrowser.Providers.Manager
_externalIds = externalIds.OrderBy(i => i.Name).ToArray();
}
public Task RefreshMetadata(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken)
public Task<ItemUpdateType> RefreshMetadata(IHasMetadata item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
var service = _metadataServices.FirstOrDefault(i => i.CanRefresh(item));
@ -118,7 +118,7 @@ namespace MediaBrowser.Providers.Manager
}
_logger.Error("Unable to find a metadata service for item of type " + item.GetType().Name);
return Task.FromResult(true);
return Task.FromResult(ItemUpdateType.None);
}
public async Task SaveImage(IHasImages item, string url, SemaphoreSlim resourcePool, ImageType type, int? imageIndex, CancellationToken cancellationToken)