2014-02-02 08:36:31 -05:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-03-07 13:48:55 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
using MediaBrowser.Controller.Localization;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Providers.Manager;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
using System;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
using System.Collections.Generic;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
using System.Linq;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.BoxSets
|
|
|
|
|
{
|
2014-02-08 17:38:02 -05:00
|
|
|
|
public class BoxSetMetadataService : MetadataService<BoxSet, BoxSetInfo>
|
2014-01-30 16:23:54 -05:00
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
private readonly ILocalizationManager _iLocalizationManager;
|
2014-01-30 16:23:54 -05:00
|
|
|
|
|
2014-02-02 08:36:31 -05: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 16:23:54 -05:00
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
2014-01-30 23:50:09 -05:00
|
|
|
|
_iLocalizationManager = iLocalizationManager;
|
2014-01-30 16:23:54 -05: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 08:36:31 -05:00
|
|
|
|
/// <param name="mergeMetadataSettings">if set to <c>true</c> [merge metadata settings].</param>
|
2014-01-30 16:23:54 -05:00
|
|
|
|
protected override void MergeData(BoxSet source, BoxSet target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
|
|
|
|
|
{
|
|
|
|
|
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
|
2014-03-07 13:48:55 -05:00
|
|
|
|
|
|
|
|
|
if (mergeMetadataSettings)
|
|
|
|
|
{
|
|
|
|
|
var list = source.LinkedChildren.ToList();
|
|
|
|
|
|
|
|
|
|
list.AddRange(target.LinkedChildren.Where(i => i.Type == LinkedChildType.Shortcut));
|
|
|
|
|
|
|
|
|
|
target.LinkedChildren = list;
|
|
|
|
|
}
|
2014-01-30 16:23:54 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 23:04:19 -05:00
|
|
|
|
protected override ItemUpdateType BeforeSave(BoxSet item)
|
2014-01-30 23:50:09 -05:00
|
|
|
|
{
|
2014-02-03 23:04:19 -05:00
|
|
|
|
var updateType = base.BeforeSave(item);
|
2014-01-30 23:50:09 -05: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 16:23:54 -05:00
|
|
|
|
}
|
|
|
|
|
}
|