jellyfin/MediaBrowser.Controller/Entities/Movies/Movie.cs

198 lines
6.1 KiB
C#
Raw Normal View History

2014-03-15 05:14:07 +01:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
2013-12-26 17:53:23 +01:00
using MediaBrowser.Model.Entities;
using System;
2013-02-21 02:33:05 +01:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
2017-05-26 08:48:54 +02:00
2016-10-25 21:02:04 +02:00
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
2016-05-29 08:03:09 +02:00
using MediaBrowser.Model.Providers;
2016-10-25 21:02:04 +02:00
using MediaBrowser.Model.Serialization;
2013-02-21 02:33:05 +01:00
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class Movie
/// </summary>
2017-05-13 21:31:25 +02:00
public class Movie : Video, IHasSpecialFeatures, IHasTrailers, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
2013-02-21 02:33:05 +01:00
{
2017-08-11 23:55:48 +02:00
public Guid[] SpecialFeatureIds { get; set; }
public Movie()
{
2017-08-11 23:55:48 +02:00
SpecialFeatureIds = EmptyGuidArray;
2017-08-10 20:01:31 +02:00
RemoteTrailers = EmptyMediaUrlArray;
LocalTrailerIds = EmptyGuidArray;
RemoteTrailerIds = EmptyGuidArray;
}
2013-06-16 21:02:57 +02:00
2017-08-10 20:01:31 +02:00
public Guid[] LocalTrailerIds { get; set; }
public Guid[] RemoteTrailerIds { get; set; }
2017-08-10 20:01:31 +02:00
public MediaUrl[] RemoteTrailers { get; set; }
2013-12-02 17:46:25 +01:00
2013-10-17 17:34:47 +02:00
/// <summary>
/// Gets or sets the name of the TMDB collection.
/// </summary>
/// <value>The name of the TMDB collection.</value>
public string TmdbCollectionName { get; set; }
2016-03-14 02:34:24 +01:00
[IgnoreDataMember]
public string CollectionName
{
get { return TmdbCollectionName; }
set { TmdbCollectionName = value; }
}
2013-02-21 02:33:05 +01:00
2017-02-10 21:06:52 +01:00
public override double? GetDefaultPrimaryImageAspectRatio()
{
double value = 2;
value /= 3;
return value;
}
2015-10-04 05:38:46 +02:00
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
2013-02-21 02:33:05 +01:00
{
2014-02-10 19:39:41 +01:00
var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
2013-06-17 22:35:43 +02:00
// Must have a parent to have special features
// In other words, it must be part of the Parent/Child tree
2017-07-31 07:16:22 +02:00
if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
2013-06-17 22:35:43 +02:00
{
var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
2013-02-21 02:33:05 +01:00
if (specialFeaturesChanged)
{
2014-02-10 19:39:41 +01:00
hasChanges = true;
}
}
2014-02-10 19:39:41 +01:00
return hasChanges;
}
2015-10-04 05:38:46 +02:00
private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
{
var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
2017-08-11 23:55:48 +02:00
var newItemIds = newItems.Select(i => i.Id).ToArray();
2013-02-21 02:33:05 +01:00
var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
2013-02-21 02:33:05 +01:00
2017-09-18 18:52:22 +02:00
var ownerId = Id;
var tasks = newItems.Select(i =>
{
var subOptions = new MetadataRefreshOptions(options);
if (i.OwnerId != ownerId)
{
i.OwnerId = ownerId;
subOptions.ForceSave = true;
}
return RefreshMetadataForOwnedItem(i, false, subOptions, cancellationToken);
});
await Task.WhenAll(tasks).ConfigureAwait(false);
SpecialFeatureIds = newItemIds;
return itemsChanged;
}
2013-06-16 21:02:57 +02:00
2015-11-06 16:02:22 +01:00
public override UnratedItem GetBlockUnratedType()
2013-12-26 17:53:23 +01:00
{
2015-11-06 16:02:22 +01:00
return UnratedItem.Movie;
2013-12-26 17:53:23 +01:00
}
2014-02-07 04:10:13 +01:00
public MovieInfo GetLookupInfo()
{
2014-12-19 05:20:07 +01:00
var info = GetItemLookupInfo<MovieInfo>();
2017-07-31 07:16:22 +02:00
if (!IsInMixedFolder)
2014-12-19 05:20:07 +01:00
{
2016-12-09 08:23:09 +01:00
var name = System.IO.Path.GetFileName(ContainingFolderPath);
if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
{
if (string.Equals(name, System.IO.Path.GetFileName(Path), StringComparison.OrdinalIgnoreCase))
{
// if the folder has the file extension, strip it
name = System.IO.Path.GetFileNameWithoutExtension(name);
}
}
info.Name = name;
2014-12-19 05:20:07 +01:00
}
return info;
2014-02-07 04:10:13 +01:00
}
2014-02-13 06:11:54 +01:00
public override bool BeforeMetadataRefresh()
{
var hasChanges = base.BeforeMetadataRefresh();
if (!ProductionYear.HasValue)
{
2014-11-16 23:46:01 +01:00
var info = LibraryManager.ParseName(Name);
2014-02-13 06:11:54 +01:00
2014-11-16 23:46:01 +01:00
var yearInName = info.Year;
2014-02-13 06:11:54 +01:00
if (yearInName.HasValue)
{
ProductionYear = yearInName;
hasChanges = true;
}
2014-12-09 05:57:18 +01:00
else
{
// Try to get the year from the folder name
2017-07-31 07:16:22 +02:00
if (!IsInMixedFolder)
2014-12-09 05:57:18 +01:00
{
info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
yearInName = info.Year;
if (yearInName.HasValue)
{
ProductionYear = yearInName;
hasChanges = true;
}
}
}
2014-02-13 06:11:54 +01:00
}
return hasChanges;
}
2016-05-29 08:03:09 +02:00
public override List<ExternalUrl> GetRelatedUrls()
{
var list = base.GetRelatedUrls();
var imdbId = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(imdbId))
{
list.Add(new ExternalUrl
{
Name = "Trakt",
Url = string.Format("https://trakt.tv/movies/{0}", imdbId)
});
}
return list;
}
2016-08-14 23:29:35 +02:00
[IgnoreDataMember]
public override bool StopRefreshIfLocalMetadataFound
{
get
{
// Need people id's from internet metadata
return false;
}
}
2013-02-21 02:33:05 +01:00
}
}