aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/Video.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Entities/Video.cs')
-rw-r--r--MediaBrowser.Controller/Entities/Video.cs106
1 files changed, 31 insertions, 75 deletions
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs
index 9c9466766..de78068b3 100644
--- a/MediaBrowser.Controller/Entities/Video.cs
+++ b/MediaBrowser.Controller/Entities/Video.cs
@@ -84,33 +84,23 @@ namespace MediaBrowser.Controller.Entities
/// <value>The aspect ratio.</value>
public string AspectRatio { get; set; }
- /// <summary>
- /// Should be overridden to return the proper folder where metadata lives
- /// </summary>
- /// <value>The meta location.</value>
[IgnoreDataMember]
- public override string MetaLocation
+ public override string ContainingFolderPath
{
get
{
- return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso || IsMultiPart ? System.IO.Path.GetDirectoryName(Path) : Path;
- }
- }
+ if (IsMultiPart)
+ {
+ return System.IO.Path.GetDirectoryName(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
- {
- if (IsInMixedFolder)
+ if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd ||
+ VideoType == VideoType.HdDvd)
{
- return false;
+ return Path;
}
- return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso || IsMultiPart;
+ return base.ContainingFolderPath;
}
}
@@ -159,106 +149,73 @@ namespace MediaBrowser.Controller.Entities
}
}
- /// <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>
- /// <returns>true if a provider reports we changed</returns>
- public override async Task<bool> RefreshMetadataDirect(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false)
+ protected override async Task BeforeRefreshMetadata(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
{
- // Kick off a task to refresh the main item
- var result = await base.RefreshMetadataDirect(cancellationToken, forceSave, forceRefresh).ConfigureAwait(false);
-
- var additionalPartsChanged = false;
+ await base.BeforeRefreshMetadata(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
// 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)
{
- try
- {
- additionalPartsChanged = await RefreshAdditionalParts(cancellationToken, forceSave, forceRefresh).ConfigureAwait(false);
- }
- catch (IOException ex)
+ var additionalPartsChanged = await RefreshAdditionalParts(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
+
+ if (additionalPartsChanged)
{
- Logger.ErrorException("Error loading additional parts for {0}.", ex, Name);
+ options.ForceSave = true;
}
}
-
- return additionalPartsChanged || result;
}
/// <summary>
/// Refreshes the additional parts.
/// </summary>
+ /// <param name="options">The options.</param>
+ /// <param name="fileSystemChildren">The file system children.</param>
/// <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)
+ private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
{
- var newItems = LoadAdditionalParts().ToList();
+ var newItems = LoadAdditionalParts(fileSystemChildren).ToList();
var newItemIds = newItems.Select(i => i.Id).ToList();
var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds);
- var tasks = newItems.Select(i => i.RefreshMetadata(new MetadataRefreshOptions
- {
- ForceSave = forceSave,
- ReplaceAllMetadata = forceRefresh
+ var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
- }, cancellationToken));
-
- var results = await Task.WhenAll(tasks).ConfigureAwait(false);
+ await Task.WhenAll(tasks).ConfigureAwait(false);
AdditionalPartIds = newItemIds;
- return itemsChanged || results.Contains(true);
+ return itemsChanged;
}
/// <summary>
/// Loads the additional parts.
/// </summary>
/// <returns>IEnumerable{Video}.</returns>
- private IEnumerable<Video> LoadAdditionalParts()
+ private IEnumerable<Video> LoadAdditionalParts(IEnumerable<FileSystemInfo> fileSystemChildren)
{
IEnumerable<FileSystemInfo> files;
var path = Path;
- if (string.IsNullOrEmpty(path))
- {
- throw new ApplicationException(string.Format("Item {0} has a null path.", Name ?? Id.ToString()));
- }
-
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
{
- var parentPath = System.IO.Path.GetDirectoryName(path);
-
- if (string.IsNullOrEmpty(parentPath))
+ files = fileSystemChildren.Where(i =>
{
- throw new IOException("Unable to get parent path info from " + path);
- }
+ if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
+ {
+ return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
+ }
- files = new DirectoryInfo(parentPath)
- .EnumerateDirectories()
- .Where(i => !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFile(i.Name));
+ return false;
+ });
}
else
{
- var resolveArgs = ResolveArgs;
-
- if (resolveArgs == null)
- {
- throw new IOException("ResolveArgs are null for " + path);
- }
-
- files = resolveArgs.FileSystemChildren.Where(i =>
+ files = fileSystemChildren.Where(i =>
{
if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
@@ -276,7 +233,6 @@ namespace MediaBrowser.Controller.Entities
if (dbItem != null)
{
- dbItem.ResetResolveArgs(video.ResolveArgs);
video = dbItem;
}