public YoutubeVideoFormat(YoutubeVideoInfo source, JToken data) { this.VideoInfo = source; this.FileExtension = data.Value <string>("ext"); this.FormatID = data.Value <string>("format_id"); this.FormatNote = data.Value <string>("format_note"); this.FormatName = data.Value <string>("format"); this.Protocol = data.Value <string>("protocol"); string tmp_str = data.Value <string>("acodec"); if (string.IsNullOrEmpty(tmp_str) || string.Equals(tmp_str, "none", StringComparison.OrdinalIgnoreCase)) { this.AudioCodec = null; } else { this.AudioSampleRate = data.Value <int?>("asr"); this.AudioCodec = tmp_str; } tmp_str = data.Value <string>("vcodec"); if (string.IsNullOrEmpty(tmp_str) || string.Equals(tmp_str, "none", StringComparison.OrdinalIgnoreCase)) { this.VideoResolution = new System.Windows.Size(0, 0); this.VideoCodec = null; } else { int?int_width = data.Value <int?>("width"), int_height = data.Value <int?>("height"); this.VideoResolution = new System.Windows.Size(int_width.HasValue ? int_width.Value : 0, int_height.HasValue ? int_height.Value : 0); this.VideoCodec = tmp_str; } this.FPS = data.Value <int?>("fps"); this.Bitrate = data.Value <double>("tbr"); this.AudioBirate = data.Value <int?>("abr"); tmp_str = data.Value <string>("url"); if (string.IsNullOrWhiteSpace(tmp_str)) { this.DirectLink = null; } else { this.DirectLink = new Uri(tmp_str); } this.FileSize = data.Value <long?>("filesize"); }
/// <summary> /// Prepare a download session for the given video information and its format /// </summary> /// <param name="videoInfo">Video information</param> /// <param name="formatID">The format ID of the video</param> /// <exception cref="ArgumentNullException"><paramref name="formatID"/> is null or whitespace.</exception> /// <exception cref="InvalidOperationException">No format matched the <paramref name="formatID"/>.</exception> /// <returns></returns> public VideoDownloadSession PrepareVideoDownload(YoutubeVideoInfo videoInfo, string formatID) { if (string.IsNullOrWhiteSpace(formatID)) { throw new ArgumentNullException(nameof(formatID)); } if (videoInfo.Formats.Count == 0) { throw new InvalidOperationException("The video has no available format to download."); } return(this.PrepareVideoDownload(videoInfo.Formats.First(x => string.Equals(x.FormatID, formatID)))); }