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

184 lines
5.9 KiB
C#
Raw Normal View History

2014-03-15 04:14:07 +00:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
2013-12-26 16:53:23 +00:00
using MediaBrowser.Model.Entities;
using System;
2013-02-21 01:33:05 +00:00
using System.Collections.Generic;
using System.Linq;
2016-03-14 01:34:24 +00:00
using System.Runtime.Serialization;
2013-02-21 01:33:05 +00:00
using System.Threading;
using System.Threading.Tasks;
2015-10-04 04:23:11 +00:00
using CommonIO;
2016-05-29 06:03:09 +00:00
using MediaBrowser.Model.Providers;
2013-02-21 01:33:05 +00:00
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class Movie
/// </summary>
public class Movie : Video, IHasCriticRating, IHasSpecialFeatures, IHasProductionLocations, IHasBudget, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping, IHasOriginalTitle
2013-02-21 01:33:05 +00:00
{
public List<Guid> SpecialFeatureIds { get; set; }
public List<Guid> ThemeSongIds { get; set; }
public List<Guid> ThemeVideoIds { get; set; }
2014-05-16 19:16:29 +00:00
public List<string> ProductionLocations { get; set; }
public Movie()
{
SpecialFeatureIds = new List<Guid>();
2013-12-02 16:46:25 +00:00
RemoteTrailers = new List<MediaUrl>();
LocalTrailerIds = new List<Guid>();
2014-12-11 06:20:28 +00:00
RemoteTrailerIds = new List<Guid>();
ThemeSongIds = new List<Guid>();
ThemeVideoIds = new List<Guid>();
Taglines = new List<string>();
2014-05-16 19:16:29 +00:00
ProductionLocations = new List<string>();
}
2013-06-16 19:02:57 +00:00
2014-01-15 05:01:58 +00:00
public string AwardSummary { get; set; }
public float? Metascore { get; set; }
2013-12-02 16:46:25 +00:00
public List<Guid> LocalTrailerIds { get; set; }
2014-12-11 06:20:28 +00:00
public List<Guid> RemoteTrailerIds { get; set; }
2013-12-02 16:46:25 +00:00
public List<MediaUrl> RemoteTrailers { get; set; }
/// <summary>
/// Gets or sets the taglines.
/// </summary>
/// <value>The taglines.</value>
public List<string> Taglines { get; set; }
/// <summary>
2013-12-02 16:16:03 +00:00
/// Gets or sets the budget.
/// </summary>
/// <value>The budget.</value>
public double? Budget { get; set; }
/// <summary>
/// Gets or sets the revenue.
/// </summary>
/// <value>The revenue.</value>
public double? Revenue { get; set; }
2013-10-17 15:34:47 +00: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 01:34:24 +00:00
[IgnoreDataMember]
public string CollectionName
{
get { return TmdbCollectionName; }
set { TmdbCollectionName = value; }
}
2013-02-21 01:33:05 +00:00
2015-10-04 03:38:46 +00:00
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
2013-02-21 01:33:05 +00:00
{
2014-02-10 18:39:41 +00:00
var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
2013-06-17 20:35:43 +00:00
// Must have a parent to have special features
// In other words, it must be part of the Parent/Child tree
2015-11-11 14:56:31 +00:00
if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
2013-06-17 20:35:43 +00:00
{
var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
2013-02-21 01:33:05 +00:00
if (specialFeaturesChanged)
{
2014-02-10 18:39:41 +00:00
hasChanges = true;
}
}
2014-02-10 18:39:41 +00:00
return hasChanges;
}
2015-10-04 03:38:46 +00:00
private async Task<bool> RefreshSpecialFeatures(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
{
var newItems = LibraryManager.FindExtras(this, fileSystemChildren, options.DirectoryService).ToList();
var newItemIds = newItems.Select(i => i.Id).ToList();
2013-02-21 01:33:05 +00:00
var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
2013-02-21 01:33:05 +00:00
var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
await Task.WhenAll(tasks).ConfigureAwait(false);
SpecialFeatureIds = newItemIds;
return itemsChanged;
}
2013-06-16 19:02:57 +00:00
2015-11-06 15:02:22 +00:00
public override UnratedItem GetBlockUnratedType()
2013-12-26 16:53:23 +00:00
{
2015-11-06 15:02:22 +00:00
return UnratedItem.Movie;
2013-12-26 16:53:23 +00:00
}
2014-02-07 03:10:13 +00:00
public MovieInfo GetLookupInfo()
{
2014-12-19 04:20:07 +00:00
var info = GetItemLookupInfo<MovieInfo>();
if (!IsInMixedFolder)
{
info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
}
return info;
2014-02-07 03:10:13 +00:00
}
2014-02-13 05:11:54 +00:00
public override bool BeforeMetadataRefresh()
{
var hasChanges = base.BeforeMetadataRefresh();
if (!ProductionYear.HasValue)
{
2014-11-16 22:46:01 +00:00
var info = LibraryManager.ParseName(Name);
2014-02-13 05:11:54 +00:00
2014-11-16 22:46:01 +00:00
var yearInName = info.Year;
2014-02-13 05:11:54 +00:00
if (yearInName.HasValue)
{
ProductionYear = yearInName;
hasChanges = true;
}
2014-12-09 04:57:18 +00:00
else
{
// Try to get the year from the folder name
if (!IsInMixedFolder)
{
info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
yearInName = info.Year;
if (yearInName.HasValue)
{
ProductionYear = yearInName;
hasChanges = true;
}
}
}
2014-02-13 05:11:54 +00:00
}
return hasChanges;
}
2016-05-29 06:03:09 +00: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;
}
2013-02-21 01:33:05 +00:00
}
}