jellyfin/MediaBrowser.Providers/BoxSets/BoxSetMetadataService.cs

84 lines
3.5 KiB
C#
Raw Normal View History

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