diff options
Diffstat (limited to 'MediaBrowser.Controller/Entities/Video.cs')
| -rw-r--r-- | MediaBrowser.Controller/Entities/Video.cs | 293 |
1 files changed, 177 insertions, 116 deletions
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 511606efc..eba1e466a 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -21,14 +21,14 @@ namespace MediaBrowser.Controller.Entities /// </summary> public class Video : BaseItem, IHasAspectRatio, - IHasTags, ISupportsPlaceHolders, IHasMediaSources, IHasShortOverview, IThemeMedia, IArchivable { - public Guid? PrimaryVersionId { get; set; } + [IgnoreDataMember] + public string PrimaryVersionId { get; set; } public List<string> AdditionalParts { get; set; } public List<string> LocalAlternateVersions { get; set; } @@ -44,10 +44,27 @@ namespace MediaBrowser.Controller.Entities } } - public long? Size { get; set; } - public string Container { get; set; } + [IgnoreDataMember] + public override string PresentationUniqueKey + { + get + { + if (!string.IsNullOrWhiteSpace(PrimaryVersionId)) + { + return PrimaryVersionId; + } + + return base.PresentationUniqueKey; + } + } + + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + public int? TotalBitrate { get; set; } - public string ShortOverview { get; set; } public ExtraType? ExtraType { get; set; } /// <summary> @@ -56,6 +73,72 @@ namespace MediaBrowser.Controller.Entities /// <value>The timestamp.</value> public TransportStreamTimestamp? Timestamp { get; set; } + /// <summary> + /// Gets or sets the subtitle paths. + /// </summary> + /// <value>The subtitle paths.</value> + public List<string> SubtitleFiles { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether this instance has subtitles. + /// </summary> + /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value> + public bool HasSubtitles { get; set; } + + public bool IsPlaceHolder { get; set; } + public bool IsShortcut { get; set; } + public string ShortcutPath { get; set; } + + /// <summary> + /// Gets or sets the video bit rate. + /// </summary> + /// <value>The video bit rate.</value> + public int? VideoBitRate { get; set; } + + /// <summary> + /// Gets or sets the default index of the video stream. + /// </summary> + /// <value>The default index of the video stream.</value> + public int? DefaultVideoStreamIndex { get; set; } + + /// <summary> + /// Gets or sets the type of the video. + /// </summary> + /// <value>The type of the video.</value> + public VideoType VideoType { get; set; } + + /// <summary> + /// Gets or sets the type of the iso. + /// </summary> + /// <value>The type of the iso.</value> + public IsoType? IsoType { get; set; } + + /// <summary> + /// Gets or sets the video3 D format. + /// </summary> + /// <value>The video3 D format.</value> + public Video3DFormat? Video3DFormat { get; set; } + + /// <summary> + /// If the video is a folder-rip, this will hold the file list for the largest playlist + /// </summary> + public List<string> PlayableStreamFileNames { get; set; } + + /// <summary> + /// Gets the playable stream files. + /// </summary> + /// <returns>List{System.String}.</returns> + public List<string> GetPlayableStreamFiles() + { + return GetPlayableStreamFiles(Path); + } + + /// <summary> + /// Gets or sets the aspect ratio. + /// </summary> + /// <value>The aspect ratio.</value> + public string AspectRatio { get; set; } + public Video() { PlayableStreamFileNames = new List<string>(); @@ -80,23 +163,6 @@ namespace MediaBrowser.Controller.Entities } [IgnoreDataMember] - public override LocationType LocationType - { - get - { - if (SourceType == SourceType.Channel) - { - if (string.IsNullOrEmpty(Path)) - { - return LocationType.Remote; - } - } - - return base.LocationType; - } - } - - [IgnoreDataMember] public override bool SupportsAddingToPlaylist { get { return LocationType == LocationType.FileSystem && RunTimeTicks.HasValue; } @@ -107,6 +173,14 @@ namespace MediaBrowser.Controller.Entities { get { + if (!string.IsNullOrWhiteSpace(PrimaryVersionId)) + { + var item = LibraryManager.GetItemById(PrimaryVersionId) as Video; + if (item != null) + { + return item.MediaSourceCount; + } + } return LinkedAlternateVersions.Count + LocalAlternateVersions.Count + 1; } } @@ -148,42 +222,65 @@ namespace MediaBrowser.Controller.Entities return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video))); } - protected override string CreateUserDataKey() + [IgnoreDataMember] + protected virtual bool EnableDefaultVideoUserDataKeys { - if (ExtraType.HasValue) + get { - var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb); + return true; + } + } + + public override List<string> GetUserDataKeys() + { + var list = base.GetUserDataKeys(); - if (!string.IsNullOrWhiteSpace(key)) + if (EnableDefaultVideoUserDataKeys) + { + if (ExtraType.HasValue) { - key = key + "-" + ExtraType.ToString().ToLower(); + var key = this.GetProviderId(MetadataProviders.Tmdb); + if (!string.IsNullOrWhiteSpace(key)) + { + list.Insert(0, GetUserDataKey(key)); + } - // Make sure different trailers have their own data. - if (RunTimeTicks.HasValue) + key = this.GetProviderId(MetadataProviders.Imdb); + if (!string.IsNullOrWhiteSpace(key)) { - key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture); + list.Insert(0, GetUserDataKey(key)); + } + } + else + { + var key = this.GetProviderId(MetadataProviders.Imdb); + if (!string.IsNullOrWhiteSpace(key)) + { + list.Insert(0, key); } - return key; + key = this.GetProviderId(MetadataProviders.Tmdb); + if (!string.IsNullOrWhiteSpace(key)) + { + list.Insert(0, key); + } } } - return base.CreateUserDataKey(); + return list; } - /// <summary> - /// Gets the linked children. - /// </summary> - /// <returns>IEnumerable{BaseItem}.</returns> - public IEnumerable<Video> GetAlternateVersions() + private string GetUserDataKey(string providerId) { - var filesWithinSameDirectory = GetLocalAlternateVersionIds() - .Select(i => LibraryManager.GetItemById(i)) - .Where(i => i != null) - .OfType<Video>(); + var key = providerId + "-" + ExtraType.ToString().ToLower(); - return filesWithinSameDirectory.Concat(GetLinkedAlternateVersions()) - .OrderBy(i => i.SortName); + // Make sure different trailers have their own data. + if (RunTimeTicks.HasValue) + { + key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture); + } + + return key; } public IEnumerable<Video> GetLinkedAlternateVersions() @@ -210,72 +307,6 @@ namespace MediaBrowser.Controller.Entities .OrderBy(i => i.SortName); } - /// <summary> - /// Gets or sets the subtitle paths. - /// </summary> - /// <value>The subtitle paths.</value> - public List<string> SubtitleFiles { get; set; } - - /// <summary> - /// Gets or sets a value indicating whether this instance has subtitles. - /// </summary> - /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value> - public bool HasSubtitles { get; set; } - - public bool IsPlaceHolder { get; set; } - public bool IsShortcut { get; set; } - public string ShortcutPath { get; set; } - - /// <summary> - /// Gets or sets the video bit rate. - /// </summary> - /// <value>The video bit rate.</value> - public int? VideoBitRate { get; set; } - - /// <summary> - /// Gets or sets the default index of the video stream. - /// </summary> - /// <value>The default index of the video stream.</value> - public int? DefaultVideoStreamIndex { get; set; } - - /// <summary> - /// Gets or sets the type of the video. - /// </summary> - /// <value>The type of the video.</value> - public VideoType VideoType { get; set; } - - /// <summary> - /// Gets or sets the type of the iso. - /// </summary> - /// <value>The type of the iso.</value> - public IsoType? IsoType { get; set; } - - /// <summary> - /// Gets or sets the video3 D format. - /// </summary> - /// <value>The video3 D format.</value> - public Video3DFormat? Video3DFormat { get; set; } - - /// <summary> - /// If the video is a folder-rip, this will hold the file list for the largest playlist - /// </summary> - public List<string> PlayableStreamFileNames { get; set; } - - /// <summary> - /// Gets the playable stream files. - /// </summary> - /// <returns>List{System.String}.</returns> - public List<string> GetPlayableStreamFiles() - { - return GetPlayableStreamFiles(Path); - } - - /// <summary> - /// Gets or sets the aspect ratio. - /// </summary> - /// <value>The aspect ratio.</value> - public string AspectRatio { get; set; } - [IgnoreDataMember] public override string ContainingFolderPath { @@ -334,6 +365,11 @@ namespace MediaBrowser.Controller.Entities { return false; } + + if (newAsVideo.VideoType != VideoType) + { + return false; + } } return base.IsValidFromResolver(newItem); @@ -480,6 +516,36 @@ namespace MediaBrowser.Controller.Entities }).FirstOrDefault(); } + private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources() + { + var list = new List<Tuple<Video, MediaSourceType>>(); + + list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default)); + list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping))); + + if (!string.IsNullOrWhiteSpace(PrimaryVersionId)) + { + var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video; + if (primary != null) + { + var existingIds = list.Select(i => i.Item1.Id).ToList(); + list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping)); + list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping))); + } + } + + var localAlternates = list + .SelectMany(i => i.Item1.GetLocalAlternateVersionIds()) + .Select(LibraryManager.GetItemById) + .Where(i => i != null) + .OfType<Video>() + .ToList(); + + list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default))); + + return list; + } + public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution) { if (SourceType == SourceType.Channel) @@ -498,13 +564,8 @@ namespace MediaBrowser.Controller.Entities }; } - var item = this; - - var result = item.GetAlternateVersions() - .Select(i => GetVersionInfo(enablePathSubstitution, i, MediaSourceType.Grouping)) - .ToList(); - - result.Add(GetVersionInfo(enablePathSubstitution, item, MediaSourceType.Default)); + var list = GetAllVideosForMediaSources(); + var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList(); return result.OrderBy(i => { |
