You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Providers/TV/SeasonMetadataService.cs

97 lines
3.8 KiB

using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Providers.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommonIO;
namespace MediaBrowser.Providers.TV
{
public class SeasonMetadataService : MetadataService<Season, SeasonInfo>
{
protected override async Task<ItemUpdateType> BeforeSave(Season item, bool isFullRefresh, ItemUpdateType currentUpdateType)
11 years ago
{
var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
11 years ago
if (item.IndexNumber.HasValue && item.IndexNumber.Value == 0)
{
if (!string.Equals(item.Name, ServerConfigurationManager.Configuration.SeasonZeroDisplayName, StringComparison.OrdinalIgnoreCase))
{
item.Name = ServerConfigurationManager.Configuration.SeasonZeroDisplayName;
updateType = updateType | ItemUpdateType.MetadataEdit;
}
11 years ago
}
if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
{
var episodes = item.GetEpisodes().ToList();
updateType |= SavePremiereDate(item, episodes);
9 years ago
updateType |= SaveIsVirtualItem(item, episodes);
}
if (!string.Equals(item.SeriesName, item.FindSeriesName(), StringComparison.Ordinal))
{
updateType |= ItemUpdateType.MetadataImport;
}
if (!string.Equals(item.SeriesSortName, item.FindSeriesSortName(), StringComparison.Ordinal))
{
updateType |= ItemUpdateType.MetadataImport;
}
if (item.SeriesId != item.FindSeriesId())
{
updateType |= ItemUpdateType.MetadataImport;
}
return updateType;
11 years ago
}
protected override void MergeData(MetadataResult<Season> source, MetadataResult<Season> target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
private ItemUpdateType SavePremiereDate(Season item, List<Episode> episodes)
{
var dates = episodes.Where(i => i.PremiereDate.HasValue).Select(i => i.PremiereDate.Value).ToList();
DateTime? premiereDate = null;
if (dates.Count > 0)
{
premiereDate = dates.Min();
}
if (item.PremiereDate != premiereDate)
{
item.PremiereDate = premiereDate;
return ItemUpdateType.MetadataEdit;
}
return ItemUpdateType.None;
}
9 years ago
private ItemUpdateType SaveIsVirtualItem(Season item, List<Episode> episodes)
{
9 years ago
var isVirtualItem = item.LocationType == LocationType.Virtual && (episodes.Count == 0 || episodes.All(i => i.LocationType == LocationType.Virtual));
9 years ago
if (item.IsVirtualItem != isVirtualItem)
{
9 years ago
item.IsVirtualItem = isVirtualItem;
return ItemUpdateType.MetadataEdit;
}
return ItemUpdateType.None;
}
public SeasonMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}