2013-12-07 09:29:12 -07:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2013-06-18 12:16:27 -07:00
|
|
|
|
using System.Collections;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Video
|
|
|
|
|
/// </summary>
|
2013-11-19 20:15:48 -07:00
|
|
|
|
public class Video : BaseItem, IHasMediaStreams, IHasAspectRatio
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-06-12 14:46:50 -07:00
|
|
|
|
public bool IsMultiPart { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<Guid> AdditionalPartIds { get; set; }
|
|
|
|
|
|
2013-05-01 19:44:52 -07:00
|
|
|
|
public Video()
|
|
|
|
|
{
|
|
|
|
|
PlayableStreamFileNames = new List<string>();
|
2013-06-12 14:46:50 -07:00
|
|
|
|
AdditionalPartIds = new List<Guid>();
|
2013-05-01 19:44:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 20:39:44 -07: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; }
|
|
|
|
|
|
|
|
|
|
/// <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-20 18:33:05 -07: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 11:10:39 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the video3 D format.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The video3 D format.</value>
|
|
|
|
|
public Video3DFormat? Video3DFormat { get; set; }
|
2013-02-20 18:33:05 -07: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 14:46:50 -07:00
|
|
|
|
|
2013-11-19 20:15:48 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the aspect ratio.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The aspect ratio.</value>
|
|
|
|
|
public string AspectRatio { get; set; }
|
2013-12-05 20:39:44 -07:00
|
|
|
|
|
2013-07-16 11:47:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Should be overridden to return the proper folder where metadata lives
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The meta location.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override string MetaLocation
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso || IsMultiPart ? System.IO.Path.GetDirectoryName(Path) : Path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needed because the resolver stops at the movie folder and we find the video inside.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [use parent path to create resolve args]; otherwise, <c>false</c>.</value>
|
|
|
|
|
protected override bool UseParentPathToCreateResolveArgs
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-08-15 09:00:39 -07:00
|
|
|
|
if (IsInMixedFolder)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 11:47:05 -07:00
|
|
|
|
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso || IsMultiPart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-01 18:35:57 -07:00
|
|
|
|
public string MainFeaturePlaylistName { get; set; }
|
|
|
|
|
|
2013-02-20 18:33:05 -07: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)
|
|
|
|
|
{
|
|
|
|
|
if (PlayableStreamFileNames == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
|
|
|
|
|
|
2013-06-16 12:02:57 -07:00
|
|
|
|
return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
|
2013-02-20 18:33:05 -07: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 11:10:39 -07:00
|
|
|
|
get { return Video3DFormat.HasValue; }
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 07:14:40 -07:00
|
|
|
|
public bool IsHD { get; set; }
|
2013-09-10 11:56:00 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07: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 14:46:50 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Overrides the base implementation to refresh metadata for local trailers
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <param name="forceSave">if set to <c>true</c> [is new item].</param>
|
|
|
|
|
/// <param name="forceRefresh">if set to <c>true</c> [force].</param>
|
|
|
|
|
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
|
2013-06-20 12:07:58 -07:00
|
|
|
|
/// <param name="resetResolveArgs">The reset resolve args.</param>
|
2013-06-12 14:46:50 -07:00
|
|
|
|
/// <returns>true if a provider reports we changed</returns>
|
2013-06-20 12:07:58 -07:00
|
|
|
|
public override async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
|
2013-06-12 14:46:50 -07:00
|
|
|
|
{
|
|
|
|
|
// Kick off a task to refresh the main item
|
2013-06-20 12:07:58 -07:00
|
|
|
|
var result = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs).ConfigureAwait(false);
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
2013-06-16 18:49:41 -07:00
|
|
|
|
var additionalPartsChanged = false;
|
|
|
|
|
|
2013-06-17 13:35:43 -07:00
|
|
|
|
// Must have a parent to have additional parts
|
|
|
|
|
// In other words, it must be part of the Parent/Child tree
|
|
|
|
|
// The additional parts won't have additional parts themselves
|
|
|
|
|
if (IsMultiPart && LocationType == LocationType.FileSystem && Parent != null)
|
2013-06-16 18:49:41 -07:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
additionalPartsChanged = await RefreshAdditionalParts(cancellationToken, forceSave, forceRefresh, allowSlowProviders).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error loading additional parts for {0}.", ex, Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
|
|
|
|
return additionalPartsChanged || result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes the additional parts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <param name="forceSave">if set to <c>true</c> [force save].</param>
|
|
|
|
|
/// <param name="forceRefresh">if set to <c>true</c> [force refresh].</param>
|
|
|
|
|
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
|
|
|
private async Task<bool> RefreshAdditionalParts(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true)
|
|
|
|
|
{
|
|
|
|
|
var newItems = LoadAdditionalParts().ToList();
|
2013-06-16 18:49:41 -07:00
|
|
|
|
|
2013-06-12 14:46:50 -07:00
|
|
|
|
var newItemIds = newItems.Select(i => i.Id).ToList();
|
|
|
|
|
|
|
|
|
|
var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds);
|
|
|
|
|
|
|
|
|
|
var tasks = newItems.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
|
|
|
|
|
|
|
|
|
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
AdditionalPartIds = newItemIds;
|
|
|
|
|
|
|
|
|
|
return itemsChanged || results.Contains(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads the additional parts.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IEnumerable{Video}.</returns>
|
|
|
|
|
private IEnumerable<Video> LoadAdditionalParts()
|
|
|
|
|
{
|
2013-06-16 12:02:57 -07:00
|
|
|
|
IEnumerable<FileSystemInfo> files;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
2013-06-16 12:02:57 -07:00
|
|
|
|
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
|
2013-06-12 14:46:50 -07:00
|
|
|
|
{
|
2013-06-16 12:02:57 -07:00
|
|
|
|
files = new DirectoryInfo(System.IO.Path.GetDirectoryName(Path))
|
|
|
|
|
.EnumerateDirectories()
|
|
|
|
|
.Where(i => !string.Equals(i.FullName, Path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFile(i.Name));
|
2013-06-12 14:46:50 -07:00
|
|
|
|
}
|
2013-06-16 12:02:57 -07:00
|
|
|
|
else
|
2013-06-12 14:46:50 -07:00
|
|
|
|
{
|
2013-06-16 18:49:41 -07:00
|
|
|
|
files = ResolveArgs.FileSystemChildren.Where(i =>
|
2013-06-16 12:02:57 -07:00
|
|
|
|
{
|
|
|
|
|
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !string.Equals(i.FullName, Path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
|
|
|
|
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>
|
|
|
|
|
{
|
|
|
|
|
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
2013-06-26 09:08:16 -07:00
|
|
|
|
var dbItem = LibraryManager.RetrieveItem(video.Id) as Video;
|
2013-06-12 14:46:50 -07:00
|
|
|
|
|
|
|
|
|
if (dbItem != null)
|
|
|
|
|
{
|
2013-09-25 11:05:21 -07:00
|
|
|
|
dbItem.ResetResolveArgs(video.ResolveArgs);
|
2013-06-12 14:46:50 -07:00
|
|
|
|
video = dbItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return video;
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-01 12:31:58 -07:00
|
|
|
|
public override IEnumerable<string> GetDeletePaths()
|
|
|
|
|
{
|
|
|
|
|
if (!IsInMixedFolder)
|
|
|
|
|
{
|
2013-12-01 19:24:14 -07:00
|
|
|
|
if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
|
|
|
|
|
{
|
|
|
|
|
return new[] { System.IO.Path.GetDirectoryName(Path) };
|
|
|
|
|
}
|
2013-12-01 12:31:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.GetDeletePaths();
|
|
|
|
|
}
|
2013-12-07 09:29:12 -07:00
|
|
|
|
|
2013-12-07 18:42:15 -07:00
|
|
|
|
public virtual IEnumerable<MediaStream> GetMediaStreams()
|
2013-12-07 09:29:12 -07:00
|
|
|
|
{
|
|
|
|
|
return ItemRepository.GetMediaStreams(new MediaStreamQuery
|
|
|
|
|
{
|
|
|
|
|
ItemId = Id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 18:42:15 -07:00
|
|
|
|
public virtual MediaStream GetDefaultVideoStream()
|
2013-12-07 09:29:12 -07:00
|
|
|
|
{
|
|
|
|
|
if (!DefaultVideoStreamIndex.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ItemRepository.GetMediaStreams(new MediaStreamQuery
|
|
|
|
|
{
|
|
|
|
|
ItemId = Id,
|
|
|
|
|
Index = DefaultVideoStreamIndex.Value
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|