2013-04-13 20:02:30 +02:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System.Collections.Generic;
|
2013-02-21 18:51:17 +01:00
|
|
|
|
using System.IO;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities.Movies
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class Movie
|
|
|
|
|
/// </summary>
|
2013-02-21 18:51:17 +01:00
|
|
|
|
public class Movie : Video
|
2013-02-21 02:33:05 +01: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 ? System.IO.Path.GetDirectoryName(Path) : Path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-04-13 20:02:30 +02:00
|
|
|
|
/// Gets the user data key.
|
2013-02-21 02:33:05 +01:00
|
|
|
|
/// </summary>
|
2013-04-13 20:02:30 +02:00
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public override string GetUserDataKey()
|
2013-02-21 02:33:05 +01:00
|
|
|
|
{
|
2013-04-13 20:02:30 +02:00
|
|
|
|
return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.GetUserDataKey();
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _special features
|
|
|
|
|
/// </summary>
|
|
|
|
|
private List<Video> _specialFeatures;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _special features initialized
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool _specialFeaturesInitialized;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _special features sync lock
|
|
|
|
|
/// </summary>
|
|
|
|
|
private object _specialFeaturesSyncLock = new object();
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the special features.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The special features.</value>
|
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public List<Video> SpecialFeatures
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-02-21 18:51:17 +01:00
|
|
|
|
LazyInitializer.EnsureInitialized(ref _specialFeatures, ref _specialFeaturesInitialized, ref _specialFeaturesSyncLock, () => LoadSpecialFeatures().ToList());
|
2013-02-21 02:33:05 +01:00
|
|
|
|
return _specialFeatures;
|
|
|
|
|
}
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
_specialFeatures = value;
|
|
|
|
|
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
_specialFeaturesInitialized = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
|
|
|
|
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Overrides the base implementation to refresh metadata for special features
|
|
|
|
|
/// </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>
|
|
|
|
|
/// <param name="resetResolveArgs">if set to <c>true</c> [reset resolve args].</param>
|
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
|
|
|
|
public override async Task<bool> RefreshMetadata(CancellationToken cancellationToken, bool forceSave = false, bool forceRefresh = false, bool allowSlowProviders = true, bool resetResolveArgs = true)
|
|
|
|
|
{
|
|
|
|
|
// Lazy load these again
|
|
|
|
|
SpecialFeatures = null;
|
|
|
|
|
|
|
|
|
|
// Kick off a task to refresh the main item
|
|
|
|
|
var result = await base.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders, resetResolveArgs).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var tasks = SpecialFeatures.Select(item => item.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
return result;
|
2013-04-10 17:56:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 18:51:17 +01:00
|
|
|
|
/// <summary>
|
2013-04-10 17:56:36 +02:00
|
|
|
|
/// Loads the special features.
|
2013-02-21 18:51:17 +01:00
|
|
|
|
/// </summary>
|
2013-04-10 17:56:36 +02:00
|
|
|
|
/// <returns>IEnumerable{Video}.</returns>
|
2013-02-21 18:51:17 +01:00
|
|
|
|
private IEnumerable<Video> LoadSpecialFeatures()
|
|
|
|
|
{
|
2013-04-28 07:29:27 +02:00
|
|
|
|
FileSystemInfo folder;
|
2013-02-21 18:51:17 +01:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
folder = ResolveArgs.GetFileSystemEntryByName("specials");
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
2013-02-21 21:26:35 +01:00
|
|
|
|
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
|
2013-04-10 17:56:36 +02:00
|
|
|
|
return new List<Video>();
|
2013-02-21 18:51:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Path doesn't exist. No biggie
|
|
|
|
|
if (folder == null)
|
|
|
|
|
{
|
2013-04-10 17:56:36 +02:00
|
|
|
|
return new List<Video>();
|
2013-02-21 18:51:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 07:29:27 +02:00
|
|
|
|
IEnumerable<FileSystemInfo> files;
|
2013-02-21 18:51:17 +01:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-04-28 07:29:27 +02:00
|
|
|
|
files = new DirectoryInfo(folder.FullName).EnumerateFiles();
|
2013-02-21 18:51:17 +01:00
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
2013-02-21 21:26:35 +01:00
|
|
|
|
Logger.ErrorException("Error loading trailers for {0}", ex, Name);
|
2013-04-10 17:56:36 +02:00
|
|
|
|
return new List<Video>();
|
2013-02-21 18:51:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 20:32:41 +01:00
|
|
|
|
return LibraryManager.ResolvePaths<Video>(files, null).Select(video =>
|
2013-02-21 18:51:17 +01:00
|
|
|
|
{
|
|
|
|
|
// Try to retrieve it from the db. If we don't find it, use the resolved version
|
2013-04-08 17:55:53 +02:00
|
|
|
|
var dbItem = LibraryManager.RetrieveItem(video.Id) as Video;
|
2013-02-21 18:51:17 +01:00
|
|
|
|
|
|
|
|
|
if (dbItem != null)
|
|
|
|
|
{
|
|
|
|
|
dbItem.ResolveArgs = video.ResolveArgs;
|
|
|
|
|
video = dbItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return video;
|
|
|
|
|
});
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
2013-02-21 18:51:17 +01:00
|
|
|
|
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|