2014-03-16 05:23:58 +01:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2014-01-28 19:37:01 +01:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-12-07 17:29:12 +01:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2013-06-18 21:16:27 +02:00
|
|
|
|
using System.Collections;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Video
|
|
|
|
|
/// </summary>
|
2014-03-03 06:11:03 +01:00
|
|
|
|
public class Video : BaseItem, IHasMediaStreams, IHasAspectRatio, IHasTags, ISupportsPlaceHolders
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-06-12 23:46:50 +02:00
|
|
|
|
public bool IsMultiPart { get; set; }
|
2014-03-15 23:52:43 +01:00
|
|
|
|
public bool HasLocalAlternateVersions { get; set; }
|
2014-03-16 05:23:58 +01:00
|
|
|
|
public Guid? PrimaryVersionId { get; set; }
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
|
|
|
|
public List<Guid> AdditionalPartIds { get; set; }
|
2014-03-16 05:23:58 +01:00
|
|
|
|
public List<Guid> LocalAlternateVersionIds { get; set; }
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2013-05-02 04:44:52 +02:00
|
|
|
|
public Video()
|
|
|
|
|
{
|
|
|
|
|
PlayableStreamFileNames = new List<string>();
|
2013-06-12 23:46:50 +02:00
|
|
|
|
AdditionalPartIds = new List<Guid>();
|
2014-03-16 05:23:58 +01:00
|
|
|
|
LocalAlternateVersionIds = new List<Guid>();
|
2014-02-08 21:02:35 +01:00
|
|
|
|
Tags = new List<string>();
|
2014-02-10 19:39:41 +01:00
|
|
|
|
SubtitleFiles = new List<string>();
|
2014-03-15 23:52:43 +01:00
|
|
|
|
LinkedAlternateVersions = new List<LinkedChild>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2014-03-22 17:16:43 +01:00
|
|
|
|
public int MediaSourceCount
|
2014-03-15 23:52:43 +01:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-03-22 17:16:43 +01:00
|
|
|
|
return LinkedAlternateVersions.Count + LocalAlternateVersionIds.Count + 1;
|
2014-03-15 23:52:43 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<LinkedChild> LinkedAlternateVersions { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the linked children.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
2014-03-19 02:35:40 +01:00
|
|
|
|
public IEnumerable<Video> GetAlternateVersions()
|
2014-03-15 23:52:43 +01:00
|
|
|
|
{
|
2014-03-16 05:23:58 +01:00
|
|
|
|
var filesWithinSameDirectory = LocalAlternateVersionIds
|
2014-03-15 23:52:43 +01:00
|
|
|
|
.Select(i => LibraryManager.GetItemById(i))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.OfType<Video>();
|
|
|
|
|
|
2014-03-19 02:35:40 +01:00
|
|
|
|
return filesWithinSameDirectory.Concat(GetLinkedAlternateVersions())
|
|
|
|
|
.OrderBy(i => i.SortName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Video> GetLinkedAlternateVersions()
|
|
|
|
|
{
|
2014-03-15 23:52:43 +01:00
|
|
|
|
var linkedVersions = LinkedAlternateVersions
|
|
|
|
|
.Select(GetLinkedChild)
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.OfType<Video>();
|
|
|
|
|
|
2014-03-19 02:35:40 +01:00
|
|
|
|
return linkedVersions
|
2014-03-15 23:52:43 +01:00
|
|
|
|
.OrderBy(i => i.SortName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the additional parts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{Video}.</returns>
|
|
|
|
|
public IEnumerable<Video> GetAdditionalParts()
|
|
|
|
|
{
|
|
|
|
|
return AdditionalPartIds
|
|
|
|
|
.Select(i => LibraryManager.GetItemById(i))
|
|
|
|
|
.Where(i => i != null)
|
|
|
|
|
.OfType<Video>()
|
|
|
|
|
.OrderBy(i => i.SortName);
|
2013-05-02 04:44:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 19:39:41 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the subtitle paths.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The subtitle paths.</value>
|
|
|
|
|
public List<string> SubtitleFiles { get; set; }
|
|
|
|
|
|
2013-12-06 04:39:44 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this instance has subtitles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool HasSubtitles { get; set; }
|
|
|
|
|
|
2014-03-03 06:11:03 +01:00
|
|
|
|
public bool IsPlaceHolder { get; set; }
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
2014-02-08 21:02:35 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the tags.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The tags.</value>
|
|
|
|
|
public List<string> Tags { get; set; }
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
2013-12-06 04:39:44 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the video bit rate.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The video bit rate.</value>
|
|
|
|
|
public int? VideoBitRate { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the default index of the video stream.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The default index of the video stream.</value>
|
|
|
|
|
public int? DefaultVideoStreamIndex { get; set; }
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the type of the video.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The type of the video.</value>
|
|
|
|
|
public VideoType VideoType { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the type of the iso.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The type of the iso.</value>
|
|
|
|
|
public IsoType? IsoType { get; set; }
|
|
|
|
|
|
2013-06-25 20:10:39 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the video3 D format.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The video3 D format.</value>
|
|
|
|
|
public Video3DFormat? Video3DFormat { get; set; }
|
2013-02-21 02:33:05 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If the video is a folder-rip, this will hold the file list for the largest playlist
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> PlayableStreamFileNames { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the playable stream files.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>List{System.String}.</returns>
|
|
|
|
|
public List<string> GetPlayableStreamFiles()
|
|
|
|
|
{
|
|
|
|
|
return GetPlayableStreamFiles(Path);
|
|
|
|
|
}
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2013-11-20 04:15:48 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the aspect ratio.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The aspect ratio.</value>
|
|
|
|
|
public string AspectRatio { get; set; }
|
2013-12-06 04:39:44 +01:00
|
|
|
|
|
2013-07-16 20:47:05 +02:00
|
|
|
|
[IgnoreDataMember]
|
2014-02-06 05:39:16 +01:00
|
|
|
|
public override string ContainingFolderPath
|
2013-07-16 20:47:05 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-02-06 05:39:16 +01:00
|
|
|
|
if (IsMultiPart)
|
|
|
|
|
{
|
|
|
|
|
return System.IO.Path.GetDirectoryName(Path);
|
|
|
|
|
}
|
2013-07-16 20:47:05 +02:00
|
|
|
|
|
2014-03-05 03:59:23 +01:00
|
|
|
|
if (!IsPlaceHolder)
|
2013-08-15 18:00:39 +02:00
|
|
|
|
{
|
2014-03-05 03:59:23 +01:00
|
|
|
|
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd ||
|
|
|
|
|
VideoType == VideoType.HdDvd)
|
|
|
|
|
{
|
|
|
|
|
return Path;
|
|
|
|
|
}
|
2013-08-15 18:00:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-06 05:39:16 +01:00
|
|
|
|
return base.ContainingFolderPath;
|
2013-07-16 20:47:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 03:35:57 +02:00
|
|
|
|
public string MainFeaturePlaylistName { get; set; }
|
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the playable stream files.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rootPath">The root path.</param>
|
|
|
|
|
/// <returns>List{System.String}.</returns>
|
|
|
|
|
public List<string> GetPlayableStreamFiles(string rootPath)
|
|
|
|
|
{
|
|
|
|
|
var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
|
|
|
|
|
|
2013-06-16 21:02:57 +02:00
|
|
|
|
return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
|
2013-02-21 02:33:05 +01:00
|
|
|
|
.Where(f => !string.IsNullOrEmpty(f))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [is3 D].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public bool Is3D
|
|
|
|
|
{
|
2013-06-25 20:10:39 +02:00
|
|
|
|
get { return Video3DFormat.HasValue; }
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:14:40 +02:00
|
|
|
|
public bool IsHD { get; set; }
|
2013-09-10 20:56:00 +02:00
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the type of the media.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The type of the media.</value>
|
|
|
|
|
public override string MediaType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Model.Entities.MediaType.Video;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2014-02-10 19:39:41 +01:00
|
|
|
|
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
2014-02-10 19:39:41 +01:00
|
|
|
|
var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
2013-06-17 03:49:41 +02:00
|
|
|
|
|
2014-03-15 23:52:43 +01:00
|
|
|
|
// Must have a parent to have additional parts or alternate versions
|
2013-06-17 22:35:43 +02:00
|
|
|
|
// In other words, it must be part of the Parent/Child tree
|
|
|
|
|
// The additional parts won't have additional parts themselves
|
2014-03-15 23:52:43 +01:00
|
|
|
|
if (LocationType == LocationType.FileSystem && Parent != null)
|
2013-06-17 03:49:41 +02:00
|
|
|
|
{
|
2014-03-15 23:52:43 +01:00
|
|
|
|
if (IsMultiPart)
|
|
|
|
|
{
|
|
|
|
|
var additionalPartsChanged = await RefreshAdditionalParts(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
2014-02-06 05:39:16 +01:00
|
|
|
|
|
2014-03-15 23:52:43 +01:00
|
|
|
|
if (additionalPartsChanged)
|
|
|
|
|
{
|
|
|
|
|
hasChanges = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-06-17 03:49:41 +02:00
|
|
|
|
{
|
2014-03-15 23:52:43 +01:00
|
|
|
|
RefreshLinkedAlternateVersions();
|
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
var additionalPartsChanged = await RefreshAlternateVersionsWithinSameDirectory(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
if (additionalPartsChanged)
|
|
|
|
|
{
|
|
|
|
|
hasChanges = true;
|
2014-03-15 23:52:43 +01:00
|
|
|
|
}
|
2013-06-17 03:49:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-10 19:39:41 +01:00
|
|
|
|
|
|
|
|
|
return hasChanges;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 23:52:43 +01:00
|
|
|
|
private bool RefreshLinkedAlternateVersions()
|
|
|
|
|
{
|
|
|
|
|
foreach (var child in LinkedAlternateVersions)
|
|
|
|
|
{
|
|
|
|
|
// Reset the cached value
|
|
|
|
|
if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
|
|
|
|
|
{
|
|
|
|
|
child.ItemId = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-12 23:46:50 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the additional parts.
|
|
|
|
|
/// </summary>
|
2014-02-06 05:39:16 +01:00
|
|
|
|
/// <param name="options">The options.</param>
|
|
|
|
|
/// <param name="fileSystemChildren">The file system children.</param>
|
2013-06-12 23:46:50 +02:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
2014-02-08 23:38:02 +01:00
|
|
|
|
private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
2014-02-13 06:11:54 +01:00
|
|
|
|
var newItems = LoadAdditionalParts(fileSystemChildren, options.DirectoryService).ToList();
|
2013-06-17 03:49:41 +02:00
|
|
|
|
|
2013-06-12 23:46:50 +02:00
|
|
|
|
var newItemIds = newItems.Select(i => i.Id).ToList();
|
|
|
|
|
|
|
|
|
|
var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds);
|
|
|
|
|
|
2014-02-06 05:39:16 +01:00
|
|
|
|
var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
|
2014-01-28 19:37:01 +01:00
|
|
|
|
|
2014-02-06 05:39:16 +01:00
|
|
|
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
|
|
|
|
AdditionalPartIds = newItemIds;
|
|
|
|
|
|
2014-02-06 05:39:16 +01:00
|
|
|
|
return itemsChanged;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the additional parts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{Video}.</returns>
|
2014-02-13 06:11:54 +01:00
|
|
|
|
private IEnumerable<Video> LoadAdditionalParts(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
2013-06-16 21:02:57 +02:00
|
|
|
|
IEnumerable<FileSystemInfo> files;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2014-01-02 22:21:47 +01:00
|
|
|
|
var path = Path;
|
|
|
|
|
|
2013-06-16 21:02:57 +02:00
|
|
|
|
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
2014-02-06 05:39:16 +01:00
|
|
|
|
files = fileSystemChildren.Where(i =>
|
2014-01-02 22:21:47 +01:00
|
|
|
|
{
|
2014-02-06 05:39:16 +01:00
|
|
|
|
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
2014-03-15 23:52:43 +01:00
|
|
|
|
return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFolder(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
|
2014-02-06 05:39:16 +01:00
|
|
|
|
}
|
2014-01-02 22:21:47 +01:00
|
|
|
|
|
2014-02-06 05:39:16 +01:00
|
|
|
|
return false;
|
|
|
|
|
});
|
2013-06-12 23:46:50 +02:00
|
|
|
|
}
|
2013-06-16 21:02:57 +02:00
|
|
|
|
else
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
2014-02-06 05:39:16 +01:00
|
|
|
|
files = fileSystemChildren.Where(i =>
|
2013-06-16 21:02:57 +02:00
|
|
|
|
{
|
|
|
|
|
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 22:21:47 +01:00
|
|
|
|
return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
|
2013-06-16 21:02:57 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2014-02-13 06:11:54 +01:00
|
|
|
|
return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
|
2013-06-12 23:46:50 +02:00
|
|
|
|
{
|
|
|
|
|
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
2014-01-14 21:03:35 +01:00
|
|
|
|
var dbItem = LibraryManager.GetItemById(video.Id) as Video;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
|
|
|
|
if (dbItem != null)
|
|
|
|
|
{
|
|
|
|
|
video = dbItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return video;
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
|
|
|
|
// Sort them so that the list can be easily compared for changes
|
|
|
|
|
}).OrderBy(i => i.Path).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<bool> RefreshAlternateVersionsWithinSameDirectory(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2014-03-16 05:23:58 +01:00
|
|
|
|
var newItems = HasLocalAlternateVersions ?
|
|
|
|
|
LoadAlternateVersionsWithinSameDirectory(fileSystemChildren, options.DirectoryService).ToList() :
|
|
|
|
|
new List<Video>();
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
|
|
|
|
var newItemIds = newItems.Select(i => i.Id).ToList();
|
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
var itemsChanged = !LocalAlternateVersionIds.SequenceEqual(newItemIds);
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
var tasks = newItems.Select(i => RefreshAlternateVersion(options, i, cancellationToken));
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
|
|
|
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
LocalAlternateVersionIds = newItemIds;
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
|
|
|
|
return itemsChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2014-04-08 06:17:18 +02:00
|
|
|
|
await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
|
2014-03-16 05:23:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 23:52:43 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the additional parts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{Video}.</returns>
|
|
|
|
|
private IEnumerable<Video> LoadAlternateVersionsWithinSameDirectory(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<FileSystemInfo> files;
|
|
|
|
|
|
|
|
|
|
// Only support this for video files. For folder rips, they'll have to use the linking feature
|
|
|
|
|
if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
|
|
|
|
|
{
|
2014-03-21 17:55:47 +01:00
|
|
|
|
var path = Path;
|
|
|
|
|
|
|
|
|
|
var filenamePrefix = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(path));
|
|
|
|
|
|
2014-03-15 23:52:43 +01:00
|
|
|
|
files = fileSystemChildren.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
EntityResolutionHelper.IsVideoFile(i.FullName) &&
|
2014-03-21 17:55:47 +01:00
|
|
|
|
i.Name.StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase);
|
2014-03-15 23:52:43 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
files = new List<FileSystemInfo>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
|
|
|
|
|
{
|
|
|
|
|
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
|
|
|
|
var dbItem = LibraryManager.GetItemById(video.Id) as Video;
|
|
|
|
|
|
|
|
|
|
if (dbItem != null)
|
|
|
|
|
{
|
|
|
|
|
video = dbItem;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-16 05:23:58 +01:00
|
|
|
|
video.PrimaryVersionId = Id;
|
2014-03-15 23:52:43 +01:00
|
|
|
|
|
|
|
|
|
return video;
|
2013-06-12 23:46:50 +02:00
|
|
|
|
|
2014-02-06 17:46:26 +01:00
|
|
|
|
// Sort them so that the list can be easily compared for changes
|
|
|
|
|
}).OrderBy(i => i.Path).ToList();
|
2013-06-12 23:46:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-01 20:31:58 +01:00
|
|
|
|
public override IEnumerable<string> GetDeletePaths()
|
|
|
|
|
{
|
|
|
|
|
if (!IsInMixedFolder)
|
|
|
|
|
{
|
2014-03-05 03:59:23 +01:00
|
|
|
|
return new[] { ContainingFolderPath };
|
2013-12-01 20:31:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.GetDeletePaths();
|
|
|
|
|
}
|
2013-12-07 17:29:12 +01:00
|
|
|
|
|
2013-12-08 02:42:15 +01:00
|
|
|
|
public virtual IEnumerable<MediaStream> GetMediaStreams()
|
2013-12-07 17:29:12 +01:00
|
|
|
|
{
|
|
|
|
|
return ItemRepository.GetMediaStreams(new MediaStreamQuery
|
|
|
|
|
{
|
|
|
|
|
ItemId = Id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-08 02:42:15 +01:00
|
|
|
|
public virtual MediaStream GetDefaultVideoStream()
|
2013-12-07 17:29:12 +01:00
|
|
|
|
{
|
|
|
|
|
if (!DefaultVideoStreamIndex.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ItemRepository.GetMediaStreams(new MediaStreamQuery
|
|
|
|
|
{
|
|
|
|
|
ItemId = Id,
|
|
|
|
|
Index = DefaultVideoStreamIndex.Value
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|