jellyfin/MediaBrowser.Controller/Entities/Video.cs

806 lines
26 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
2014-06-02 19:01:30 -07:00
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
2013-02-20 18:33:05 -07:00
using System.Collections.Generic;
2016-03-19 08:38:05 -07:00
using System.Globalization;
2013-02-20 18:33:05 -07:00
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
2017-05-25 23:48:54 -07:00
2016-03-19 08:38:05 -07:00
using MediaBrowser.Controller.Channels;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Extensions;
2013-02-20 18:33:05 -07:00
namespace MediaBrowser.Controller.Entities
{
/// <summary>
/// Class Video
/// </summary>
2014-12-02 20:13:03 -07:00
public class Video : BaseItem,
IHasAspectRatio,
2014-06-02 19:01:30 -07:00
ISupportsPlaceHolders,
2016-10-30 21:28:23 -07:00
IHasMediaSources
2013-02-20 18:33:05 -07:00
{
2016-05-05 21:50:39 -07:00
[IgnoreDataMember]
public string PrimaryVersionId { get; set; }
2017-08-10 11:01:31 -07:00
public string[] AdditionalParts { get; set; }
public string[] LocalAlternateVersions { get; set; }
public LinkedChild[] LinkedAlternateVersions { get; set; }
2016-10-10 23:46:59 -07:00
[IgnoreDataMember]
public override bool SupportsPlayedStatus
{
get
{
return true;
2016-12-11 22:49:19 -07:00
}
}
2017-06-29 12:10:58 -07:00
[IgnoreDataMember]
public override bool SupportsInheritedParentImages
{
get
{
return true;
}
}
2016-12-11 22:49:19 -07:00
[IgnoreDataMember]
public override bool SupportsPositionTicksResume
{
get
{
2017-07-10 00:37:00 -07:00
var extraType = ExtraType;
if (extraType.HasValue)
{
if (extraType.Value == Model.Entities.ExtraType.Sample)
{
return false;
}
if (extraType.Value == Model.Entities.ExtraType.ThemeVideo)
{
return false;
}
if (extraType.Value == Model.Entities.ExtraType.Trailer)
{
return false;
}
}
2016-12-11 22:49:19 -07:00
return true;
2016-10-10 23:46:59 -07:00
}
}
public override string CreatePresentationUniqueKey()
2016-05-01 15:11:24 -07:00
{
if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
2016-05-01 15:11:24 -07:00
{
return PrimaryVersionId;
2016-05-01 15:11:24 -07:00
}
return base.CreatePresentationUniqueKey();
2016-05-01 15:11:24 -07:00
}
2016-07-24 09:46:17 -07:00
[IgnoreDataMember]
public override bool EnableRefreshOnDateModifiedChange
2016-07-24 09:46:17 -07:00
{
get
{
return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
}
2016-07-24 09:46:17 -07:00
}
2016-10-09 00:18:43 -07:00
[IgnoreDataMember]
public override bool SupportsThemeMedia
{
get { return true; }
}
/// <summary>
/// Gets or sets the timestamp.
/// </summary>
/// <value>The timestamp.</value>
2014-04-24 19:45:06 -07:00
public TransportStreamTimestamp? Timestamp { get; set; }
2014-12-02 20:13:03 -07:00
2016-05-05 21:50:39 -07:00
/// <summary>
/// Gets or sets the subtitle paths.
/// </summary>
/// <value>The subtitle paths.</value>
2017-08-10 11:01:31 -07:00
public string[] SubtitleFiles { get; set; }
2016-05-05 21:50:39 -07:00
/// <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 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>
/// Gets the playable stream files.
/// </summary>
/// <returns>List{System.String}.</returns>
2017-08-19 12:43:35 -07:00
public string[] GetPlayableStreamFiles()
2016-05-05 21:50:39 -07:00
{
return GetPlayableStreamFiles(Path);
}
2017-08-19 12:43:35 -07:00
public string[] GetPlayableStreamFileNames()
2017-08-05 12:02:33 -07:00
{
2017-08-19 12:43:35 -07:00
return GetPlayableStreamFiles().Select(System.IO.Path.GetFileName).ToArray();
2017-08-05 12:02:33 -07:00
}
2016-05-05 21:50:39 -07:00
/// <summary>
/// Gets or sets the aspect ratio.
/// </summary>
/// <value>The aspect ratio.</value>
public string AspectRatio { get; set; }
2013-05-01 19:44:52 -07:00
public Video()
{
2017-08-10 11:01:31 -07:00
AdditionalParts = EmptyStringArray;
LocalAlternateVersions = EmptyStringArray;
SubtitleFiles = EmptyStringArray;
LinkedAlternateVersions = EmptyLinkedChildArray;
}
2015-02-05 22:39:07 -07:00
public override bool CanDownload()
{
2017-08-07 13:36:41 -07:00
if (VideoType == VideoType.Dvd || VideoType == VideoType.BluRay)
2015-02-05 22:39:07 -07:00
{
return false;
}
var locationType = LocationType;
return locationType != LocationType.Remote &&
locationType != LocationType.Virtual;
}
2014-08-30 07:26:29 -07:00
[IgnoreDataMember]
public override bool SupportsAddingToPlaylist
{
2016-10-09 00:18:43 -07:00
get { return true; }
}
[IgnoreDataMember]
2014-03-22 09:16:43 -07:00
public int MediaSourceCount
{
get
{
2016-05-05 21:50:39 -07:00
if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
2016-05-01 15:11:24 -07:00
{
2016-05-05 21:50:39 -07:00
var item = LibraryManager.GetItemById(PrimaryVersionId) as Video;
2016-05-01 15:11:24 -07:00
if (item != null)
{
return item.MediaSourceCount;
}
}
2017-08-10 11:01:31 -07:00
return LinkedAlternateVersions.Length + LocalAlternateVersions.Length + 1;
}
}
2014-12-02 20:13:03 -07:00
[IgnoreDataMember]
public bool IsStacked
{
2017-08-10 11:01:31 -07:00
get { return AdditionalParts.Length > 0; }
2014-12-02 20:13:03 -07:00
}
[IgnoreDataMember]
public bool HasLocalAlternateVersions
{
2017-08-10 11:01:31 -07:00
get { return LocalAlternateVersions.Length > 0; }
2014-12-02 20:13:03 -07:00
}
public IEnumerable<Guid> GetAdditionalPartIds()
{
return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
}
public IEnumerable<Guid> GetLocalAlternateVersionIds()
{
return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
}
2016-04-30 16:05:21 -07:00
[IgnoreDataMember]
protected virtual bool EnableDefaultVideoUserDataKeys
2016-03-19 08:38:05 -07:00
{
2016-04-30 16:05:21 -07:00
get
2016-03-19 08:38:05 -07:00
{
2016-04-30 16:05:21 -07:00
return true;
}
}
public override List<string> GetUserDataKeys()
{
var list = base.GetUserDataKeys();
2016-03-19 08:38:05 -07:00
2016-04-30 16:05:21 -07:00
if (EnableDefaultVideoUserDataKeys)
{
if (ExtraType.HasValue)
2016-03-19 08:38:05 -07:00
{
2016-04-30 16:05:21 -07:00
var key = this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, GetUserDataKey(key));
}
2016-03-19 08:38:05 -07:00
2016-04-30 16:05:21 -07:00
key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, GetUserDataKey(key));
}
}
else
{
var key = this.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrWhiteSpace(key))
2016-03-19 08:38:05 -07:00
{
2016-04-30 16:05:21 -07:00
list.Insert(0, key);
2016-03-19 08:38:05 -07:00
}
2016-04-30 16:05:21 -07:00
key = this.GetProviderId(MetadataProviders.Tmdb);
if (!string.IsNullOrWhiteSpace(key))
{
list.Insert(0, key);
}
2016-03-19 08:38:05 -07:00
}
}
2016-04-30 16:05:21 -07:00
return list;
}
private string GetUserDataKey(string providerId)
{
var key = providerId + "-" + ExtraType.ToString().ToLower();
// Make sure different trailers have their own data.
if (RunTimeTicks.HasValue)
{
key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
}
return key;
2016-03-19 08:38:05 -07:00
}
2014-03-18 18:35:40 -07:00
public IEnumerable<Video> GetLinkedAlternateVersions()
{
2017-05-24 12:12:55 -07:00
return LinkedAlternateVersions
.Select(GetLinkedChild)
.Where(i => i != null)
2017-05-24 12:12:55 -07:00
.OfType<Video>()
.OrderBy(i => i.SortName);
}
/// <summary>
/// Gets the additional parts.
/// </summary>
/// <returns>IEnumerable{Video}.</returns>
public IEnumerable<Video> GetAdditionalParts()
{
2014-12-02 20:13:03 -07:00
return GetAdditionalPartIds()
.Select(i => LibraryManager.GetItemById(i))
.Where(i => i != null)
.OfType<Video>()
.OrderBy(i => i.SortName);
2013-05-01 19:44:52 -07:00
}
2013-07-16 11:47:05 -07:00
[IgnoreDataMember]
public override string ContainingFolderPath
2013-07-16 11:47:05 -07:00
{
get
{
2014-12-02 20:13:03 -07:00
if (IsStacked)
{
2017-05-04 11:14:45 -07:00
return FileSystem.GetDirectoryName(Path);
}
2013-07-16 11:47:05 -07:00
2014-03-04 19:59:23 -07:00
if (!IsPlaceHolder)
{
2017-08-07 13:36:41 -07:00
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
2014-03-04 19:59:23 -07:00
{
return Path;
}
}
return base.ContainingFolderPath;
2013-07-16 11:47:05 -07:00
}
}
2014-12-08 21:57:18 -07:00
[IgnoreDataMember]
public override string FileNameWithoutExtension
{
get
{
if (LocationType == LocationType.FileSystem)
{
2017-08-07 13:36:41 -07:00
if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
2014-12-08 21:57:18 -07:00
{
return System.IO.Path.GetFileName(Path);
}
2014-12-29 13:18:48 -07:00
2014-12-08 21:57:18 -07:00
return System.IO.Path.GetFileNameWithoutExtension(Path);
}
return null;
}
}
2014-12-02 20:13:03 -07:00
internal override bool IsValidFromResolver(BaseItem newItem)
{
var current = this;
var newAsVideo = newItem as Video;
if (newAsVideo != null)
{
if (!current.AdditionalParts.SequenceEqual(newAsVideo.AdditionalParts, StringComparer.OrdinalIgnoreCase))
{
return false;
}
if (!current.LocalAlternateVersions.SequenceEqual(newAsVideo.LocalAlternateVersions, StringComparer.OrdinalIgnoreCase))
{
return false;
}
2016-04-27 18:59:09 -07:00
if (newAsVideo.VideoType != VideoType)
{
return false;
}
2014-12-02 20:13:03 -07:00
}
return base.IsValidFromResolver(newItem);
}
2013-02-20 18:33:05 -07:00
/// <summary>
/// Gets the playable stream files.
/// </summary>
/// <param name="rootPath">The root path.</param>
/// <returns>List{System.String}.</returns>
2017-08-19 12:43:35 -07:00
public string[] GetPlayableStreamFiles(string rootPath)
2013-02-20 18:33:05 -07:00
{
2017-08-07 13:36:41 -07:00
if (VideoType == VideoType.VideoFile)
{
2017-08-19 12:43:35 -07:00
return new string[] { };
2017-08-07 13:36:41 -07:00
}
2015-09-24 10:50:49 -07:00
var allFiles = FileSystem.GetFilePaths(rootPath, true).ToList();
2013-02-20 18:33:05 -07:00
2017-08-05 12:02:33 -07:00
var videoType = VideoType;
if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.BluRay)
{
videoType = VideoType.BluRay;
}
else if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.Dvd)
{
videoType = VideoType.Dvd;
}
return QueryPlayableStreamFiles(rootPath, videoType).Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
2013-02-20 18:33:05 -07:00
.Where(f => !string.IsNullOrEmpty(f))
2017-08-19 12:43:35 -07:00
.ToArray();
2013-02-20 18:33:05 -07:00
}
2017-08-19 12:43:35 -07:00
public static string[] QueryPlayableStreamFiles(string rootPath, VideoType videoType)
2017-08-05 12:02:33 -07:00
{
if (videoType == VideoType.Dvd)
{
return FileSystem.GetFiles(rootPath, new[] { ".vob" }, false, true)
.OrderByDescending(i => i.Length)
.ThenBy(i => i.FullName)
.Take(1)
.Select(i => i.FullName)
2017-08-19 12:43:35 -07:00
.ToArray();
2017-08-05 12:02:33 -07:00
}
if (videoType == VideoType.BluRay)
{
return FileSystem.GetFiles(rootPath, new[] { ".m2ts" }, false, true)
.OrderByDescending(i => i.Length)
.ThenBy(i => i.FullName)
.Take(1)
.Select(i => i.FullName)
2017-08-19 12:43:35 -07:00
.ToArray();
2017-08-05 12:02:33 -07:00
}
2017-08-19 12:43:35 -07:00
return new string[] { };
2017-08-05 12:02:33 -07:00
}
2013-02-20 18:33:05 -07:00
/// <summary>
/// Gets a value indicating whether [is3 D].
/// </summary>
/// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool Is3D
{
2013-06-25 11:10:39 -07:00
get { return Video3DFormat.HasValue; }
2013-02-20 18:33:05 -07:00
}
/// <summary>
/// Gets the type of the media.
/// </summary>
/// <value>The type of the media.</value>
2014-08-30 07:26:29 -07:00
[IgnoreDataMember]
2013-02-20 18:33:05 -07:00
public override string MediaType
{
get
{
return Model.Entities.MediaType.Video;
}
}
2015-10-03 20:38:46 -07:00
protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
{
2014-02-10 11:39:41 -07:00
var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
2014-12-02 20:13:03 -07:00
if (IsStacked)
{
var tasks = AdditionalParts
2016-10-16 10:11:32 -07:00
.Select(i => RefreshMetadataForOwnedVideo(options, true, i, cancellationToken));
2014-12-02 20:13:03 -07:00
await Task.WhenAll(tasks).ConfigureAwait(false);
}
// Must have a parent to have additional parts or alternate versions
2013-06-17 13:35:43 -07:00
// In other words, it must be part of the Parent/Child tree
// The additional parts won't have additional parts themselves
2015-11-11 07:56:31 -07:00
if (LocationType == LocationType.FileSystem && GetParent() != null)
{
2014-12-02 20:13:03 -07:00
if (!IsStacked)
{
RefreshLinkedAlternateVersions();
2014-12-02 20:13:03 -07:00
var tasks = LocalAlternateVersions
2016-10-16 10:11:32 -07:00
.Select(i => RefreshMetadataForOwnedVideo(options, false, i, cancellationToken));
2014-12-02 20:13:03 -07:00
await Task.WhenAll(tasks).ConfigureAwait(false);
}
}
2014-02-10 11:39:41 -07:00
return hasChanges;
}
2014-12-02 20:13:03 -07:00
private void RefreshLinkedAlternateVersions()
{
foreach (var child in LinkedAlternateVersions)
{
// Reset the cached value
if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
{
child.ItemId = null;
}
}
}
public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
{
await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
2014-12-16 22:30:31 -07:00
var localAlternates = GetLocalAlternateVersionIds()
.Select(i => LibraryManager.GetItemById(i))
.Where(i => i != null);
foreach (var item in localAlternates)
{
item.ImageInfos = ImageInfos;
item.Overview = Overview;
item.ProductionYear = ProductionYear;
item.PremiereDate = PremiereDate;
item.CommunityRating = CommunityRating;
item.OfficialRating = OfficialRating;
item.Genres = Genres;
item.ProviderIds = ProviderIds;
2014-04-07 21:17:18 -07:00
await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
}
}
public override IEnumerable<FileSystemMetadata> GetDeletePaths()
{
2017-07-30 22:16:22 -07:00
if (!IsInMixedFolder)
{
return new[] {
new FileSystemMetadata
{
FullName = ContainingFolderPath,
IsDirectory = true
}
};
}
return base.GetDeletePaths();
}
2017-08-05 12:02:33 -07:00
public List<MediaStream> GetMediaStreams()
{
2017-08-05 12:02:33 -07:00
return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
{
2017-08-05 12:02:33 -07:00
ItemId = Id
});
}
2013-12-07 18:42:15 -07:00
public virtual MediaStream GetDefaultVideoStream()
{
if (!DefaultVideoStreamIndex.HasValue)
{
return null;
}
return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
{
ItemId = Id,
Index = DefaultVideoStreamIndex.Value
}).FirstOrDefault();
}
2014-06-02 19:01:30 -07:00
2016-05-01 15:11:24 -07:00
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)));
2016-05-05 21:50:39 -07:00
if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
2016-05-01 15:11:24 -07:00
{
2016-05-05 21:50:39 -07:00
var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
2016-05-01 15:11:24 -07:00
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;
}
2017-08-05 12:02:33 -07:00
public virtual List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
2014-06-02 19:01:30 -07:00
{
2016-03-19 08:38:05 -07:00
if (SourceType == SourceType.Channel)
{
2016-12-23 01:54:30 -07:00
var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
2017-05-25 23:48:54 -07:00
.ToList();
2016-03-19 08:38:05 -07:00
if (sources.Count > 0)
{
return sources;
}
return new List<MediaSourceInfo>
{
GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
};
}
2016-05-01 15:11:24 -07:00
var list = GetAllVideosForMediaSources();
var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
2014-06-02 19:01:30 -07:00
return result.OrderBy(i =>
{
2015-03-07 15:43:53 -07:00
if (i.VideoType == VideoType.VideoFile)
2014-06-02 19:01:30 -07:00
{
return 0;
}
return 1;
}).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
.ThenByDescending(i =>
{
var stream = i.VideoStream;
return stream == null || stream.Width == null ? 0 : stream.Width.Value;
})
.ToList();
}
2017-04-28 12:17:26 -07:00
private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
2014-06-02 19:01:30 -07:00
{
2017-04-28 12:17:26 -07:00
if (media == null)
{
throw new ArgumentNullException("media");
}
2017-08-05 12:02:33 -07:00
var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id);
2014-06-02 19:01:30 -07:00
2017-04-28 12:17:26 -07:00
var locationType = media.LocationType;
2014-12-02 20:13:03 -07:00
2014-06-02 19:01:30 -07:00
var info = new MediaSourceInfo
{
2017-04-28 12:17:26 -07:00
Id = media.Id.ToString("N"),
IsoType = media.IsoType,
Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
2014-06-02 19:01:30 -07:00
MediaStreams = mediaStreams,
2017-04-28 12:17:26 -07:00
Name = GetMediaSourceName(media, mediaStreams),
Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
RunTimeTicks = media.RunTimeTicks,
Video3DFormat = media.Video3DFormat,
VideoType = media.VideoType,
Container = media.Container,
Size = media.Size,
Timestamp = media.Timestamp,
2014-06-11 19:38:40 -07:00
Type = type,
2017-04-28 12:17:26 -07:00
SupportsDirectStream = media.VideoType == VideoType.VideoFile,
IsRemote = media.IsShortcut
2014-06-02 19:01:30 -07:00
};
if (info.Protocol == MediaProtocol.File)
{
2017-04-28 12:17:26 -07:00
info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
}
2017-04-28 12:17:26 -07:00
if (media.IsShortcut)
{
2017-04-28 12:17:26 -07:00
info.Path = media.ShortcutPath;
2017-05-24 12:12:55 -07:00
if (!string.IsNullOrWhiteSpace(info.Path))
{
2017-05-24 12:12:55 -07:00
if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Http;
2017-06-05 23:13:49 -07:00
info.SupportsDirectStream = false;
2017-05-24 12:12:55 -07:00
}
else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Rtmp;
2017-06-05 23:13:49 -07:00
info.SupportsDirectStream = false;
2017-05-24 12:12:55 -07:00
}
else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
{
info.Protocol = MediaProtocol.Rtsp;
2017-06-05 23:13:49 -07:00
info.SupportsDirectStream = false;
2017-05-24 12:12:55 -07:00
}
else
{
info.Protocol = MediaProtocol.File;
}
}
}
2014-06-02 19:01:30 -07:00
if (string.IsNullOrEmpty(info.Container))
{
2017-04-28 12:17:26 -07:00
if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
2014-06-02 19:01:30 -07:00
{
2017-04-28 12:17:26 -07:00
if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
2014-06-02 19:01:30 -07:00
{
2017-04-28 12:17:26 -07:00
info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
2014-06-02 19:01:30 -07:00
}
}
}
2017-04-28 12:17:26 -07:00
info.Bitrate = media.TotalBitrate;
2017-01-21 13:27:07 -07:00
info.InferTotalBitrate();
2014-06-02 19:01:30 -07:00
return info;
}
private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
{
var terms = new List<string>();
var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
if (video.Video3DFormat.HasValue)
{
terms.Add("3D");
}
if (video.VideoType == VideoType.BluRay)
{
terms.Add("Bluray");
}
else if (video.VideoType == VideoType.Dvd)
{
terms.Add("DVD");
}
else if (video.VideoType == VideoType.Iso)
{
if (video.IsoType.HasValue)
{
if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
{
terms.Add("Bluray");
}
else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
{
terms.Add("DVD");
}
}
else
{
terms.Add("ISO");
}
}
if (videoStream != null)
{
if (videoStream.Width.HasValue)
{
if (videoStream.Width.Value >= 3800)
{
terms.Add("4K");
}
else if (videoStream.Width.Value >= 1900)
{
terms.Add("1080P");
}
else if (videoStream.Width.Value >= 1270)
{
terms.Add("720P");
}
else if (videoStream.Width.Value >= 700)
{
terms.Add("480P");
}
else
{
terms.Add("SD");
}
}
}
if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
{
terms.Add(videoStream.Codec.ToUpper());
}
if (audioStream != null)
{
var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
? audioStream.Profile
: audioStream.Codec;
if (!string.IsNullOrEmpty(audioCodec))
{
terms.Add(audioCodec.ToUpper());
}
}
return string.Join("/", terms.ToArray(terms.Count));
2014-06-02 19:01:30 -07:00
}
2013-02-20 18:33:05 -07:00
}
}