/// <summary> /// Gets the input argument. /// </summary> /// <param name="video">The video.</param> /// <param name="isoMount">The iso mount.</param> /// <param name="type">The type.</param> /// <returns>System.String[][].</returns> public static string[] GetInputArgument(Video video, IIsoMount isoMount, out InputType type) { var inputPath = isoMount == null ? new[] { video.Path } : new[] { isoMount.MountedPath }; type = InputType.VideoFile; switch (video.VideoType) { case VideoType.BluRay: type = InputType.Bluray; break; case VideoType.Dvd: type = InputType.Dvd; inputPath = video.GetPlayableStreamFiles(inputPath[0]).ToArray(); break; case VideoType.Iso: if (video.IsoType.HasValue) { switch (video.IsoType.Value) { case IsoType.BluRay: type = InputType.Bluray; break; case IsoType.Dvd: type = InputType.Dvd; inputPath = video.GetPlayableStreamFiles(inputPath[0]).ToArray(); break; } } break; case VideoType.VideoFile: { if (video.LocationType == LocationType.Remote) { type = InputType.Url; } break; } } return inputPath; }
public static string GetMovieSavePath(Video item) { if (item.IsInMixedFolder) { return Path.ChangeExtension(item.Path, ".xml"); } return Path.Combine(item.ContainingFolderPath, "movie.xml"); }
private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type) { var mediaStreams = MediaSourceManager.GetMediaStreams(i.Id) .ToList(); var locationType = i.LocationType; var info = new MediaSourceInfo { Id = i.Id.ToString("N"), IsoType = i.IsoType, Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File, MediaStreams = mediaStreams, Name = GetMediaSourceName(i, mediaStreams), Path = enablePathSubstitution ? GetMappedPath(i.Path, locationType) : i.Path, RunTimeTicks = i.RunTimeTicks, Video3DFormat = i.Video3DFormat, VideoType = i.VideoType, Container = i.Container, Size = i.Size, Timestamp = i.Timestamp, Type = type, PlayableStreamFileNames = i.PlayableStreamFileNames.ToList(), SupportsDirectStream = i.VideoType == VideoType.VideoFile }; if (info.Protocol == MediaProtocol.File) { info.ETag = i.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N"); } if (i.IsShortcut) { info.Path = i.ShortcutPath; if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Http; } else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Rtmp; } else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Rtsp; } else { info.Protocol = MediaProtocol.File; } } if (string.IsNullOrEmpty(info.Container)) { if (i.VideoType == VideoType.VideoFile || i.VideoType == VideoType.Iso) { if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual) { info.Container = System.IO.Path.GetExtension(i.Path).TrimStart('.'); } } } try { var bitrate = i.TotalBitrate ?? info.MediaStreams.Where(m => m.Type != MediaStreamType.Subtitle && !string.Equals(m.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)) .Select(m => m.BitRate ?? 0) .Sum(); if (bitrate > 0) { info.Bitrate = bitrate; } } catch (OverflowException ex) { Logger.ErrorException("Error calculating total bitrate", ex); } 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.HdDvd) { terms.Add("HD-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()); }
private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type) { if (media == null) { throw new ArgumentNullException("media"); } var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id); var locationType = media.LocationType; var info = new MediaSourceInfo { Id = media.Id.ToString("N"), IsoType = media.IsoType, Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File, MediaStreams = mediaStreams, 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, Type = type, SupportsDirectStream = media.VideoType == VideoType.VideoFile, IsRemote = media.IsShortcut }; if (info.Protocol == MediaProtocol.File) { info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N"); } if (media.IsShortcut) { info.Path = media.ShortcutPath; if (!string.IsNullOrWhiteSpace(info.Path)) { if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Http; info.SupportsDirectStream = false; } else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Rtmp; info.SupportsDirectStream = false; } else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase)) { info.Protocol = MediaProtocol.Rtsp; info.SupportsDirectStream = false; } else { info.Protocol = MediaProtocol.File; } } } if (string.IsNullOrEmpty(info.Container)) { if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso) { if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual) { info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.'); } } } info.Bitrate = media.TotalBitrate; info.InferTotalBitrate(); return(info); }