using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Controller.Channels;
namespace MediaBrowser.Controller.Entities
{
///
/// Class Video
///
public class Video : BaseItem,
IHasAspectRatio,
IHasTags,
ISupportsPlaceHolders,
IHasMediaSources,
IHasShortOverview,
IThemeMedia,
IArchivable
{
public Guid? PrimaryVersionId { get; set; }
public List AdditionalParts { get; set; }
public List LocalAlternateVersions { get; set; }
public List LinkedAlternateVersions { get; set; }
public List ChannelMediaSources { get; set; }
[IgnoreDataMember]
public bool IsThemeMedia
{
get
{
return ExtraType.HasValue && ExtraType.Value == Model.Entities.ExtraType.ThemeVideo;
}
}
public long? Size { get; set; }
public string Container { get; set; }
public int? TotalBitrate { get; set; }
public string ShortOverview { get; set; }
public ExtraType? ExtraType { get; set; }
///
/// Gets or sets the timestamp.
///
/// The timestamp.
public TransportStreamTimestamp? Timestamp { get; set; }
public Video()
{
PlayableStreamFileNames = new List();
AdditionalParts = new List();
LocalAlternateVersions = new List();
Tags = new List();
SubtitleFiles = new List();
LinkedAlternateVersions = new List();
}
public override bool CanDownload()
{
if (VideoType == VideoType.HdDvd || VideoType == VideoType.Dvd ||
VideoType == VideoType.BluRay)
{
return false;
}
var locationType = LocationType;
return locationType != LocationType.Remote &&
locationType != LocationType.Virtual;
}
[IgnoreDataMember]
public override bool SupportsAddingToPlaylist
{
get { return LocationType == LocationType.FileSystem && RunTimeTicks.HasValue; }
}
[IgnoreDataMember]
public int MediaSourceCount
{
get
{
return LinkedAlternateVersions.Count + LocalAlternateVersions.Count + 1;
}
}
[IgnoreDataMember]
public bool IsStacked
{
get { return AdditionalParts.Count > 0; }
}
[IgnoreDataMember]
public bool HasLocalAlternateVersions
{
get { return LocalAlternateVersions.Count > 0; }
}
[IgnoreDataMember]
public bool IsArchive
{
get
{
if (string.IsNullOrWhiteSpace(Path))
{
return false;
}
var ext = System.IO.Path.GetExtension(Path) ?? string.Empty;
return new[] { ".zip", ".rar", ".7z" }.Contains(ext, StringComparer.OrdinalIgnoreCase);
}
}
public IEnumerable GetAdditionalPartIds()
{
return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
}
public IEnumerable GetLocalAlternateVersionIds()
{
return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
}
protected override string CreateUserDataKey()
{
if (ExtraType.HasValue)
{
var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
key = key + "-" + ExtraType.ToString().ToLower();
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
}
return key;
}
}
return base.CreateUserDataKey();
}
///
/// Gets the linked children.
///
/// IEnumerable{BaseItem}.
public IEnumerable