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

216 lines
6.9 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 MediaBrowser.Model.Users;
using System;
2013-02-21 02:33:05 +01:00
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.Threading;
using System.Threading.Tasks;
2015-10-04 06:23:11 +02:00
using CommonIO;
2015-10-04 05:38:46 +02:00
using MediaBrowser.Common.IO;
2013-02-21 02:33:05 +01:00
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class Movie
/// </summary>
2015-04-26 05:25:07 +02:00
public class Movie : Video, IHasCriticRating, IHasSpecialFeatures, IHasProductionLocations, IHasBudget, IHasKeywords, IHasTrailers, IHasThemeMedia, IHasTaglines, IHasAwards, IHasMetascore, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping, IHasOriginalTitle
2013-02-21 02:33:05 +01:00
{
public List<Guid> SpecialFeatureIds { get; set; }
2015-03-10 02:30:20 +01:00
public string OriginalTitle { get; set; }
2013-11-12 16:36:08 +01:00
public List<Guid> ThemeSongIds { get; set; }
public List<Guid> ThemeVideoIds { get; set; }
2014-05-16 21:16:29 +02:00
public List<string> ProductionLocations { get; set; }
public Movie()
{
SpecialFeatureIds = new List<Guid>();
2013-12-02 17:46:25 +01:00
RemoteTrailers = new List<MediaUrl>();
LocalTrailerIds = new List<Guid>();
2014-12-11 07:20:28 +01:00
RemoteTrailerIds = new List<Guid>();
ThemeSongIds = new List<Guid>();
ThemeVideoIds = new List<Guid>();
Taglines = new List<string>();
2014-01-14 16:50:39 +01:00
Keywords = new List<string>();
2014-05-16 21:16:29 +02:00
ProductionLocations = new List<string>();
}
2013-06-16 21:02:57 +02:00
2014-01-15 06:01:58 +01:00
public string AwardSummary { get; set; }
public float? Metascore { get; set; }
2013-12-02 17:46:25 +01:00
public List<Guid> LocalTrailerIds { get; set; }
2014-12-11 07:20:28 +01:00
public List<Guid> RemoteTrailerIds { get; set; }
2014-01-14 16:50:39 +01:00
public List<string> Keywords { get; set; }
2013-12-02 17:46:25 +01: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 17:16:03 +01: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-11-06 17:06:16 +01:00
/// <summary>
/// Gets or sets the critic rating.
/// </summary>
/// <value>The critic rating.</value>
public float? CriticRating { get; set; }
/// <summary>
/// Gets or sets the critic rating summary.
/// </summary>
/// <value>The critic rating summary.</value>
public string CriticRatingSummary { get; set; }
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; }
2014-12-11 07:20:28 +01:00
/// <summary>
/// Gets the trailer ids.
/// </summary>
/// <returns>List&lt;Guid&gt;.</returns>
public List<Guid> GetTrailerIds()
{
var list = LocalTrailerIds.ToList();
list.AddRange(RemoteTrailerIds);
return list;
}
2013-02-21 02:33:05 +01:00
/// <summary>
/// Gets the user data key.
2013-02-21 02:33:05 +01:00
/// </summary>
/// <returns>System.String.</returns>
2015-01-24 23:33:26 +01:00
protected override string CreateUserDataKey()
2013-02-21 02:33:05 +01:00
{
2015-08-21 01:55:23 +02:00
var key = GetMovieUserDataKey(this);
2015-04-29 19:39:23 +02:00
if (string.IsNullOrWhiteSpace(key))
{
2015-08-21 01:55:23 +02:00
key = base.CreateUserDataKey();
2015-04-29 19:39:23 +02:00
}
2015-08-21 01:55:23 +02:00
return key;
}
public static string GetMovieUserDataKey(BaseItem movie)
{
var key = movie.GetProviderId(MetadataProviders.Tmdb);
2015-04-29 19:39:23 +02:00
if (string.IsNullOrWhiteSpace(key))
{
2015-08-21 01:55:23 +02:00
key = movie.GetProviderId(MetadataProviders.Imdb);
2015-04-29 19:39:23 +02:00
}
return key;
2013-02-21 02:33:05 +01:00
}
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
if (LocationType == LocationType.FileSystem && Parent != 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();
var newItemIds = newItems.Select(i => i.Id).ToList();
2013-02-21 02:33:05 +01:00
var itemsChanged = !SpecialFeatureIds.SequenceEqual(newItemIds);
2013-02-21 02:33:05 +01:00
var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
await Task.WhenAll(tasks).ConfigureAwait(false);
SpecialFeatureIds = newItemIds;
return itemsChanged;
}
2013-06-16 21:02:57 +02:00
2014-12-20 07:06:27 +01:00
protected override bool GetBlockUnratedValue(UserPolicy config)
2013-12-26 17:53:23 +01:00
{
return config.BlockUnratedItems.Contains(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>();
if (!IsInMixedFolder)
{
info.Name = System.IO.Path.GetFileName(ContainingFolderPath);
}
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
if (!IsInMixedFolder)
{
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;
}
2013-02-21 02:33:05 +01:00
}
}