2014-02-02 06:36:31 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
using MediaBrowser.Controller.Localization;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Providers.Manager;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
using System;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
using System.Collections.Generic;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
using System.Linq;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.BoxSets
|
|
|
|
|
{
|
2014-02-06 20:10:13 -07:00
|
|
|
|
public class BoxSetMetadataService : MetadataService<BoxSet, ItemLookupInfo>
|
2014-01-30 14:23:54 -07:00
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
private readonly ILocalizationManager _iLocalizationManager;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
|
2014-02-02 06:36:31 -07:00
|
|
|
|
public BoxSetMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IProviderRepository providerRepo, IFileSystem fileSystem, ILibraryManager libraryManager, ILocalizationManager iLocalizationManager)
|
|
|
|
|
: base(serverConfigurationManager, logger, providerManager, providerRepo, fileSystem)
|
2014-01-30 14:23:54 -07:00
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
_iLocalizationManager = iLocalizationManager;
|
2014-01-30 14:23:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Merges the specified source.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="source">The source.</param>
|
|
|
|
|
/// <param name="target">The target.</param>
|
|
|
|
|
/// <param name="lockedFields">The locked fields.</param>
|
|
|
|
|
/// <param name="replaceData">if set to <c>true</c> [replace data].</param>
|
2014-02-02 06:36:31 -07:00
|
|
|
|
/// <param name="mergeMetadataSettings">if set to <c>true</c> [merge metadata settings].</param>
|
2014-01-30 14:23:54 -07:00
|
|
|
|
protected override void MergeData(BoxSet source, BoxSet target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
|
|
|
|
|
{
|
|
|
|
|
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 21:04:19 -07:00
|
|
|
|
protected override ItemUpdateType BeforeSave(BoxSet item)
|
2014-01-30 21:50:09 -07:00
|
|
|
|
{
|
2014-02-03 21:04:19 -07:00
|
|
|
|
var updateType = base.BeforeSave(item);
|
2014-01-30 21:50:09 -07:00
|
|
|
|
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.OfficialRating))
|
|
|
|
|
{
|
|
|
|
|
var currentOfficialRating = item.OfficialRating;
|
|
|
|
|
|
|
|
|
|
// Gather all possible ratings
|
|
|
|
|
var ratings = item.RecursiveChildren
|
|
|
|
|
.Concat(item.GetLinkedChildren())
|
|
|
|
|
.Where(i => i is Movie || i is Series)
|
|
|
|
|
.Select(i => i.OfficialRating)
|
|
|
|
|
.Where(i => !string.IsNullOrEmpty(i))
|
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
|
|
|
|
.Select(i => new Tuple<string, int?>(i, _iLocalizationManager.GetRatingLevel(i)))
|
|
|
|
|
.OrderBy(i => i.Item2 ?? 1000)
|
|
|
|
|
.Select(i => i.Item1);
|
|
|
|
|
|
|
|
|
|
item.OfficialRating = ratings.FirstOrDefault() ?? item.OfficialRating;
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(currentOfficialRating ?? string.Empty, item.OfficialRating ?? string.Empty,
|
|
|
|
|
StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
updateType = updateType | ItemUpdateType.MetadataDownload;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return updateType;
|
|
|
|
|
}
|
2014-01-30 14:23:54 -07:00
|
|
|
|
}
|
|
|
|
|
}
|