You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Controller/Entities/Movies/Movie.cs

147 lines
4.3 KiB

#nullable disable
4 years ago
#pragma warning disable CS1591
4 years ago
using System;
6 years ago
using System.Collections.Generic;
4 years ago
using System.Globalization;
6 years ago
using System.Linq;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
6 years ago
using MediaBrowser.Model.Providers;
namespace MediaBrowser.Controller.Entities.Movies
{
/// <summary>
/// Class Movie.
6 years ago
/// </summary>
public class Movie : Video, IHasSpecialFeatures, IHasTrailers, IHasLookupInfo<MovieInfo>, ISupportsBoxSetGrouping
{
4 years ago
/// <inheritdoc />
[JsonIgnore]
public IReadOnlyList<Guid> SpecialFeatureIds => GetExtras()
.Where(extra => extra.ExtraType != null && extra is Video)
.Select(extra => extra.Id)
.ToArray();
/// <inheritdoc />
[JsonIgnore]
public IReadOnlyList<BaseItem> LocalTrailers => GetExtras()
.Where(extra => extra.ExtraType == Model.Entities.ExtraType.Trailer)
.ToArray();
6 years ago
/// <summary>
/// Gets or sets the name of the TMDb collection.
6 years ago
/// </summary>
/// <value>The name of the TMDb collection.</value>
6 years ago
public string TmdbCollectionName { get; set; }
[JsonIgnore]
6 years ago
public string CollectionName
{
get => TmdbCollectionName;
set => TmdbCollectionName = value;
6 years ago
}
4 years ago
[JsonIgnore]
public override bool StopRefreshIfLocalMetadataFound => false;
6 years ago
public override double GetDefaultPrimaryImageAspectRatio()
{
// hack for tv plugins
if (SourceType == SourceType.Channel)
{
return 0;
}
return 2.0 / 3;
6 years ago
}
4 years ago
/// <inheritdoc />
6 years ago
public override UnratedItem GetBlockUnratedType()
{
return UnratedItem.Movie;
}
public MovieInfo GetLookupInfo()
{
var info = GetItemLookupInfo<MovieInfo>();
if (!IsInMixedFolder)
{
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;
}
return info;
}
4 years ago
/// <inheritdoc />
public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
6 years ago
{
var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
6 years ago
if (!ProductionYear.HasValue)
{
var info = LibraryManager.ParseName(Name);
var yearInName = info.Year;
if (yearInName.HasValue)
{
ProductionYear = yearInName;
hasChanges = true;
}
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;
}
}
}
}
return hasChanges;
}
4 years ago
/// <inheritdoc />
6 years ago
public override List<ExternalUrl> GetRelatedUrls()
{
var list = base.GetRelatedUrls();
var imdbId = this.GetProviderId(MetadataProvider.Imdb);
6 years ago
if (!string.IsNullOrEmpty(imdbId))
{
list.Add(new ExternalUrl
{
Name = "Trakt",
4 years ago
Url = string.Format(CultureInfo.InvariantCulture, "https://trakt.tv/movies/{0}", imdbId)
6 years ago
});
}
return list;
}
}
}