2014-05-31 20:19:06 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-02-02 12:31:56 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2014-01-28 11:37:01 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-05-31 20:19:06 -07:00
|
|
|
|
using System;
|
2014-01-28 11:37:01 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2014-02-08 13:02:35 -07:00
|
|
|
|
namespace MediaBrowser.Providers.Manager
|
2014-01-28 11:37:01 -07:00
|
|
|
|
{
|
|
|
|
|
public static class ProviderUtils
|
|
|
|
|
{
|
|
|
|
|
public static void MergeBaseItemData(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
|
|
|
|
|
{
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Name))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.Name))
|
|
|
|
|
{
|
2014-05-31 20:19:06 -07:00
|
|
|
|
// Safeguard against incoming data having an emtpy name
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(source.Name))
|
|
|
|
|
{
|
|
|
|
|
target.Name = source.Name;
|
|
|
|
|
}
|
2014-01-28 11:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.CommunityRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.CommunityRating = source.CommunityRating;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.EndDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.EndDate = source.EndDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Genres))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || target.Genres.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
target.Genres = source.Genres;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.HomePageUrl))
|
|
|
|
|
{
|
|
|
|
|
target.HomePageUrl = source.HomePageUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.IndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.IndexNumber = source.IndexNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.OfficialRating))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.OfficialRating))
|
|
|
|
|
{
|
|
|
|
|
target.OfficialRating = source.OfficialRating;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.OfficialRatingDescription))
|
|
|
|
|
{
|
|
|
|
|
target.OfficialRatingDescription = source.OfficialRatingDescription;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-01 10:53:56 -07:00
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.CustomRating))
|
|
|
|
|
{
|
|
|
|
|
target.CustomRating = source.CustomRating;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 11:37:01 -07:00
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(target.Overview))
|
|
|
|
|
{
|
|
|
|
|
target.Overview = source.Overview;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.ParentIndexNumber.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.ParentIndexNumber = source.ParentIndexNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || target.People.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
target.People = source.People;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.PremiereDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.PremiereDate = source.PremiereDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !target.ProductionYear.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.ProductionYear = source.ProductionYear;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Runtime))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || !target.RunTimeTicks.HasValue)
|
|
|
|
|
{
|
2014-02-05 21:39:16 -07:00
|
|
|
|
if (!(target is Audio) && !(target is Video))
|
|
|
|
|
{
|
|
|
|
|
target.RunTimeTicks = source.RunTimeTicks;
|
|
|
|
|
}
|
2014-01-28 11:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Studios))
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || target.Studios.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
target.Studios = source.Studios;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 21:50:09 -07:00
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Tags))
|
|
|
|
|
{
|
|
|
|
|
var sourceHasTags = source as IHasTags;
|
|
|
|
|
var targetHasTags = target as IHasTags;
|
|
|
|
|
|
|
|
|
|
if (sourceHasTags != null && targetHasTags != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || targetHasTags.Tags.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
targetHasTags.Tags = sourceHasTags.Tags;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.Keywords))
|
|
|
|
|
{
|
|
|
|
|
var sourceHasKeywords = source as IHasKeywords;
|
|
|
|
|
var targetHasKeywords = target as IHasKeywords;
|
|
|
|
|
|
|
|
|
|
if (sourceHasKeywords != null && targetHasKeywords != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || targetHasKeywords.Keywords.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
targetHasKeywords.Keywords = sourceHasKeywords.Keywords;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lockedFields.Contains(MetadataFields.ProductionLocations))
|
|
|
|
|
{
|
|
|
|
|
var sourceHasProductionLocations = source as IHasProductionLocations;
|
|
|
|
|
var targetHasProductionLocations = target as IHasProductionLocations;
|
|
|
|
|
|
|
|
|
|
if (sourceHasProductionLocations != null && targetHasProductionLocations != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || targetHasProductionLocations.ProductionLocations.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
targetHasProductionLocations.ProductionLocations = sourceHasProductionLocations.ProductionLocations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 11:37:01 -07:00
|
|
|
|
if (replaceData || !target.VoteCount.HasValue)
|
|
|
|
|
{
|
|
|
|
|
target.VoteCount = source.VoteCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var id in source.ProviderIds)
|
|
|
|
|
{
|
2014-02-12 22:11:54 -07:00
|
|
|
|
var key = id.Key;
|
|
|
|
|
|
|
|
|
|
// Don't replace existing Id's.
|
|
|
|
|
if (!target.ProviderIds.ContainsKey(key))
|
|
|
|
|
{
|
|
|
|
|
target.ProviderIds[key] = id.Value;
|
|
|
|
|
}
|
2014-01-28 11:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 12:31:56 -07:00
|
|
|
|
MergeAlbumArtist(source, target, lockedFields, replaceData);
|
2014-02-04 13:19:29 -07:00
|
|
|
|
MergeBudget(source, target, lockedFields, replaceData);
|
2014-02-05 21:39:16 -07:00
|
|
|
|
MergeMetascore(source, target, lockedFields, replaceData);
|
|
|
|
|
MergeCriticRating(source, target, lockedFields, replaceData);
|
|
|
|
|
MergeAwards(source, target, lockedFields, replaceData);
|
|
|
|
|
MergeTaglines(source, target, lockedFields, replaceData);
|
|
|
|
|
MergeTrailers(source, target, lockedFields, replaceData);
|
2014-06-23 21:18:02 -07:00
|
|
|
|
MergeShortOverview(source, target, lockedFields, replaceData);
|
2014-02-02 12:31:56 -07:00
|
|
|
|
|
2014-01-28 11:37:01 -07:00
|
|
|
|
if (mergeMetadataSettings)
|
|
|
|
|
{
|
|
|
|
|
target.ForcedSortName = source.ForcedSortName;
|
|
|
|
|
target.LockedFields = source.LockedFields;
|
2014-04-26 20:42:05 -07:00
|
|
|
|
target.IsLocked = source.IsLocked;
|
2014-01-28 11:37:01 -07:00
|
|
|
|
target.DisplayMediaType = source.DisplayMediaType;
|
2014-01-30 21:50:09 -07:00
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
// Grab the value if it's there, but if not then don't overwrite the default
|
|
|
|
|
if (source.DateCreated != default(DateTime))
|
|
|
|
|
{
|
|
|
|
|
target.DateCreated = source.DateCreated;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 21:50:09 -07:00
|
|
|
|
var sourceHasLanguageSettings = source as IHasPreferredMetadataLanguage;
|
|
|
|
|
var targetHasLanguageSettings = target as IHasPreferredMetadataLanguage;
|
|
|
|
|
|
|
|
|
|
if (sourceHasLanguageSettings != null && targetHasLanguageSettings != null)
|
|
|
|
|
{
|
|
|
|
|
targetHasLanguageSettings.PreferredMetadataCountryCode = sourceHasLanguageSettings.PreferredMetadataCountryCode;
|
|
|
|
|
targetHasLanguageSettings.PreferredMetadataLanguage = sourceHasLanguageSettings.PreferredMetadataLanguage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sourceHasDisplayOrder = source as IHasDisplayOrder;
|
|
|
|
|
var targetHasDisplayOrder = target as IHasDisplayOrder;
|
|
|
|
|
|
|
|
|
|
if (sourceHasDisplayOrder != null && targetHasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
targetHasDisplayOrder.DisplayOrder = sourceHasDisplayOrder.DisplayOrder;
|
|
|
|
|
}
|
2014-01-28 11:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-02 12:31:56 -07:00
|
|
|
|
|
2014-06-23 21:18:02 -07:00
|
|
|
|
private static void MergeShortOverview(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceHasShortOverview = source as IHasShortOverview;
|
|
|
|
|
var targetHasShortOverview = target as IHasShortOverview;
|
|
|
|
|
|
|
|
|
|
if (sourceHasShortOverview != null && targetHasShortOverview != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(targetHasShortOverview.ShortOverview))
|
|
|
|
|
{
|
|
|
|
|
targetHasShortOverview.ShortOverview = sourceHasShortOverview.ShortOverview;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 12:31:56 -07:00
|
|
|
|
private static void MergeAlbumArtist(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceHasAlbumArtist = source as IHasAlbumArtist;
|
|
|
|
|
var targetHasAlbumArtist = target as IHasAlbumArtist;
|
|
|
|
|
|
|
|
|
|
if (sourceHasAlbumArtist != null && targetHasAlbumArtist != null)
|
|
|
|
|
{
|
2014-06-23 09:05:19 -07:00
|
|
|
|
if (replaceData || targetHasAlbumArtist.AlbumArtists.Count > 0)
|
2014-02-02 12:31:56 -07:00
|
|
|
|
{
|
2014-06-23 09:05:19 -07:00
|
|
|
|
targetHasAlbumArtist.AlbumArtists = sourceHasAlbumArtist.AlbumArtists;
|
2014-02-02 12:31:56 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-04 13:19:29 -07:00
|
|
|
|
|
|
|
|
|
private static void MergeBudget(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceHasBudget = source as IHasBudget;
|
|
|
|
|
var targetHasBudget = target as IHasBudget;
|
|
|
|
|
|
|
|
|
|
if (sourceHasBudget != null && targetHasBudget != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || !targetHasBudget.Budget.HasValue)
|
|
|
|
|
{
|
|
|
|
|
targetHasBudget.Budget = sourceHasBudget.Budget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || !targetHasBudget.Revenue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
targetHasBudget.Revenue = sourceHasBudget.Revenue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-05 21:39:16 -07:00
|
|
|
|
|
|
|
|
|
private static void MergeMetascore(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceCast = source as IHasMetascore;
|
|
|
|
|
var targetCast = target as IHasMetascore;
|
|
|
|
|
|
|
|
|
|
if (sourceCast != null && targetCast != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || !targetCast.Metascore.HasValue)
|
|
|
|
|
{
|
|
|
|
|
targetCast.Metascore = sourceCast.Metascore;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void MergeAwards(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceCast = source as IHasAwards;
|
|
|
|
|
var targetCast = target as IHasAwards;
|
|
|
|
|
|
|
|
|
|
if (sourceCast != null && targetCast != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(targetCast.AwardSummary))
|
|
|
|
|
{
|
|
|
|
|
targetCast.AwardSummary = sourceCast.AwardSummary;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void MergeCriticRating(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceCast = source as IHasCriticRating;
|
|
|
|
|
var targetCast = target as IHasCriticRating;
|
|
|
|
|
|
|
|
|
|
if (sourceCast != null && targetCast != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || !targetCast.CriticRating.HasValue)
|
|
|
|
|
{
|
|
|
|
|
targetCast.CriticRating = sourceCast.CriticRating;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (replaceData || string.IsNullOrEmpty(targetCast.CriticRatingSummary))
|
|
|
|
|
{
|
|
|
|
|
targetCast.CriticRatingSummary = sourceCast.CriticRatingSummary;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void MergeTaglines(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceCast = source as IHasTaglines;
|
|
|
|
|
var targetCast = target as IHasTaglines;
|
|
|
|
|
|
|
|
|
|
if (sourceCast != null && targetCast != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || targetCast.Taglines.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
targetCast.Taglines = sourceCast.Taglines;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void MergeTrailers(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData)
|
|
|
|
|
{
|
|
|
|
|
var sourceCast = source as IHasTrailers;
|
|
|
|
|
var targetCast = target as IHasTrailers;
|
|
|
|
|
|
|
|
|
|
if (sourceCast != null && targetCast != null)
|
|
|
|
|
{
|
|
|
|
|
if (replaceData || targetCast.RemoteTrailers.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
targetCast.RemoteTrailers = sourceCast.RemoteTrailers;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 11:37:01 -07:00
|
|
|
|
}
|
|
|
|
|
}
|