private async Task DownloadVideosAsync() { try { downloading = true; int count = 0, selectedVideos = 0; for (int i = 0; i < gvVideos.RowCount; i++) { if (Convert.ToBoolean(gvVideos.Rows[i].Cells[1].Value) == true) { selectedVideos++; } } progressBar1.Maximum = selectedVideos; foreach (var videoInfo in PlaylistVideosInfo) { if (Convert.ToBoolean(gvVideos.Rows[count].Cells[1].Value) == false) { count++; continue; } StreamManifest streamManifest = await Youtube.Videos.Streams.GetManifestAsync(videoInfo.Id); gvVideos.Rows[count].Cells[3].Value = "Downloading"; var streamInfo = streamManifest.GetMuxed().FirstOrDefault(x => x.VideoQualityLabel == qualityComboBox.Text); if (streamInfo == null) { streamInfo = (MuxedStreamInfo)streamManifest.GetMuxed().WithHighestVideoQuality(); } gvVideos.Rows[count].Cells[4].Value = streamInfo.Size.ToString(); if (streamInfo != null) { try { var stream = await Youtube.Videos.Streams.GetAsync(streamInfo); await Youtube.Videos.Streams.DownloadAsync(streamInfo, Path.Combine(extractPath, RemoveInvalidChars(videoInfo.Title) + '.' + streamInfo.Container)); } catch (Exception ex) { gvVideos.Rows[count].Cells[3].Value = "Failed"; count++; continue; } } gvVideos.Rows[count].Cells[3].Value = "Done"; count++; progressBar1.PerformStep(); } MessageBox.Show("Download complete successfully"); downloadBtn.Text = " Get Playlist"; downloading = false; } catch (Exception ex) { } }
private async Task <bool> DownloadTrailerAsync(Movie movie) { try { YoutubeClient youtube = new YoutubeClient(); StreamManifest streamManifest = await youtube.Videos.Streams.GetManifestAsync(movie.TrailerURL); // Get highest quality muxed stream IVideoStreamInfo streamInfo = streamManifest.GetMuxed().WithHighestVideoQuality(); if (streamInfo != null) { // Download the stream to file await youtube.Videos.Streams.DownloadAsync(streamInfo, Path.Combine(movie.FilePath, $"{movie.Title}-trailer.{streamInfo.Container}")); return(true); } return(false); } catch (Exception ex) { _logger.LogError($"Error downloading trailer for {movie.Title}\n{ex.Message}"); await _hubContext.Clients.All.SendAsync("downloadAllTrailers", movie); return(false); } }
/// <summary> /// Gets the muxed stream with highest video quality and Mp4 container. /// Returns null if sequence is empty. /// </summary> public static MuxedStreamInfo WithHighestVideoQualitySupported(this StreamManifest streamManifest) { if (streamManifest == null) { throw new ArgumentNullException(nameof(streamManifest)); } return(streamManifest.GetMuxed().WithHighestVideoQualitySupported()); }
/// <summary> /// Gets the muxed stream with custom video quality and Mp4 container. /// Returns null if sequence is empty. /// </summary> public static MuxedStreamInfo WithCustomVideoQualitySupported(this StreamManifest streamManifest, VideoQuality quality) { if (streamManifest == null) { throw new ArgumentNullException(nameof(streamManifest)); } return(streamManifest.GetMuxed().Where(info => info.VideoQuality == quality).Select(info => info).FirstOrDefault()); }
public static List <VideoQuality> GetVideoQualityList(this StreamManifest streamManifest) { if (streamManifest == null) { throw new ArgumentNullException(nameof(streamManifest)); } return(streamManifest.GetMuxed().GetAllVideoQualities().ToList()); }
static async Task DownloadMuxOnly(YoutubeClient youtube, StreamManifest streamManifest, string title, string path) { var highMuxQuality = streamManifest.GetMuxed().WithHighestVideoQuality(); if (highMuxQuality != null) { string newPath = $"{path}/m{title}.{highMuxQuality.Container}"; await youtube.Videos.Streams.DownloadAsync(highMuxQuality, newPath); } }
public async Task DownloadMediumQualityAsync(VideoQuality quality, string saveFile) { var streamInfo = streamManifest.GetMuxed().Where(t => t.VideoQuality == quality).WithHighestVideoQuality(); if (streamInfo != null) { var stream = await youtube.Videos.Streams.GetAsync(streamInfo); await youtube.Videos.Streams.DownloadAsync(streamInfo, $"{saveFile}.{streamInfo.Container}"); } }
private static IEnumerable <IStreamInfo> GetBestMediaStreamInfos( StreamManifest streamManifest, ConversionFormat format) { // Fail if there are no available streams if (!streamManifest.Streams.Any()) { throw new ArgumentException("There are no streams available.", nameof(streamManifest)); } // Use single muxed stream if adaptive streams are not available if (!streamManifest.GetAudioOnly().Any() || !streamManifest.GetVideoOnly().Any()) { // Priority: video quality -> transcoding yield return(streamManifest .GetMuxed() .OrderByDescending(s => s.VideoQuality) .ThenByDescending(s => !IsTranscodingRequired(s.Container, format)) .First()); yield break; } // Include audio stream // Priority: transcoding -> bitrate yield return(streamManifest .GetAudioOnly() .OrderByDescending(s => !IsTranscodingRequired(s.Container, format)) .ThenByDescending(s => s.Bitrate) .First()); // Include video stream if (!format.IsAudioOnly) { // Priority: video quality -> framerate -> transcoding yield return(streamManifest .GetVideoOnly() .OrderByDescending(s => s.VideoQuality) .ThenByDescending(s => s.Framerate) .ThenByDescending(s => !IsTranscodingRequired(s.Container, format)) .First()); } }
private async Task GetVideosAsync() { try { List <string> quality = new List <string>(); StreamManifest streamManifest = await Youtube.Videos.Streams.GetManifestAsync(PlaylistVideosInfo[0].Id); List <MuxedStreamInfo> streamInfos = streamManifest.GetMuxed().ToList(); for (int i = 0; i < streamInfos.Count(); i++) { quality.Add(streamInfos[i].VideoQualityLabel); } qualityComboBox.DataSource = quality; downloadBtn.Text = " Download"; } catch (Exception ex) { } }
public static List <MediaStreamList> PopulateListGrouped(StreamManifest mediaStreamInfos) { var mixedStreams = new MediaStreamList(); var mixed = mediaStreamInfos.GetMuxed().ToList(); mixedStreams.Heading = "Mixed Downloads"; foreach (var item in mixed) { mixedStreams.Add(item); } var videoStreams = new MediaStreamList(); var videoS = mediaStreamInfos.GetVideoOnly().ToList(); videoStreams.Heading = "Video Only Downloads"; foreach (var item in videoS) { videoStreams.Add(item); } var audioStreams = new MediaStreamList(); var audio = mediaStreamInfos.GetAudioOnly().ToList(); audioStreams.Heading = "Audio Only Downloads"; foreach (var item in audio) { audioStreams.Add(item); } var list = new List <MediaStreamList> { mixedStreams, videoStreams, audioStreams }; return(list); }