|
|
@ -1,4 +1,5 @@
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
@ -20,26 +21,27 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public bool IsMultiPart { get; set; }
|
|
|
|
public bool IsMultiPart { get; set; }
|
|
|
|
public bool HasLocalAlternateVersions { get; set; }
|
|
|
|
public bool HasLocalAlternateVersions { get; set; }
|
|
|
|
|
|
|
|
public Guid? PrimaryVersionId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public List<Guid> AdditionalPartIds { get; set; }
|
|
|
|
public List<Guid> AdditionalPartIds { get; set; }
|
|
|
|
public List<Guid> AlternateVersionIds { get; set; }
|
|
|
|
public List<Guid> LocalAlternateVersionIds { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public Video()
|
|
|
|
public Video()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PlayableStreamFileNames = new List<string>();
|
|
|
|
PlayableStreamFileNames = new List<string>();
|
|
|
|
AdditionalPartIds = new List<Guid>();
|
|
|
|
AdditionalPartIds = new List<Guid>();
|
|
|
|
AlternateVersionIds = new List<Guid>();
|
|
|
|
LocalAlternateVersionIds = new List<Guid>();
|
|
|
|
Tags = new List<string>();
|
|
|
|
Tags = new List<string>();
|
|
|
|
SubtitleFiles = new List<string>();
|
|
|
|
SubtitleFiles = new List<string>();
|
|
|
|
LinkedAlternateVersions = new List<LinkedChild>();
|
|
|
|
LinkedAlternateVersions = new List<LinkedChild>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
[IgnoreDataMember]
|
|
|
|
public bool HasAlternateVersions
|
|
|
|
public int AlternateVersionCount
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get
|
|
|
|
get
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return HasLocalAlternateVersions || LinkedAlternateVersions.Count > 0;
|
|
|
|
return LinkedAlternateVersions.Count + LocalAlternateVersionIds.Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -51,7 +53,7 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
|
|
|
public IEnumerable<BaseItem> GetAlternateVersions()
|
|
|
|
public IEnumerable<BaseItem> GetAlternateVersions()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var filesWithinSameDirectory = AlternateVersionIds
|
|
|
|
var filesWithinSameDirectory = LocalAlternateVersionIds
|
|
|
|
.Select(i => LibraryManager.GetItemById(i))
|
|
|
|
.Select(i => LibraryManager.GetItemById(i))
|
|
|
|
.Where(i => i != null)
|
|
|
|
.Where(i => i != null)
|
|
|
|
.OfType<Video>();
|
|
|
|
.OfType<Video>();
|
|
|
@ -233,14 +235,11 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RefreshLinkedAlternateVersions();
|
|
|
|
RefreshLinkedAlternateVersions();
|
|
|
|
|
|
|
|
|
|
|
|
if (HasLocalAlternateVersions)
|
|
|
|
var additionalPartsChanged = await RefreshAlternateVersionsWithinSameDirectory(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
|
|
|
{
|
|
|
|
|
|
|
|
var additionalPartsChanged = await RefreshAlternateVersionsWithinSameDirectory(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (additionalPartsChanged)
|
|
|
|
if (additionalPartsChanged)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
hasChanges = true;
|
|
|
|
hasChanges = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -339,21 +338,72 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<bool> RefreshAlternateVersionsWithinSameDirectory(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
|
|
|
|
private async Task<bool> RefreshAlternateVersionsWithinSameDirectory(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var newItems = LoadAlternateVersionsWithinSameDirectory(fileSystemChildren, options.DirectoryService).ToList();
|
|
|
|
var newItems = HasLocalAlternateVersions ?
|
|
|
|
|
|
|
|
LoadAlternateVersionsWithinSameDirectory(fileSystemChildren, options.DirectoryService).ToList() :
|
|
|
|
|
|
|
|
new List<Video>();
|
|
|
|
|
|
|
|
|
|
|
|
var newItemIds = newItems.Select(i => i.Id).ToList();
|
|
|
|
var newItemIds = newItems.Select(i => i.Id).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var itemsChanged = !AlternateVersionIds.SequenceEqual(newItemIds);
|
|
|
|
var itemsChanged = !LocalAlternateVersionIds.SequenceEqual(newItemIds);
|
|
|
|
|
|
|
|
|
|
|
|
var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
|
|
|
|
var tasks = newItems.Select(i => RefreshAlternateVersion(options, i, cancellationToken));
|
|
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
AlternateVersionIds = newItemIds;
|
|
|
|
LocalAlternateVersionIds = newItemIds;
|
|
|
|
|
|
|
|
|
|
|
|
return itemsChanged;
|
|
|
|
return itemsChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Task RefreshAlternateVersion(MetadataRefreshOptions options, Video video, CancellationToken cancellationToken)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var currentImagePath = video.GetImagePath(ImageType.Primary);
|
|
|
|
|
|
|
|
var ownerImagePath = this.GetImagePath(ImageType.Primary);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newOptions = new MetadataRefreshOptions
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DirectoryService = options.DirectoryService,
|
|
|
|
|
|
|
|
ImageRefreshMode = options.ImageRefreshMode,
|
|
|
|
|
|
|
|
MetadataRefreshMode = options.MetadataRefreshMode,
|
|
|
|
|
|
|
|
ReplaceAllMetadata = options.ReplaceAllMetadata
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.Equals(currentImagePath, ownerImagePath, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
newOptions.ForceSave = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ownerImagePath))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
video.ImageInfos.Clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
video.SetImagePath(ImageType.Primary, ownerImagePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return video.RefreshMetadata(newOptions, cancellationToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in LocalAlternateVersionIds.Select(i => LibraryManager.GetItemById(i)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item.ImageInfos = ImageInfos;
|
|
|
|
|
|
|
|
item.Overview = Overview;
|
|
|
|
|
|
|
|
item.ProductionYear = ProductionYear;
|
|
|
|
|
|
|
|
item.PremiereDate = PremiereDate;
|
|
|
|
|
|
|
|
item.CommunityRating = CommunityRating;
|
|
|
|
|
|
|
|
item.OfficialRating = OfficialRating;
|
|
|
|
|
|
|
|
item.Genres = Genres;
|
|
|
|
|
|
|
|
item.ProviderIds = ProviderIds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Loads the additional parts.
|
|
|
|
/// Loads the additional parts.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -395,7 +445,7 @@ namespace MediaBrowser.Controller.Entities
|
|
|
|
video = dbItem;
|
|
|
|
video = dbItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
video.ImageInfos = ImageInfos;
|
|
|
|
video.PrimaryVersionId = Id;
|
|
|
|
|
|
|
|
|
|
|
|
return video;
|
|
|
|
return video;
|
|
|
|
|
|
|
|
|
|
|
|